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.


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


  • Detect motion to turn on lights
  • Turn off city lights after 5 minutes of inactivity


  • 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



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.

PIR Motion Sensor 220 ohm resistor LED

PIR Motion Sensor
220 ohm resistor


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).




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 1442865455303Device(s)/dev/ttyACM0 1442865455386Connected/dev/ttyACM0 1442865458332ReplInitialized >> sleep timer reset sleep timer reset sleep timer reset sleep timer reset


I basically just stuck the motion sensor to a vertical strut beam, using tacky tape. I then attached the LED to the top of an antenna and used a twist tie to lock it in place.

Probably not the most polished build, but it was quick and easy. The exposed electronics kind of makes sense on a radio tower.

Energy efficiency!