Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Resistor 10k ohm
Breadboard (generic)
5 mm LED: Red
PIR Motion Sensor (generic)
Software & Tools
Arduino IDE
Project description
Code
Code
c_cpp
1const int led = 9; // Led positive terminal to the digital pin 9. 2const int sensor = 5; // signal pin of sensor to digital pin 5. 3const int state = LOW; 4const int val = 0; 5 6void setup() { // Void setup is ran only once after each powerup or reset of the Arduino board. 7 pinMode(led, OUTPUT); // Led is determined as an output here. 8 pinMode(sensor, INPUT); // PIR motion sensor is determined is an input here. 9 Serial.begin(9600); 10} 11 12void loop(){ // Void loop is ran over and over and consists of the main program. 13 val = digitalRead(sensor); 14 if (val == HIGH) { 15 digitalWrite(led, HIGH); 16 delay(500); // Delay of led is 500 17 18 if (state == LOW) { 19 Serial.println(" Motion detected "); 20 state = HIGH; 21 } 22 } 23 else { 24 digitalWrite(led, LOW); 25 delay(500); 26 27 if (state == HIGH){ 28 Serial.println("The action/ motion has stopped"); 29 state = LOW; 30 } 31 } 32} 33
Downloadable files
Circuit diagram
Circuit diagram

Image
Image

Image
Image

Image
Image

Circuit diagram
Circuit diagram

Image
Image

Comments
Only logged in users can leave comments