Smart Room Energy Saver
Hi everyone, my goal is to create a device that automatically turns a light on when someone enters a room and turns it off after the room has been empty for a period of time. The system also displays its status and estimated energy savings. Thank you for showing interest.
Note: I had to use computer power for the last half of this build since my 9V battery ran out because it had been used for other projects and was old.
But a full 9V battery will work for this project.
Supplies
Electronics:
1x Arduino Uno (or compatible)
1x PIR Motion sensor (HC-SR501)
1x Breadboard
Jumper Wires
1x LCD 1602 display
LED
220 ohms resistor
Laptop compatible with Arduino IDE (or equivalent)
USB cable
9V battery
Snap-on connector
Enclosure:
Foam board
Hot glue
Hobby knife
Ruler
Pencil
Gather and Inspect Electronics
Check Everything
Make sure:
- The Arduino powers on.
- The LCD isn't damaged.
- The PIR sensor has all three pins.
- You have enough jumper wires.
Once everything is working. You can now begin.
Place Components
I like to lay out my components on a table
A good layout is:
LCD
PIR
Arduino
Breadboard
This layout leaves enough room between parts so wires aren't stretched.
Power to Breadboard
CONNECTIONS:
Arduino 5V to Breadboard positive rail (+)
Arduino GND to Breadboard negative rail (-)
Now every component will get power from the breadboard rails instead of directly from the Arduino.
LCD 1602 Mounting + Wiring
Connect LCD pins:
- Pin 1 (VSS) to GND rail
- Pin 2 (VDD) to 5V rail
- Pin 16 (K) to GND rail
- Pin 3 (VO) to GND rail
- Pin 15 (A) to 5V
LCD control connections:
Pin 4 (RS) to Arduino D12
Pin 5 (RW) to GND
Pin 6 (E) to Arduino D11
LCD data connections:
Pin 11 (D4) to Arduino D5
Pin 12 (D5) to Arduino D4
Pin 13 (D6) to Arduino D7
Pin 14 (D7) to Arduino D6
Connect the PIR Motion Sensor
Find the 3 pins on the PIR sensor and follow the connections guide.
Connections:
VCC to 5V rail
GND to GND rail
OUT to Arduino D2
The sensor sends a signal to the Arduino when motion is detected.
Connect the LED Light
The LED is going to be used as a prototype for an actual room light.
Connections:
- Arduino D8 to 220 ohms resistor to LED positive leg.
- LED negative leg to GND rail.
The Arduino controls the LED
- High signal = light ON
- LOW signal = light OFF
So far, the LED should light up and the LCD too.
Install Arduino Software
(I used the Arduino cloud but the IDE should work better)
Open the Arduino IDE and Connect the Arduino Uno.
Install the LiquidCrystal library.
Now, upload this code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 7, 6);
const int pirPin = 2;
const int ledPin = 8;
unsigned long lastMotionTime = 0;
unsigned long savedTime = 0;
unsigned long emptyStartTime = 0;
const unsigned long timeout = 30000;
bool lightOn = false;
bool countingSaved = false;
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
lcd.begin(16, 2);
lcd.print("SMART ENERGY");
delay(2000);
lcd.clear();
}
void loop() {
int motion = digitalRead(pirPin);
// Motion detected
if (motion == HIGH) {
lastMotionTime = millis();
if (!lightOn) {
lightOn = true;
digitalWrite(ledPin, HIGH);
}
countingSaved = false;
lcd.setCursor(0,0);
lcd.print("ROOM: OCCUPIED");
lcd.setCursor(0,1);
lcd.print("Light: ON ");
}
// No motion for timeout period
if (lightOn && millis() - lastMotionTime > timeout) {
lightOn = false;
digitalWrite(ledPin, LOW);
countingSaved = true;
emptyStartTime = millis();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ROOM: EMPTY");
}
// Count only after shutoff
if (countingSaved) {
savedTime = (millis() - emptyStartTime) / 1000;
lcd.setCursor(0,1);
lcd.print("Saved: ");
lcd.print(savedTime);
lcd.print("s ");
}
}
Build the Enclosure (Optional)
Create a small enclosure using foam board or cardboard.
My enclosure will use hot glue and foam board but foam-tac and cardboard also works.
Make sure the PIR can still see outside the enclosure and the USB cable can reach the Arduino.
Test the System
- Plug the 9V battery into the Arduino.
- Wait for the PIR sensor to initialize.
- Move in front of the sensor.
- Confirm LED turns on and shows "ROOM: OCCUPIED"
- Stop moving.
- Wait 30 seconds.
- Confirm LED turns off, LCD shows "ROOM: EMPTY", and Saved timer increases.
'
Thanks to everyone for looking at my project as this is my first one published on Instructables!!