Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Motion-Activated Relay Control for AC Lighting

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Motion-Activated Relay Control for AC Lighting

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

5V 2-Relay Module (JD-VCC)

LED Bulb AC

HC-SR501 Motion Sensor

Power 220V

Wiring Details

Arduino UNO

5V 2-Relay Module (JD-VCC)

LED Bulb AC

HC-SR501 Motion Sensor

Power 220V

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.