Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
LED (generic)
PIR Sensor, 7 m
Project description
Code
Arduino UNO interface PIR sensor
arduino
1const int PIR_Sensor = 2; // the number of the PIR_Sensor pin 2const int ledPin = 13; // the number of the LED pin 3int Motion_State = 0; // variable for reading the Motion status 4 5void setup() { 6 pinMode(ledPin, OUTPUT); // initialize the LED pin as an output: 7 pinMode(PIR_Sensor, INPUT); // initialize the PIR_Sensor pin as an input: 8} 9 10void loop() { 11 12 Motion_State = digitalRead(PIR_Sensor); // read the state of the PIR_Sensor value: 13 if (Motion_State == HIGH) { // check if the Motion_State is High. 14 digitalWrite(ledPin, HIGH); // turn LED on: 15 delay(10000); 16 } else { 17 18 digitalWrite(ledPin, LOW); // turn LED off: 19 } 20}
Comments
Only logged in users can leave comments