This project demonstrates how to make a nightlight by using an Arduino, a PIR motion sensor, and PowerSwitch Tail to turn on a 120V light.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Setup Your Arduino / Geekduino
Our instructable will be using the RobotGeek Geekduino board and the RobotGeek SensorShield. If you've never used an Arduino or the RobotGeek Sensor Shield, these guides will get you up to speed.
We'll also have some wiring diagrams for a standard Arduino Uno if you're not using a RobotGeek kit.
Step 2: Project Parts List
This is a list of the parts we used to make this project. An Arduino Uno or Duemilanove will also work for your microprocessor. We recommend using the Sensor Shield listed here though, because it absolutely simplifies the build process.
Step 3: Wiring
Wire as shown in the diagram above that matches the parts you've chosen to use.
|Device||Sensor Shield Port|
|PIR Motion Sensor||Digital Pin 2|
|PowerSwitch Tail|| Digital Pin 4 |
White = 1 +in / Black = 2 -in
Step 4: Coding
You can download the code sketch here:
Load it on to your board, and you're ready to light up the night! There are a few things worth mention in the code. To put it simply, this code says that when the PIR sensor detects movement to set the signal pin connected to the Powerswitch Tail to HIGH, and to keep it that way for a predetermined amount of time. if you want to change that amount of time, take a look at the code. Notice where it says
#define LIGHT_ON_TIME 10000? This sets the delay for an amount of time (in this case, 10 seconds/10000 milliseconds) in milliseconds. Play with that a bit to activate the light for what you deem an appropriate amount of time.
Also worth mentioning is the fact that you can hook up just about any 120v device to the power switch tail, and it will activate in the same way as the light has. We've used it for spooky halloween decorations, but the sky is the limit, really.
Step 5: Project Ideas
Since you've got a device that functions whenever something moves in front of it at this point, why not try adding some things to it? You could easily add a buzzer to make a jaunty tune every time the sensor catches you, or make a proximity alarm for when interlopers invade your desk space. Maybe you want a little light in your drawer when it opens? You could have the sensor turn on some LEDs. Experiment with it! Arduino programming is simple enough, and if you're using the RobotGeek Sensor Shield, adding new modules is quick and easy. Most of all, have fun with it and make something you love!