Arduino UNO Board with PIR Motion Sensor
Arduino UNO Board with PIR Motion Sensor
In this project, we will create a simple circuit with an Arduino UNO and PIR motion sensor detects movement. An LED light up when the movement is detected.
Requirements of hardware in this Project:
- Arduino UNO board
- PIR Motion Sensor (HC-SR501)
- 1 LED bulb
- Jumper Cables
- A USB cable for connecter Arduino UNO board
Requirements of software in this Project:
- Arduino IDE software
The Working principle of the Project:
The module consists of a Pyroelectric-sensor that generates energy when exposed to heat. It means that when a human or animal body enters in the sensor area, it detects movement and emits heat in the form of infrared radiation. From here comes the name of the sensor, a Passive infra-red sensor. The term "passive" means that the sensor does not use energy for detection purposes. It only works by detecting the energy released by other objects.
Write the following program in the Arduino IDE:
int led = 13; // LED is attached to int sensor = 2; // Motion sensor is attached to int state = LOW; // by default, no motion detected int val = 0; void setup() { pinMode(led, OUTPUT); // initalize LED as an result pinMode(sensor, INPUT); // initialize sensor as an input Serial.begin(9600); } void loop() { val = digitalRead(sensor); if (val == HIGH) // check if the sensor is HIGH { digitalWrite(led, HIGH); // turn LED ON delay(100); // delay 100 milliseconds if (state == LOW) { Serial.println("Motion detected!"); state = HIGH; // update variable state to HIGH } } else { digitalWrite(led, LOW); // turn LED OFF delay(200); // delay 200 milliseconds if (state == HIGH){ Serial.println("Motion stopped!"); state = LOW; // update variable state to LOW } } }
Save the program and compile it.
Connect your Arduino UNO board to your laptop or desktop computer via Arduino UNO USB cable. Remove all other connections with the Arduino UNO board, such as PIR Motion Sensor and LED bulb, and then Upload the program to the Arduino UNO board, as Shown in the following figure.
Before uploading the code to the Arduino UNO board, make sure that your Arduino serial port is selected. Otherwise, it shows an error message Serial port not selected.
To select your serial port in your laptop or desktop:
Open Device Manager -> Ports ->Arduino Uno, and then upload your program.
After uploading the program in the Arduino UNO board, connect all modules with the Arduino UNO board, such as the PIR Motion Sensor and LED bulb. The Digital circuit diagram is shown below.
After all, modules connected to the Arduino UNO board. Then connected the Arduino UNO board with the help of Arduino USB cable.