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

Arduino UNO Motion-Activated LED and Relay System

View and Edit Project In Cirkit DesignerImage of Arduino UNO Motion-Activated LED and Relay System

Circuit Documentation

Summary

This circuit is designed to detect motion using a PIR motion sensor and control a red LED and a relay based on the sensor's output and a pushbutton input. The circuit is built around an Arduino UNO microcontroller, which processes the inputs and controls the outputs accordingly.

Component List

  1. PIR Motion Sensor (Wokwi Compatible)

    • Pins: VCC, OUT, GND
    • Description: Detects motion and outputs a high signal when motion is detected.
  2. LED: Two Pin (red)

    • Pins: Cathode, Anode
    • Description: A red LED that lights up when current flows through it.
  3. Arduino UNO

    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
    • Description: A microcontroller board based on the ATmega328P.
  4. RELAY-G5D

    • Pins: COIL1, COIL2, NO, COM
    • Description: A relay used to control high-power devices.
  5. LED: Two Pin (green)

    • Pins: Cathode, Anode
    • Description: A green LED that lights up when current flows through it.
  6. Pushbutton

    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
    • Description: A pushbutton switch used to provide user input.

Wiring Details

PIR Motion Sensor (Wokwi Compatible)

LED: Two Pin (red)

Arduino UNO

RELAY-G5D

LED: Two Pin (green)

Pushbutton

Code Documentation

void setup() {
  // Set pin modes
  DDRB |= 0x0C; // Set D12 (PB4) and D10 (PB2) as outputs
  DDRC &= ~0x20; // Set D13 (PC5) as input
  DDRD &= ~0x02; // Set D9 (PD1) as input

  // Initialize pins
  PORTB &= ~0x0C; // Ensure RED_LED_PIN and RELAY_PIN are LOW
}

void loop() {
  // Read PIR sensor
  if (PINC & 0x20) { // If motion detected
    PORTB |= 0x10; // Turn on RED_LED_PIN
  } else {
    PORTB &= ~0x10; // Turn off RED_LED_PIN
  }

  // Read pushbutton
  if (PIND & 0x02) { // If button pressed
    PORTB |= 0x04; // Activate RELAY_PIN
  } else {
    PORTB &= ~0x04; // Deactivate RELAY_PIN
  }
}

Code Explanation