Comments on: HC-SR501 PIR motion sensor https://osoyoo.com/2017/05/27/hc-sr501-pir-motion-sensor/ Project Tutorial for Arduino compatible products Sun, 03 May 2020 13:34:48 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: TOSEI https://osoyoo.com/2017/05/27/hc-sr501-pir-motion-sensor/comment-page-1/#comment-1435 Sun, 03 May 2020 13:34:48 +0000 https://osoyoo.com/?p=6290#comment-1435 TEST OK :

HARDWARE :
Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
PIR Motion sensor x 1
Relay x 1
Breadboard x 1
Jumpers
USB Cable x 1
PC x 1

Pin Definitions :
VCC : 3.3V-5V ⇔ UNO 5V
GND : The Ground ⇔ UNO GND
OUT : I/O Interface of PIR Motion sensor ⇔ PIN 4

Mixly source :
volatile int val;

volatile int pir;

void setup()

{

val = 0;

pir = LOW;

pinMode(4, INPUT);

pinMode(13, OUTPUT);

Serial.begin(9600);

}

void loop()

{

val = digitalRead(4);

if (val == HIGH) {

digitalWrite(13,HIGH);

if (pir == LOW) {

Serial.println(“motion detected”);

pir = HIGH;

}

} else {

digitalWrite(13,LOW);

if (pir == HIGH) {

Serial.println(“motion ended”);

pir = LOW;

}

}

}

]]>