Energy Saver

Now that we have an energized city, the electricity bills are coming in. Let’s figure out a way to turn off the lights when we are not in the room. And also check out money saving expert energy to help you save energy and money.

Goal:

Turn off the city lights if we don’t detect anybody for 5 minutes.

Challenges:

Detect motion to turn on lights

Turn off city lights after 5 minutes of inactivity

Components:

Raspberry Pi (or any NodeJS host)

Arduino (I used the Mega 2560 but any will do)

HC-SR501 motion sensor

motion sensor 1.8v LED

resistor

Schematic:

This is a pretty simple circuit, the same in fact as one you would need to place a motion sensor light bulb in your garden. We just need to plug the motion sensor into a digital input pin and supply it 5v of power. We will then connect an LED and resistor to an output pin to indicate when motion has been detected.

Code:

Initialize the board, the LED and motion detector. Then we just define a sensor listener that will be activated by the motion detector. An LED is connected to an output pin so we could get instant feedback when motion has been detected.

Basic Flow

Set initial energy delay timer for 5 minutes. Turn off devices if no motion detected.

Listen for motion detection . Reset timer. Turn on LED for 2 seconds. Turn on lights (and other optional devices).



Filename

energysave.js



Now save and run your file.

Note: If this is your first project, you will need to initialize the folder and add the johhny-five module.

Run the following two commands before launching your new app.

npm init

npm install johnny-five --save

Now run the code

node energysave.js

You should now see the following on your console and the LED should turn on when you make any motion. The city lights, disco lights and anything else you want to turn on should also be working now.

root@thethingbox:~/IoL# node energysave.js 1442865455303 Device(s) /dev/ttyACM0 1442865455386 Connected /dev/ttyACM0 1442865458332 Repl Initialized >> sleep timer reset sleep timer reset sleep timer reset sleep timer reset