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

Arduino-Controlled Automatic Room Light with IR Sensors

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Automatic Room Light with IR Sensors

Circuit Documentation

Summary

The circuit is designed to automatically control a light bulb in a washroom based on the detection of occupancy using infrared (IR) sensors. It utilizes an Arduino UNO microcontroller to process signals from the IR sensors and to control a relay that switches the light bulb on or off. The system counts the number of people entering and exiting the washroom to determine occupancy.

Component List

IR Sensors

Arduino UNO

KF-301 Relay

Bulb

Socket

Wiring Details

IR Sensors

Arduino UNO

KF-301 Relay

Bulb

Socket

Documented Code

// Automatic washroom light
int total = 0;

void setup() {
  // Initialize the pins
  pinMode(7, INPUT); // IR sensor 1
  pinMode(8, INPUT); // IR sensor 2
  pinMode(9, OUTPUT); // Relay control
  Serial.begin(9600); // Start serial communication
}

void show() {
  // Print the total number of people in the room
  Serial.println(total);
  Serial.print("people in room.");
}

void loop() {
  // Check if someone has entered the washroom
  if (digitalRead(7) == LOW) {
    while (digitalRead(8) == HIGH) {
      // Wait for the second sensor to be unblocked
    }
    Serial.print("person entered there are ");
    total++;
    show();
    delay(300);
  } else if (digitalRead(8) == LOW) {
    // Check if someone has exited the washroom
    while (digitalRead(7) == HIGH) {
      // Wait for the first sensor to be unblocked
    }
    Serial.print("person exited there are ");
    total--;
    show();
    delay(300);
  }

  // Control the relay based on the occupancy
  if (total == 1) {
    digitalWrite(9, HIGH); // Turn on the light
  } else {
    digitalWrite(9, LOW); // Turn off the light
  }
}

This code is designed to run on the Arduino UNO microcontroller. It reads the output from two IR sensors to detect entry and exit of individuals in the washroom. The relay is controlled based on the occupancy, turning the light bulb on when the washroom is occupied and off when it is not. Serial communication is used for debugging purposes to monitor the number of people in the room.