SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By arduino_beginner21
#72285
Hi,
I bought a PIR sensor from the SparkFun store.
http://www.sparkfun.com/commerce/produc ... ts_id=8630

I hooked it up to my Arduino ATmega328 according to the data on the page.
What would the code for the Arduino look like?

I've searched Google, but I only come across code referring to Parallax PIR sensors, not these ones.

Thanks,
--md
User avatar
By leon_heller
#72286
Just write a program to detect when the alarm pin goes low.

Leon
By riden
#72310
leon_heller wrote:Just write a program to detect when the alarm pin goes low.
arduino_beginner21, don't forget the pull-up resistor to VDD:
SparkFun catalog listing wrote:The alarm pin is an open collector meaning you will need a pull up resistor on the alarm pin. The open drain setup allows multiple motion sensors to be connected on a single input pin. If any of the motion sensors go off, the input pin will be pulled low.
The Parallax sensors may be like the X10 ones that I use, the sensor provides an analog output that needs to be conditioned and processed. The SparkFun unit is a plug and chug unit providing an on/off output.
By arduino_beginner21
#72416
Thanks for the help, but it seems to still not work.

I have an Arduino Duemilenove with an ATmega328 and a PIR sensor bought from SparkFun's store. The physical configuration is as follows:

BLACK (Alarm) ====> 10K ohm resistor ===> Digital Pin 2
BROWN (Ground) ==> GND
RED (Power) =====> 5V


Here's the code that I wrote for it:
Code: Select all
// variables
int PIRpin = 2;  // PIR sensor's alarm pin ==> 10K ohm pull-up resistor ==> Digital Pin 2
int LEDpin = 13; // the LED pin to display output
int val = 0;     // the value of the PIR sensor

// setup
void setup()
{
 pinMode(PIRpin, INPUT);   // the PIR sensor alarm is input
 pinMode(LEDpin, OUTPUT);  // the LED is output
}

// code loop
void loop()
{
 val = digitalRead(PIRpin); // read PIR & set value to variable
   if (val == LOW){         // if the alarm is triggered
     digitalWrite(LEDpin, HIGH);  // turn on the LED
   } else {
     digitalWrite(LEDpin, LOW);  // turn off the LED
   }
} 
I wonder what I am doing wrong? :?:
User avatar
By leon_heller
#72417
Have you checked the output voltage from the PIR?

Leon
User avatar
By FartingMonkey92
#72418
And from the sounds of it, you haven't got a pull-up resistor between the PIR output and 5V...
By arduino_beginner21
#72419
leon_heller wrote:Have you checked the output voltage from the PIR?

Leon
No, how would I do that? With a multimeter?

--md
By arduino_beginner21
#72420
FartingMonkey92 wrote:And from the sounds of it, you haven't got a pull-up resistor between the PIR output and 5V...
No, I haven't. Is this necessary?
User avatar
By FartingMonkey92
#72421
Read the description on it's product page.
By arduino_beginner21
#72422
FartingMonkey92 wrote:Read the description on it's product page.
Yes, I have. But it says:
The alarm pin is an open collector meaning you will need a pull up resistor on the alarm pin.
This refers to the Black alarm pin, not the 5V connection, yes?
User avatar
By leon_heller
#72423
Checking the PIR output with a meter will show you if it is working! You need the pull-up resistor, of course.

Leon
Last edited by leon_heller on Sat May 09, 2009 2:18 pm, edited 1 time in total.
User avatar
By FartingMonkey92
#72424
You should have the PIR output hooked up directly to the Arduino pin then from there to 5V with a resistor. Pull-up resistor
But do what Leon says first...
Last edited by FartingMonkey92 on Sat May 09, 2009 2:21 pm, edited 1 time in total.
By arduino_beginner21
#72445
leon_heller wrote:Checking the PIR output with a meter will show you if it is working! You need the pull-up resistor, of course.

Leon
So, I would test it with what configuration? Do the GND and 5V pins need no resistor? Do I just include a 10K resistor between the Alarm and pin 2?
User avatar
By leon_heller
#72448
You seem to be a bit clueless! The pull-up resistor goes between the output and Vcc, of course, as you've been told at least once. What's the point of putting it anywhere else?

Leon
By arduino_beginner21
#72928
leon_heller wrote:You seem to be a bit clueless! The pull-up resistor goes between the output and Vcc, of course, as you've been told at least once. What's the point of putting it anywhere else?

Leon
Well, I am sorry for being so clueless, but I have not have a very in-depth introduction to electronics. I've tried my best searching Google and using common sense, but to a point, I don't have all the practical knowledge of a real electrician. I have only just finished experimenting with potentiometers and LEDs. What may be the most elementary knowledge for you might be a very complex idea for me. Please respect that. I'm sorry for asking so many questions, but I thought the PIR sensor I bought could have needed a resistor before it connected to ground, just like a LED.