Saturday, November 26, 2016

220V Auto room light switch using Arduino and Lazer (Visitor counter)

Many peoples forgets the Room lamps in running state when nobody in the room, this causes increasing electric bill or battery energy losing in solar home.
This Arduino project is a visitor counter that turns OFF the lamp when nobody in the room automatically, it also can used for lamps of bathroom, toilet, kitchen, etc.
Visitor counter can makes by using different types of sensors, such as IR ray, Ultrasonic, Avoidance sensor, Laser ray, etc.
Here i used Laser because the laser has long distance range, Avoidance sensor is very easy to use but its distance rang is lower than 30cm.
You can make this project with LCD display for showing the numbers of people in the room but as you can see in the video i don't used display because its not important for me, any way the code is same with or without display.
This project help to power consumption optimizing. 

Parts list:
Arduino board 
1 Channel Relay module
Laser diode(2 pcs)
Light sensor modules(2 pcs)
Adapter 5v 200mA
If you want to using display, need :
16X2 LCD Display
Resistor 10K
Resistor 220 ohm

220V Auto room light switch using Arduino and Lazer (Visitor counter)


220V Auto room light switch using Arduino and Lazer (Visitor counter)

220V Auto room light switch using Arduino and Lazer (Visitor counter)

Manual OFF switch used when you are in the room but want to turning OFF the lamp for sleep.

220V Auto room light switch using Arduino and Lazer (Visitor counter)


I used 1000uF 16v capacitor for power line to protect the arduino board from sudden voltage raising but its not necessary.

220V Auto room light switch using Arduino and Lazer (Visitor counter)

220V Auto room light switch using Arduino and Lazer (Visitor counter)



There are some important notes for making this project: 

1-Put the laser diode in the door frame before LDRs to determine the LDRs suitable position and to making sure the laser beam and LDRs are in same straight line. 

2-The laser diodes must set in suitable height to become suitable for all peoples with different long. also you have pay attention to door handle position, when the door is closed, handle maybe cuts the laser beam so put the laser beam above the handle.

3-The laser is harmful for eyes when its directly toward your eyes. 

4-One problem will happen for ONLY FIRST TIME USING this project. That problem is:
When you are in the room and turns this project ON for first time the light will be OFF because the Arduino count zero people come in the room(nobody) when you try to getting out the room the arduino turns ON the light because it count -1 people in the room. So in first time please try to get out the room without cutting the laser beam.
I'm trying solve this problem in the code.  



Code:

#include<LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 3, 4, 5, 6);
#define in 11
#define out 12
#define relay 13
int count=0;
void IN()
{
    count++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}
void OUT()
{
  count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}
void setup()
{
  lcd.begin(16,2);
  lcd.print("Visitor Counter");
  delay(2000);
  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(relay, OUTPUT);
  lcd.clear();
  lcd.print("Person In Room:");
  lcd.setCursor(0,1);
  lcd.print(count);
}
void loop()

 
  if(digitalRead(in))
  IN();
  if(digitalRead(out))
  OUT();
 
  if(count<=0)
  {
    lcd.clear();
    digitalWrite(relay, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Light Is Off");
    delay(200);
  }
 
  else
    digitalWrite(relay, HIGH);
 
}