Go Down

Topic: Stupid PIR Sensor (Read 462 times) previous topic - next topic

hrhtml99

Hello, I have been trying for a while to get a RIP motion sensor to work. This is the sensor https://www.sparkfun.com/products/8630 I have wired it exactly as in this picture. http://bildr.org/blog/wp-content/uploads/2011/06/PIR-Arduino_hookup.png Here is my code:
Code: [Select]
int pirPin = 2; //digital 2

void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
}

void loop(){
  int pirVal = digitalRead(pirPin);

  if(pirVal == LOW){ //was motion detected
    Serial.println("Motion Detected");
    delay(150);
  }

}


Can someone please help me? Thanks!!
I enjoy electrical engineering and robotics engineering. I have a Arduino Mega 2560 based rover with ultrasonic, infrared and gyroscopic cap

PaulS

Quote
Can someone please help me?

Sure. What is the problem?

Sparkfun says that it is a 12V sensor. You are powering it from 5V.

James C4S

What is the problem? 

Have you verified the value of the resistor you are using?
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

hrhtml99

Yes, I do have a 10K ohm resistor, I will try powering it with 12V. It is not returning any data, and it quite frustrating, as it is a remarkably simple device.
I enjoy electrical engineering and robotics engineering. I have a Arduino Mega 2560 based rover with ultrasonic, infrared and gyroscopic cap

PaulS

Quote
It is not returning any data

No data? Or, not the data you want?

hrhtml99

After fiddling some more, I get it saying there is motion even when it is in a dark box. Here is my new code. The data I want is pin 2 to go LOW if there is motion, and HIGH if there is not. Here is my slightly updated code:
Code: [Select]
int pirPin = 2; //digital 2

void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
}

void loop(){
  int pirVal = digitalRead(pirPin);

  if(pirVal == LOW){ //was motion detected
    Serial.println("Motion Detected");
    delay(150);
  }else{
    Serial.println("No Motion");
  }

}


And I am now using a Ni-MH 12V battery.
I enjoy electrical engineering and robotics engineering. I have a Arduino Mega 2560 based rover with ultrasonic, infrared and gyroscopic cap

PaulS

Quote
And I am now using a Ni-MH 12V battery.

For what? A schematic is essential.

Go Up