Materials:
- Arduino board (such as an Arduino UNO)
- PIR motion sensor
- LED light
- Resistor (220 ohms)
- Breadboard
- Jumper wires
Instructions:
- Connect the PIR motion sensor to the Arduino board. The sensor has three pins: VCC, GND, and OUT. Connect VCC to the 5V pin on the Arduino, GND to the GND pin, and OUT to pin 2 on the Arduino.
- Connect the LED to the breadboard. Connect the positive leg of the LED to pin 3 on the Arduino using the 220 ohm resistor, and the negative leg of the LED to the GND pin on the Arduino.
- Upload the following code to the Arduino:
int led = 3; // LED is connected to pin 3
int motionSensor = 2; // Motion sensor is connected to pin 2
int state = 0; // Current state of the sensor
void setup() {
pinMode(led, OUTPUT); // Set LED as output
pinMode(motionSensor, INPUT); // Set motion sensor as input
}
void loop() {
state = digitalRead(motionSensor); // Read the sensor state
if (state == HIGH) { // If motion is detected
digitalWrite(led, HIGH); // Turn on the LED
delay(5000); // Wait for 5 seconds
} else { // If no motion is detected
digitalWrite(led, LOW); // Turn off the LED
}
}
- Power the Arduino board using a USB cable or a power supply.
That’s it! Your motion sensor based light using Arduino is ready. When the sensor detects motion, the LED will turn on and stay on for 5 seconds. When there is no motion, the LED will turn off. You can adjust the delay time by changing the value of the delay function in the code.