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

Arduino UNO Motion-Activated Servo and LED Control System

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

Circuit Documentation

Summary

This circuit is designed to detect motion using a PIR motion sensor and respond by turning on a red LED, activating a relay, and rotating a servo motor. When motion is detected, the red LED turns on for 10 seconds. After this period, the relay is activated, and the servo motor rotates 90 degrees for 3 seconds before returning to its original position.

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: Emits red light when powered.
  3. Servo (Wokwi Compatible)

    • Pins: GND, V+, PWM
    • Description: Rotates to a specified angle based on the PWM signal.
  4. 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: Microcontroller board used to control the circuit.
  5. RELAY-G5D

    • Pins: COIL1, COIL2, NO, COM
    • Description: Electromechanical switch used to control high-power devices.
  6. LED: Two Pin (green)

    • Pins: Cathode, Anode
    • Description: Emits green light when powered.

Wiring Details

PIR Motion Sensor (Wokwi Compatible)

LED: Two Pin (red)

Servo (Wokwi Compatible)

Arduino UNO

RELAY-G5D

LED: Two Pin (green)

Code Documentation

/*
 * This Arduino Sketch controls a circuit with a PIR motion sensor, a red LED,
 * a relay, and a servo motor. When motion is detected by the PIR sensor, the
 * red LED turns on. After 10 seconds, the relay is activated, and the servo
 * motor rotates 90 degrees for 3 seconds before returning to its original
 * position.
 */

#include <Servo.h>

// Define pin connections
const int pirPin = 13; // PIR sensor output connected to D13
const int redLedCathode = 12; // Red LED cathode connected to D12
const int redLedAnode = 11; // Red LED anode connected to D11
const int relayPin = 9; // Relay coil connected to D9
const int servoPin = 10; // Servo PWM connected to D10

Servo myServo;

void setup() {
  // Initialize pin modes
  pinMode(pirPin, INPUT);
  pinMode(redLedCathode, OUTPUT);
  pinMode(redLedAnode, OUTPUT);
  pinMode(relayPin, OUTPUT);
  myServo.attach(servoPin);
  // Ensure initial states
  digitalWrite(redLedCathode, LOW);
  digitalWrite(redLedAnode, LOW);
  digitalWrite(relayPin, LOW);
  myServo.write(0);
}

void loop() {
  if (digitalRead(pirPin) == HIGH) { // Motion detected
    digitalWrite(redLedCathode, HIGH); // Turn on red LED
    delay(10000); // Wait for 10 seconds
    digitalWrite(relayPin, HIGH); // Activate relay
    myServo.write(90); // Rotate servo to 90 degrees
    delay(3000); // Wait for 3 seconds
    myServo.write(0); // Rotate servo back to 0 degrees
    delay(1000); // Wait for 1 second
    digitalWrite(relayPin, LOW); // Deactivate relay
    digitalWrite(redLedCathode, LOW); // Turn off red LED
  }
}

This code initializes the necessary pins and sets their modes. In the loop function, it continuously checks for motion detected by the PIR sensor. When motion is detected, it turns on the red LED, waits for 10 seconds, activates the relay, rotates the servo motor to 90 degrees, waits for 3 seconds, and then returns the servo motor to its original position before turning off the relay and the red LED.