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.
- 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
- 1.8v LED
This is a pretty simple circuit. 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.
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.
- 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.
npm install johnny-five --save
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.