Introduction: Raspberry Pi Zero Moon Light (Controlled With Smart Phone)
Welcome! Here's how to build a smart-phone controlled light. I found a very nice "moon shaped" lamp at Ikea - but really any lamp will do that has a simple 2-prong AC plug.
This will work with any raspberry pi. (I have not tried it on the Raspberry Pi A models). This tutorial uses a Raspberry Pi Zero, but I also have a few photos of how to hook this up with a Raspberry Pi 2.
I hope you enjoy this as much as my wife and I do. We always have our smartphones at night closeby - so it makes perfect sense to turn on and off a lamp from our phones to move around as we are settling into bed.
The hardware took me about 2 hours to setup - the most time consuming part was soldering the pins/headers onto the Pi Zero. If you want to skip that step - just use a Raspberry Pi 2 - it already has everything soldered for you, but it's just a little larger to hide in the lamp.
The author of this instructable takes no responsibility for anything that happens because of this tutorial.
Step 1: Get All the Pieces Ready
You will need:
2*20 Male Header (Found on Ada Fruit) - Only if you are doing this with the Raspberry Pi Zero
Relay Module (Used to turn the lamp power on and off from the pi)
USB - OTG (Straight - not right angle) - Only if you are doing this with the Raspberry Pi Zero
Debug Cable for Raspberry Pi (Optional - if you buy this you do not need to get the HDMI adapter or have a way to plug the pi into an HDMI monitor/screen - this is the only one I got working in windows 10)
Mini HDMI to HDMI(Only needed if not buying debug cable above) Only if you are doing this with the Raspberry Pi Zero
Powered Usb Hub - if not using the Console Cable with your pi
HDMI cord (I learned this the hard way and had to wait for one - you can not setup the wifi with a plugged in keyboard if you do not have a powered hub on the pi zero) - Only needed for Pi Zero & If you choose not to use the Console Cable
Female to Female Pins (You will have extra for other projects)
Any lamp will work - but these lamps make it easy to tuck away the Raspberry Pi and relay.
Smila Mane (Moon Lamp) / 700.108.40 - Make sure you buy an LED bulb - at Ikea - the lamp does not include the bulb!
If you are not near an Ikea (or want to avoid it on Saturdays like I do in the future) - you can easily get this from Amazon:
Odds and Ends
You may already have these - but including links if you do not.
Soldering Kit with "Helping Hands" magnifier - if you do not have one - this includes the nice holder for soldering - it helped me with the soldering to see things closer.
White Electrical Tape (Black would be ok too - but might not look as good)
Wire Cutters/Strippers (if you don't have them already)
Step 2: Setup Your Raspberry Pi!
Download Raspbian (This might take a while - go ahead and get it going)
Setup Console Cable (If you decided to buy the console cable from previous step)
Setup SSH - you will need this for Initial Setup to run commands if you are not plugging a keyboard and screen in directly for setup
Step 3: Solder! (Only Needed If You Are Using the Raspberry Pi Zero)
This step is only needed if you are using a Raspberry Pi Zero
Note: I am an amatuer and have only soldered a few times - this took the longest of any part of the project - but it really was not as bad as I expected.
Plug your soldering iron in to get it heated up.
Stick the "shorter" side of the pins into the raspberry pi zero - they should fit in easily.
Once you have the "shorter" side of the pins inserted into the top of the pi zero - use some electrical tape to hold the pins in place. (They should be flush against the board when taped down)
Turn over the pi and start soldering.
Congrats! No more soldering required after this!
Step 4: Connect the Lamp to the Pi
Use a knife or other sharp object to "split" the ac cord.
Note: it's better to cut a little more to the right side - as you will be cutting the right side of the cord anyway.
Pull apart the cord just a little bit - maybe 3 inches.
Cut the right side of the cord in half. DO NOT CUT BOTH WIRES in the cord.
Strip just a LITTLE bit of the cord - it does not need to be much at all - just enough to fit into the relay on the next step.
Step 5: Connecting the Power to the Relay Switch
Now is the first "electronics" step (except for the soldering).
Find the "k1" section of the relay.
Loosen the left 2 connections. (In the photo that would be the 2nd and 3rd from the right)
Slightly twist the copper on both stripped wires to keep all the individual wires together as you "insert" them into the relay.
Start with the cut side of the cord that is closest to the lamp and put that wire into the relay in K1 - third from the right.
Tighten the screw.
Put the other side of the cord in the second from the right in the K1 section.
Tighten the screw.
You should see no more copper wire.
Step 6: Connect the Raspberry Pi to the Relay Switch
Now we needs to wire up the Raspberry Pi and the Relay Switch.
The Raspberry Pi will send a small signal to the relay switch to tell it to turn on and off the power. (This is light flipping the light switch on your wall).
Pull 3 female-to-female pins leave them mostly connected so it's easier to manage the wires.
Any colors will work - here I used Red, Yellow and Green.
Plug the red cable into the "GND"
Plug the yellow cable into "IN1"
Plug the green cable into the VOC
Now connect those wires to your Pi.
Count the pins to make sure your's looks EXACTLY the same as in the picture - you do not want to get the colors or the pins mixed up.
The image of the pi is looking at it such that the pins are CLOSEST to you. The pin layouts are the same for the pi 2 and pi zero. (Both devices show in the photos)
Green cable into the first cable on the right.
Red cable to the third from the right
Yellow cable to the 8th pin from the left
Step 7: Put Everything in Place
If you have not already done so.
Plug in the power cord to the Pi
Plug the wifi adaptor into the USB OTG cable
Plug the wifi adaptor directly into the Pi2
Note: I taped over the wifi adaptor to cover up the blinking blue light (This is going to be in our bedroom and it should be dark when not in use).
Secure Everything as shown.
I found the relay fit best at the bottom right of the casing.
I originally put the pi on the bottom left of the casing - but it did not fit there well after adding the yellow moon cover - so I put the pi at the top of the casing.
Note: Careful not to cover up the "screw" holes on the gray casing - you will need those to mount the lamp to the wall.
Step 8: Test the Fit
Screw the light bulb into the light receptacle (not shown in photos)
Connect the "outer cover" (the yellow moon) to make sure everything fits.
Note: make sure you do not have any cables between the light bulb and the outer casing to avoid any unsightly shadows.
Step 9: Setup the Apps to Control the Lights From Your Phone
I have all the code setup to use "Java" - any language would work here - you just need to toggle the correct pin.
Note: I used Java to control the pins on the raspberry pi using the "PI4j" project.
Please Note - this is very important if you are developing something on your own - in Pi4j the pin mappings are different than the normal raspberry pi pin layout.
If you followed these instructions - you will be using RaspiPin.GPIO_11 for Java
or - if you decide to set something up on your own with Python/PHP - you need to toggle GPIO 7
I will gladly post the Java code for the Pi and the Android App for anyone who is interested. Please just add a comment or reply so I know someone would actually use them. (This is my first instructable and I did not realize how much time it would take to document everything)