Arduino UNO-Based Motion-Activated Relay Control for AC Lighting
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control an LED bulb using an Arduino UNO microcontroller in response to a motion sensor. The system uses a 5V 2-Relay module to switch the LED bulb on and off. The HC-SR501 motion sensor detects movement and sends a signal to the Arduino, which then controls the relay to power the LED bulb. The circuit is powered by a 220V AC power source, which is also used to power the LED bulb through the relay.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
5V 2-Relay Module (JD-VCC)
- A relay module with two channels that can control high power devices.
- It has a JD-VCC pin for relay power, VCC for input signal voltage, and a ground pin.
LED Bulb AC
- An AC-powered LED bulb that can be switched on and off.
- It has a positive and a negative terminal for AC power connection.
HC-SR501 Motion Sensor
- A PIR motion sensor module that detects movement within its detection range.
- It has a ground pin, an output pin, and a VCC pin for power.
Power 220V
- The main AC power source for the circuit.
- It has a hot wire and a neutral wire for AC power input.
Wiring Details
Arduino UNO
- 5V: Connected to the VCC of the HC-SR501 Motion Sensor.
- GND: Connected to the GND of the HC-SR501 Motion Sensor and the GND of the 5V 2-Relay Module.
- D7: Connected to the OUT pin of the HC-SR501 Motion Sensor.
- D3: Connected to the IN1 pin of the 5V 2-Relay Module.
5V 2-Relay Module (JD-VCC)
- JD-VCC: Not connected in this circuit.
- VCC: Not connected in this circuit.
- GND: Connected to the GND of the Arduino UNO.
- IN1: Connected to the D3 of the Arduino UNO.
- IN2: Not connected in this circuit.
- NO: Not connected in this circuit.
- COM: Connected to the neutral wire of the Power 220V.
- NC: Connected to the positive terminal of the LED Bulb AC.
LED Bulb AC
- +: Connected to the NC pin of the 5V 2-Relay Module.
- -: Connected to the hot wire of the Power 220V.
HC-SR501 Motion Sensor
- GND: Connected to the GND of the Arduino UNO.
- OUT: Connected to the D7 of the Arduino UNO.
- VCC: Connected to the 5V of the Arduino UNO.
Power 220V
- Hot wire: Connected to the negative terminal of the LED Bulb AC.
- Neutral wire: Connected to the COM pin of the 5V 2-Relay Module.
Documented Code
// Pin Definitions
int pirPin = 7; // PIR sensor connected to pin 7
int relayPin = 3; // Relay connected to pin 3
void setup () {
// Initialize the PIR sensor pin as an input
pinMode(pirPin, INPUT);
// Initialize the relay pin as an output
pinMode(relayPin, OUTPUT);
// Start with the relay off
digitalWrite(relayPin, LOW);
// Begin serial communication for debugging purposes
Serial.begin(9600);
}
void loop() {
// Read the PIR sensor input
int pirState = digitalRead(pirPin);
if (pirState == HIGH) {
// If motion is detected, turn on the relay (light)
digitalWrite(relayPin, HIGH);
Serial.println("Motion detected: Light ON");
} else {
// If no motion, turn off the relay (light)
digitalWrite(relayPin, LOW);
Serial.println("No motion: Light OFF");
}
// Add a small delay to avoid false triggering
delay(1000);
}
This code is designed to run on the Arduino UNO. It initializes the PIR sensor and relay pins, reads the state of the PIR sensor, and controls the relay accordingly. The relay activates the LED bulb when motion is detected and turns it off when there is no motion. Serial communication is used for debugging purposes.