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

PIR Sensor-Activated Automatic Light with Arduino and Relay

View and Edit Project In Cirkit DesignerImage of PIR Sensor-Activated Automatic Light with Arduino and Relay

Automatic Light Control Circuit Documentation

Summary

This circuit is designed to control an AC bulb automatically using a PIR (Passive Infrared) motion sensor and a 5V relay. The system operates by detecting motion through the PIR sensor, which then triggers the relay to switch on the AC bulb. The Arduino UNO microcontroller is used to process the signal from the PIR sensor and control the relay accordingly. Additionally, the circuit keeps a count of motion detection events and outputs this information to the serial monitor.

Component List

PIR/Motion Sensor

5V Relay

AC Bulb

MB102 Breadboard Power Supply Module 3.3V/5V

Arduino UNO

Wiring Details

PIR/Motion Sensor

5V Relay

AC Bulb

MB102 Breadboard Power Supply Module 3.3V/5V

Arduino UNO

Documented Code

/*
 * Project: Automatic Light with PIR Sensor and Relay
 * Description: This code controls an automatic light using a PIR sensor
 * and a relay. Whenever the PIR sensor detects motion, the relay is activated
 * to turn on a bulb. Additionally, the code counts the number of times
 * a person is detected and prints it on the serial monitor.
 */

// Pin definitions
const int pirPin = 3; // PIR sensor output pin
const int relayPin = 4; // Relay input pin

// Variables
int motionDetected = 0; // Motion detection counter

void setup() {
  // Pin configuration
  pinMode(pirPin, INPUT);
  pinMode(relayPin, OUTPUT);
  // Serial monitor initialization
  Serial.begin(9600);
  // Initialize relay to off state
  digitalWrite(relayPin, LOW);
}

void loop() {
  // Read the state of the PIR sensor
  int pirState = digitalRead(pirPin);
  if (pirState == HIGH) {
    // If motion is detected
    digitalWrite(relayPin, HIGH); // Turn on the light
    motionDetected++; // Increment the counter
    Serial.print("Motion detected: ");
    Serial.println(motionDetected);
    delay(5000); // Keep the light on for 5 seconds
  } else {
    // If no motion is detected
    digitalWrite(relayPin, LOW); // Turn off the light
  }
  delay(100); // Small delay to avoid bouncing
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It sets up the necessary pin modes, initializes the serial communication, and contains the main logic for controlling the relay based on the PIR sensor's output. The relay is turned on when motion is detected and turned off otherwise. The delay functions are used to manage the timing of the light and to debounce the PIR sensor signal.