Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled Automatic Room Light with IR Sensors

Image 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

  • Description: Used to detect the presence of people entering or exiting the washroom.
  • Pins: out, gnd, vcc

Arduino UNO

  • Description: The main microcontroller unit that processes sensor inputs and controls the relay.
  • Pins: IOREF, Reset, 3.3V, 5V, GND, Vin, A0 to A5, SCL, SDA, AREF, D0 to D13

KF-301 Relay

  • Description: An electromechanical switch used to control the power to the light bulb.
  • Pins: signal, power, ground, NC, C, NO

Bulb

  • Description: The light source for the washroom.
  • Pins: positive, negative

Socket

  • Description: Provides electrical connection to the bulb.
  • Pins: positive, negative

Wiring Details

IR Sensors

  • VCC: Connected to the 5V output on the Arduino UNO.
  • GND: Connected to the ground (GND) on the Arduino UNO.
  • OUT: One sensor's output is connected to pin D7 on the Arduino UNO, and the other sensor's output is connected to pin D8.

Arduino UNO

  • 5V: Provides power to the IR sensors and the relay.
  • GND: Common ground for the circuit.
  • D7: Receives the output signal from one of the IR sensors.
  • D8: Receives the output signal from the other IR sensor.
  • D9: Controls the relay signal.

KF-301 Relay

  • POWER: Connected to the 5V output on the Arduino UNO.
  • GROUND: Connected to the ground (GND) on the Arduino UNO.
  • SIGNAL: Controlled by pin D9 on the Arduino UNO.
  • C (Common): Connected to the negative pin of the bulb.
  • NO (Normally Open): Connected to the positive pin of the socket.

Bulb

  • POSITIVE: Connected to the NO (Normally Open) pin of the relay.
  • NEGATIVE: Connected to the C (Common) pin of the relay.

Socket

  • POSITIVE: Connected to the NO (Normally Open) pin of the relay.
  • NEGATIVE: Connected to the negative pin of the bulb.

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.