简体   繁体   中英

PIR Motion Sensor

I have Arduino-UNO. My code is given below. Whenever I run the program, the PIR sensor triggers false highs. But, when the sensor and the jump wires are kept fixed at a point without moving, it reads perfectly.

int led = 13;
int pin = 2;

int value = 0;
int pirState = LOW;

void setup() {
 pinMode(led, OUTPUT);
 pinMode(pin, INPUT);
 Serial.begin(9600);
}

void loop() {

  value = digitalRead(pin);

  if (value == HIGH) {
    digitalWrite(led, HIGH);

  if (pirState == LOW) {
    Serial.println("Motion Detected!");
    pirState = HIGH;
    }
  }else{
    digitalWrite(led, LOW);

if(pirState == HIGH){
  Serial.println("Motion Ended!");
  pirState = LOW;
  }
 }
}

Here is my circuit:电路图

That sounds like you have a bad connection somewhere in the wiring between the Arduino and the sensor module.

Check the wiring, or use different wires, to make sure the wiring makes proper contact at all connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM