Skip to main content

Automated Washroom Light Using IR Sensors

Automated Washroom Light Using IR Sensors

This project-based on Arduino Uno and IR sensors is used to automatically switch on and switch off a washroom’s light that works on AC mains. Whenever a person enters the washroom, the light bulb (or tubelight) will automatically turn on. When the person leaves the bathroom, the light will turn off. This will save electricity charges due to the light remaining on by mistake after use of the washroom. The prototype is shown in Fig. 1.


Fig. 1: prototype for Automated Washroom Light Using IR Sensors

Circuit and working

Circuit diagram of the automated washroom light is shown in Fig. 2. It is built around Arduino Uno (Borad1), BC547 transistor (T1), infrared (IR) sensor modules (Module1 and Module2), and relay (RL1).


Fig. 2: Circuit diagram of automated washroom light


Infrared sensor

The IR sensors (FC-51) used here (refer Fig. 3) are commonly used in obstacle-detection projects. Two pairs of the IR sensor modules are used to detect a person’s entry or exit from the washroom.

Fig. 3: IR sensor module


Each sensor has three pins, namely, Vcc, Vout, and GND. The Vcc pin is to be provided with 5V DC supply, which can be taken from 5V pin of the Arduino Uno. The ground pin (GND) of the sensor can be connected to GND pin of Arduino Uno. The Vout pins of IR Module1 and IR Module2 are the output pins connected to pins 8 and 7 of Arduino Uno, respectively.

           The output of each sensor will be either 5V (high) or 0V (low) based on the detection. When a person is detected, Vout is low, otherwise it is high (about 5V). These logic levels of both the sensors are used to find out whether the person is entering or leaving the washroom.

5V relay

The 5V electromechanical relay (RL1) is used to switch on and switch off the light bulb. A typical sugar-cube type 5V relay has five terminals, two of which are used for energising the coil. The rest are common (COM), normally closed (NC), and normally open (NO) terminals.
The light bulb is connected between NO and COM contacts of the relay. As is obvious, in normal condition, NO pin does not have any contact with the COM pin. When the relay coil is energised, the COM pin touches the NO pin and the light bulb gets 230V AC mains supply. Pin details of a typical sugar cube relay are shown in Fig. 4.


Fig. 4: Pin details of 5V sugar cube relay


Neutral (N) wire of the 230V AC source is connected to the light bulb through the relay. The live (L) wire is directly connected to the light bulb.

When the ‘in’ sensor (Module2) detects a person followed by ‘out’ sensor (Module1), the microcontroller in Arduino assumes that a person is entering the washroom and it provides 5V at pin 9 of Board1. The current from the output pin of Arduino is, however, insufficient to energise the relay. So, npn transistor T1 (BC547) is used for amplification to control the relay and switch on the light.

When ‘out’ sensor detects a person followed by ‘in’ sensor, the microcontroller assumes that a person is leaving and provides 0V at pin 9, which de-energises the relay. This disconnects the neutral and the light bulb switches off.

If only one of the two sensors is used, the current state will not change, so you need both the sensors. The ‘in’ sensor should be placed just outside the washroom near the door and the ‘out’ sensor should be placed inside the washroom near the door. You need to install the sensors such that they can easily detect the person entering or leaving the bathroom.

Software
Arduino Uno is used to compute the logics of the two IR sensors. The circuit is controlled through the software loaded in internal memory of the Arduino. The program (bathroom.ino) is written in Arduino programming language. Arduino IDE 1.8.5 is used to compile and upload the program.

ATmega328P on Arduino Uno comes with a pre-programmed bootloader that allows you to upload a code to it without using an external hardware like programmer kit. In the IDE, the count (total) is globally initialised to zero.

In the code (bathroom.ino), the ‘void setup’ contains the initialisation of digital pins 7 and 8 as input, and digital pin 9 as output. Serial begin in void setup is for serial communication. Void show ( ) is a function used for serial communication. Void setup is shown in the Fig. 5.

The main part of the program is void loop, which contains the logic to be executed. First the ‘in’ sensor is checked for obstruction (person). In case of any obstruction, if condition is satisfied and while loop is executed. At this stage, the ‘out’ sensor is not yet subjected to obstruction.
When the person obstructs the ‘out’ sensor, the output of the sensor is low, so the program exits the while loop and count is incremented. The vice versa is framed for else if part with the count value decremented. Show ( ) function is used for serial monitor and is unnecessary for practical application. Void loop is shown in Fig. 5.


Fig. 5: Arduino code void setup ( )

It is assumed that only one person would be using the washroom at a time, so using if condition, when count (here ‘total’) is checked for the value ‘1’ is shown in Fig. 5. If total is one, digital pin 9 output will be high only for count one and the relay will be connected. If not, it will be kept low, that is, the relay will not be energised.


Construction and testing
A PCB layout for the automated washroom light is shown in Fig. 6 and its components layout in Fig. 7. After assembling the circuit on PCB and uploading the source code (bathroom.ino) into Arduino Uno, connect a 5V supply across CON1, 230V AC across CON2, and the light bulb across CON3. Installation of the sensors near the door


Fig. 6: PCB layout for the automated washroom light


Fig. 7: Components layout of the PCB


Code

//Automatic washroom light

int total=0;


void setup() {

  // put your setup code here, to run once:


pinMode(7, INPUT);

pinMode(8, INPUT);

pinMode(9, OUTPUT);

Serial.begin(9600);

}


void show()

{

Serial.println(total);

   Serial.print("people in room.");

}


void loop() {

  // put your main code here, to run repeatedly:


if(digitalRead(7) ==LOW){

   while(digitalRead(8) == HIGH){

   }

  

   Serial.print("person entered there are ");

   total++;

   show();

   delay(300);

   

} else if (digitalRead(8) == LOW){

  while (digitalRead(7) == HIGH){

  }


  Serial.print("person exited there are ");

  total--;

  show();

  delay(300);

 

}


if(total==1)

{

  digitalWrite(9,1);

}

else

{

   digitalWrite(9,0);

}


}


Comments

Popular posts from this blog

Weather Station Using Arduino & DHT11

Weather Station Using Arduino & DHT11      Introduction: Weather monitoring is an important task in many industries and applications. In this project, we are going to build a weather monitoring station using Arduino Nano, DHT11 sensor, 16x2 LCD display, and I2C module. The DHT11 sensor will be used to measure temperature and humidity, and the results will be displayed on the 16x2 LCD display with the help of the I2C module. Hardware Required:

Understanding the Basics of Resistors: A Beginner's Guide

  Understanding the Basics of Resistors: A Beginner's Guide Introduction: Resistors are one of the most basic and fundamental components used in electronic circuits. They play a vital role in controlling the flow of current in a circuit and have a wide range of applications in everything from simple LED circuits to complex electronic systems. In this blog post, we will dive into the world of resistors, exploring what they are, how they work, and the different types of resistors that are available. What is a Resistor? A resistor is an electrical component that is used to regulate the flow of electrical current in a circuit. It is designed to have a specific resistance value, which is measured in ohms (Ω). The resistance value of a resistor determines how much current can flow through it, with higher resistance values limiting the current flow, and lower resistance values allowing more current to flow. Resistors are passive components, which means that they do not generate or amplify

Exciting ESP8266 Projects to Elevate Your DIY Skills

Exciting ESP8266 Projects to Elevate Your DIY Skills 1. Home Automation System: A home automation system based on the ESP8266 offers an excellent way to transform your house into a smart home. The ESP8266, being a low-cost and powerful microcontroller, can easily communicate with various sensors and actuators to control appliances and devices. It can be connected to your home Wi-Fi network, enabling remote access from anywhere through a web interface or mobile app. To set up a home automation system, you'll need to start by connecting the ESP8266 to the sensors and actuators you want to control. For example, you can use relay modules to switch lights or appliances on and off, and motion sensors to detect movement. Temperature and humidity sensors can help you monitor the environment and adjust the climate accordingly. The ESP8266 can host a web server that allows you to control the connected devices through buttons or switches on a web page. You can also create a mobile app using p