How to Build a DIY Electronic Device to Automatically Turn Off Your Lights and Save on Your Electric Bill
Building a DIY electronic device to automatically turn off your lights can help you save money on your electric bill. With some basic electronic components and a bit of tinkering, you can create a simple automation device that turns lights off when you leave a room. Here is a step-by-step guide on how to build your own automatic light switch off device.
What You Will Need
To build the automatic light switch off device, you will need the following components:
-
Arduino Uno board - The brain of the device. An Arduino is a microcontroller board that can be programmed to control electronic components.
-
Motion sensor module - Detects movement and signals the Arduino. I used a HC-SR501 passive infrared (PIR) motion sensor.
-
Relay module - Acts like a switch to turn the lights on and off, controlled by the Arduino.
-
Jumper wires - To connect the components together.
-
Breadboard - To easily prototype the circuit.
-
9V battery - To power the Arduino.
-
Lamp or light fixture - To test the device.
Optional components:
-
Breadboard power supply - Regulated 5V power source for breadboard instead of 9V battery.
-
Enclosure - To contain the device if installing it permanently.
Circuit Design
Here is how to connect the components together:
-
Connect the motion sensor to the Arduino's 5V power and ground pins. Also connect the output pin to a digital input pin on the Arduino.
-
Connect the relay module to the Arduino's 5V and ground. Connect the signal pin to a digital output pin on the Arduino.
-
Connect the lamp or light fixture to the relay module normally open (NO) and common (C) pins.
-
Power the Arduino with a 9V battery or breadboard power supply.
The motion sensor detects movement and sends a HIGH signal to the Arduino. The Arduino reads this signal and triggers the relay to turn on the light. When motion is no longer detected, the relay turns the light back off.
Programming the Arduino
The Arduino code needs to do the following:
-
Initialize the motion sensor and relay pins.
-
Continuously check for motion detected.
-
Turn relay on when motion is detected.
-
Turn relay off when motion is no longer detected.
Here is example code to achieve this:
```cpp
// Motion sensor on pin 2
int motionSensor = 2;
// Relay on pin 4
int relay = 4;
void setup() {
// Set relay as output
pinMode(relay, OUTPUT);
// Set motionSensor as input
pinMode(motionSensor, INPUT);
}
void loop(){
// Check if motion detected
if (digitalRead(motionSensor) == HIGH) {
// Turn ON relay (and light)
digitalWrite(relay, HIGH);
}
else {
// Turn OFF relay (and light)
digitalWrite(relay, LOW);
}
// Small delay
delay(200);
}
```
This code turns the relay and light on when motion is detected. It turns them off a few moments after motion is no longer detected.
Installation Tips
Here are some tips for installing the finished device:
-
Mount the motion sensor in a location with a good view of the area. Test the sensor coverage.
-
Install the Arduino and breadboard safely inside an enclosure if desired.
-
Connect lamp to relay using an extension cord for easy installation.
-
Upload Arduino code and test operation before permanent installation.
-
Adjust the motion sensor delay as needed to keep lights on for an appropriate time after exiting the room.
Conclusion
Building your own automatic light switch off device is an easy Arduino project that can save energy and money. With basic electronic components like a motion sensor, relay, and Arduino, you can create a simple automation system to turn lights off automatically when you leave a room. Install it in any indoor lighting fixture to start saving electricity!