In this project I will show you how to build a light switch that will turn on the lights when you enter the room.
This project will be build using an ATtiny85 but you could use a Arduino board if you would like. I chose to use an ATtiny85 as it will reduce the amount of space the circuit will take up in the light switch box.
The circuit will be powered by a small 5v power supply (shown below). So that the power supply will work you will need to make sure that your light switch box has a neutral wire in it because without it the device wont work.
The circuit will use a PIR sensor to sense when someone has entered the room and the lights will be turned on by a relay.
Below is the schematic for the circuit. Try to keep all the wires as short as possible to save space. I would recommend using a PCB to keep all the components together so nothing gets connected incorrectly.
Now you will need to program the ATtiny85 to do this follow my tutorial on how to do it using a Arduino Uno Once the attiny85 is programmed insert it back into the IC socket. I have provided the code for you below.
int PIR = 11;
int light = 6;
int val = 0;
void setup() {
pinMode(PIR, INPUT); // Set the PIR sensor as a input
pinMode(light, OUTPUT); // Set the light as an output
}
void loop(){
val = digitalRead(PIR); // read the input value
if (val == HIGH) { // check if PIR sensor is high
digitalWrite(light, HIGH); // turn ON the light
delay(600000) // Time until the light turns OFF
digitalWrite(light, LOW); // Turn OFF the light
Once you have built the circuit you can take a normal light switch and drill a 10mm hol using a Arduino Uno light switch then use hot glue to secure the PIR sensor to the light switch.
After every thing is assembled turn off the power to your lighting circuit and insert the live and neutral wires into the screw terminals for the power supply and connect the live to the relay then the switched live wire to the normally open relay screw terminal.
Turn back on the power to your lighting circuit and test to see if the device works. You may need to adjust the potentiometer on the PIR to set how sensitive the device is.
In the code you can change the amount of time the lights will stay on for after the sensor has been triggered and if you want to have the lights continually on you can use the switch.
AcknowledgementI thank PCBWay & LCSC Electronics for the partnership.
PCBWay is a cheap and reliable service where you can get your PCBs manufactured. All the PCBs are high quality and the engineers are very helpful. Sign up today and get a $5 welcome bonus. Check out PCBWay's Hackster page. Also check out their gift shop and Gerber viewer.
LCSC Electronics Is China's leading Electronic Components Distributor. LCSC sells a wide variety of high quality electronic components at low prices. With over 150, 000 parts in stock they should have the components you need for your next project. Sign up today and get $8 off on your first order.
WebsiteCheck out more of my other projects on my website.
Comments