Introduction: Infrared Smart Outlet
The latest buzz in the tech world has been about "smart" home technology. These technologies are futuristic, and make day-to-day tasks simpler, but for most of us the price for such luxuries isn't realistic. There aren't many cheap alternatives for the consumer; however, for the maker and DIYers there are plenty. DIY Hacks and How Tos created a cheap DIY "smart" tech outlet in his instructable: Control Any Circuit With a TV Remote (and an Arduino). After seeing this, I wanted to make my own spin off on his project, but more tailored for "smart" home enthusiasts. So to bring features of a "smart" home to the everyday household, I designed "Smart Outlet".
Smart Outlet is an infrared controlled AC outlet with an integrated timer. The infrared communication enables this outlet to be turned on and off from many feet away. Using the integrated timer, the outlet may also function as a digital timer, allowing the user to enter times in which the outlet turn on and off.
The Smart Outlet is the simpler way to control any appliance. There is no longer a need for confusing analog outlet timers or even getting off your couch to turn off or on the fan/lamp/clock. With about $20 and a few hours, you can start living in luxury by having the latest hyped tech: "smart" home technology. Let's jump right into our first step: the parts list!
(The video below shows a demonstration of the Smart Outlet. Not shown in the camera's view is the remote which is being pressed from behind the line of sight.)
Step 1: Get Parts!
You will need these parts:
-5V 500mA DC Power Supply
-Keyes IR Remote/Receiver Kit
-DS1307 RTC Module
-Keyes Relay Module
-Female to Female Dupont Wire
-Arduino Pro Mini 5V (or Arduino Nano 3.0)
-Mountable AC Outlet
-IEC320 C14 Receptacle
-Radioshack Project Enclosure 6x3x2"
-White/Black 18AWG wire (for 120V connections)
-Assorted 22AWG wire (for 5V connections)
-5cm by 7cm Perfboard
You will need these tools:
-Soldering Iron (with rosin)
-Hot glue gun (with sticks)
Step 2: Solder Arduino to Perfboard
Let's begin by soldering our arduino to the perfboard. Assuming you have already added male headers to your Pro Mini or Nano 3.0,, push your arduino through the holes in the perfboard. Try to keep the arduino near a corner of the board to reserve room for our other components and modules.
When working with a small board such as the Pro Mini, the pinouts are printed on the bottom of the board. This makes soldering difficult later on, so save yourself the frustration and label the pinouts on your perfboard. (You may want to take a picture as a back up too).
Once your arduino is soldered into the perfboard we can start adding some modules!
Step 3: Solder RTC and IR Headers
Next, let's add some of our modules! We are going to solder the DS1307 RTC module directly to the perfboard, and solder three headers for our IR receiver module. I used headers for the receiver because later, the receiver module is going to be mounted on our project box and for maintenance purposes we want the main-board to be able to be removed from the project box. The RTC is soldered directly to the perfboard, since it has no need to be mounted directly onto the project box.
To add the RTC to our board, first label the pinouts (since they too are listed on the bottom of the module). Then solder the module close to our arduino, being sure to leave room for our relay, lcd headers, and IR headers. The DS1307 RTC module communicates via an interface called I2C andto connect a I2C device to an arduino you must use the connect the following pins: SDA to A4, and SCL to A5. Then, connect the module's G to ground and VCC to +5V.
Finally, we can add three male headers for our IR receiver. Solder the headers to the following pins: Header 1 to Ground, Header 2 to +5V, Header 3 to Pin 10.
After your RTC and three IR headers are soldered in, we can work on that LCD!
Step 4: Solder LCD
To allow easy communication between the user and the Smart Outlet, I chose to add a LCD screen. Lucky attaching an LCD to an arduino is pretty simple, but it takes a some knowledge about how LCDs work. For those of you who are new to using LCDs with arduino check out the following links:
Before soldering header pins, let's make some inter-LCD connections. To save us from adding extra headers (and wires), I've made some quick connections directly on the LCD's pcb. Make the following connections using some 22awg stranded wire: Backlight Ground to Ground via 330 ohm resistor, Backlight VCC to +5V, LCD's R/W to Ground.
As you see in the third attached picture, I used some heat-shrink tubing to protect the 330 ohm resistor from shorting out the LCD. If you do make these connections, you too need to protect your resistor from shorting the circuit, heat-shrink is required.
Since the LCD will be mounted to our project box later on, we need to make it detachable from our main-board. To do this we will need to solder 9 male headers to our main-board, and 9 to the LCD.
Solder the headers on the main-board to the following pins: Header 1 to Ground, Header 2 to +5V, Header 3 to a 10k variable resistor (see diagram), Header 4 to Pin 12, Header 5 to Pin 11, Header 6 to Pin 5, Header 7 to Pin 4, Header 8 to Pin 3, Header 9 to Pin 2.
Then also solder headers directly to these LCD "pins": GND, VCC, V0, RS, E, D4, D5, D6, D7. Finally, using female to female dupont wire, connect the LCD to the headers on the main-board according to the diagram attached to this step.
To make this easier for others, I chose to use the exact pins as shown in arduino.cc's LCD tutorial. Click on the link for more information and see the attached diagram (originally from arduino.cc). If you have trouble communicating between the LCD and arduino, there are I2C modules that can simplify this step down to 2 arduino pins. (However, this may lead to compatibility problems with the arduino code).
Step 5: Solder Relay
Only one more step until our main-board is complete! Let's solder on the relay to get ready to control our AC outlet.
Before soldering anything, check to see how much space will be left in your project box once all the various parts are together. If you have room to screw in your relay, I suggest using male headers (as seen in the attached pictures). However, if there is no room, you'll need to solder the relay module directly to the main-board. (Use the same arduino pins, but instead of using headers just use the module pins).
All we need to control a relay is one arduino pin, VCC and GND. So, if you have space, solder three male headers to your perfboard making the following connections: Header 1 to GND, Header 2 to +5V, Header 3 to arduino Pin 9. (If you do not have space, make the same connections but solder the relay directly to the perfboard).
Let's not worry about the rest of the relay's connections until we hook up our project box to 120V. For testing the code, you can tell the relay is active when the module's red LED shines (it will also click as most relays do). To see our entire circuit in action, move on to the next step: "Upload Code"!
Step 6: Download and Install Libraries
Finally, we can upload some code and get the Smart Outlet working! But first we are going to have to go over the libraries that are required, the basics of my code, and how to use a FTDI USB to Serial adapter.
For my code to work on an arduino, it requires several arduino libraries. Arduino libraries are basically collections of pre-written code that makes communicating with sensors, and other input/output modules simple for the everyday programmer. Since I used these libraries in my code, it will only work if the compiler has access to these libraries. To give your arduino access to a library you have to add it in the Arduino IDE (click here for tutorial and more information). In my code, I used 5 libraries. The following is a list of the libraries linked to a location to download them:
-LiquidCrystal.h (Core library, included with installation of Arduino IDE)
-Wire.h (Core library, included with installation of Arduino IDE)
Those using a Arduino Pro Mini 5V need an adapter called a FTDI USB to Serial adapter. This is because Pro Mini's do not have the typical serial communication hardware on the chip (to keep expenses and size down). Instead, you need to have a breakout board or special USB cable that has the hardware on it. To use it, simply attach the 6 headers on each together and upload code as you usually would. (If you have an Arduino Uno you can skip the FTDI chip and program via arduino too!).
To download the arduino code, and learn more about the technicalities of how the code works, go to the next step!
Step 7: Upload Code!
My code uses a menu based interface. After welcoming the user, Smart Outlet enters the first few lines of loop() in which it prompts the user to enter 1 for help mode, 2 for setting timers, 3 for options, and 4 for "idle" mode. Often times, a while loop is used to continuously listen for commands sent from the IR remote. (In case it is confusing, whenever I say "IRIn = "?";" in my code, it just is for clearing whatever value was received by the IR remote previously).
To listen to IR commands, I used code from the IRremote library to listen and decode commands from the Keyes IR remote (decoded as hexadecimal values). If you would like to use a different remote for this project, simply change the values in the function "remoteListener()" to your remote's commands.
Another important part of the code is the timer functions with the DS1307. Many of the functions in my code have to do with converting times to seconds, formatting time to HHMMSS, calculating time until, getting/setting time.
When making modifications, take advantage of these functions as they are useful for making more complicated timers as well. Turning on and off the relay in arduino code is actually very simple. In case you have trouble finding the single line in the hundreds of lines of code, the line says: "digitalWrite(relayPin, HIGH);" or "digitalWrite(relayPin, LOW);".
The rest of the code should be self explanatory; however, if you have any issues or questions please leave a comment below and I can clarify!
Step 8: Test the Program and Circuit
Now that all the code is uploaded properly, let's make sure everything works the way it should. Plug in your arduino via USB (or FTDI) to a computer for power. Using your Keyes remote, attempt to navigate through the various menus that are displayed on the screen. If you have trouble with the IR remote, make sure you used the correct pins as stated before and be sure that the IR receiver is not connected to pin 13 (as this will cause a malfunction due to an LED being in series with pin 13).
The first menu that comes up will prompt you to press either: 1 for help mode, 2 for setting timers, 3 for options, 4 for idle mode. To test if the relay is connected properly, press 4 to enter idle mode. The screen should now prompt you to press "#" to control the outlet. Press "#", if the relay is connected properly, an LED should be on and you will hear a loud click coming from the relay. If this does not happen, check your connections and refer back to the "Soldering Relay" step.
One final test to make sure everything is working accordingly is to test the RTC. Attempt to set the time by going to options mode, then set time. Enter a time then return to the main menu and enter set timer mode. The time should be displayed on the first row of the LCD if the time is incorrect or says: "??:??", check your connections, and if all else fails, try replacing your DS1307 module.
When you are sure that the device is functioning accurately, we can dress it up in a project box!
Step 9: Dremel and Mount Outlets
To make our circuit work, we will need two different AC outlets. One for connecting the circuit to 120V of AC power, and one for controlling an appliance. First let's mount our IEC320 C14 receptacle to give our circuit power.
WARNING: This step uses deadly voltages. Do not continue unless you are aware of the dangers of high voltages/electrical currents.
Using a dremel, cut a hole in one side of the project box large enough to fit the receptacle. When you are sure that the receptacle fits snug in place, drill holes to screw mount it into the project box. Finally solder two wires, one black and one white to transport some AC current later on. Solder the black wire to "live" and the white to "neutral". (There should be marking on the back of the receptacle with either an N or L). Do not solder unless you are positive you know which terminal is neutral and live.
Repeating the process above, mount your AC outlet to the longer side of your project box. Let's not worry about making any connections to our outlet until we wire the relay. Just make sure your outlet is locked in place to make sure it is safe for when there is actual current running through it.
Once both outlets are mounted into the case, we can mount our LCD!
Step 10: Mount LCD
Let's take a step back from all that alternating current and work on mounting our LCD to the cover of our project box.
Using a dremel, cut out a large rectangle out on the cover of the project box. Make sure the rectangle is large enough to fit the LCD, but not so big that you can see the PCB. When you are sure the cuts are accurate, drill four holes to screw mount the display. Screw in the LCD and finish the job by twisting four nuts onto the screws.
Ensure that the display is mounted firmly to the enclosure, then we can move onto our next step!
Step 11: Wire Power Supply
Our circuit is going to need some 5V DC current to function; therefore, we need to add a power supply to our project box. Make sure your power supply is somewhere between 5V and 12V, supplies more than 300mA of current, and is small enough to fit in the enclosure.
WARNING: This step uses deadly voltages. Do not continue unless you are aware of the dangers of high voltages/electrical currents.
First, cut the cord on the power supply to about 6-8 inches. Then strip the wire to expose the GND and +5V lines. Use a multimeter to distinguish which wire is GND and which is +5V. Solder the +5Vs wire to arduino's VIN pin and the GND wire to arduino's GND.
Now let's deal with the AC side of the power supply. Cut the wire that you soldered to the AC receptacle previously down to about 3 inches. Strip and tin the wire. Cut two pieces of large diameter heat-shrink tubing to fit over the power supply's plugs. Put the heat-shrink through the wire, and solder the white wire into the power supply's largest plug (neutral) and the black to the smaller. (If you have a switching power supply both plugs will be the same size, then it doesn't matter which goes where). Finally move the heat-shrink over the soldered connections and shrink it with a heat gun. Push the power supply into the enclosure and make sure it fits snugly.
Don't forget to label your power supply with a warning message! Since you certainly do not want to open this project box when it is plugged into the wall!
To make sure this step was completed properly, I suggest placing the circuit in the project box, closing it, and making sure the arduino is receiving power via the LCD. If it is functioning accordingly, we can move on to our next step!
Step 12: Mount IR Receiver
To have reliable communication between the IR remote and receiver, we need to mount the receiver to a place were it can collect the most amount of infrared light. We can do this by dremeling a hole for the receiver to collect IR commands.
Begin by dremeling a hole the size of the IR receiver, so that you can push it through the hole in the enclosure. Then hot glue the receiver to the inside of the project box facing the dremeled hole. Finally push the receiver so that it protrudes through the hole.
If you have problems communicating with your remote later on, try enlarging the hole to make the receiver more visible.
Step 13: Wire Relay
Let's finally complete our circuit to make your Smart Outlet complete. However, take caution as this circuit will have 120V AC flowing through it.
First, using 18 AWG black wire, solder the live terminal from the IEC320 receptacle to the live terminal on the AC outlet. Then tin and solder one side of a 18 AWG white wire to the neutral terminal on the IEC320 receptacle. Screw the other end of the wire into the center terminal on the relay. Ensure that it is screwed in tightly and that there is little to no bare wire showing. Finally, strip and tin about 5 inches of white wire. Screw one end into the N.O. (Normally Open) terminal on the relay. Solder the remaining end to the neutral terminal on the AC outlet.
Both our arduino circuit and AC relay circuit should be soldered and connected correctly. Now let's finish this project by taking some safety precautions and closing the project box!
Step 14: Secure With Hot Glue and Close the Box!
Now that every connection is made, we want to make sure they never come undone (unless we want them to). Hot glue is perfect for securing connections since it make a semi-permanent bond that can be broken with a knife, but not by hand.
So heat up your hot glue gun, and douse your IEC320 receptacle and AC outlet in hot glue. Wait a few minutes to let it dry, and make sure you secure anything that is loose. When you are sure everything is tightly in place and there are no loose metal parts, we can finally close the project box.
Plug the closed enclosure into a 120V AC wall outlet and plug any AC appliance into the outlet on the Smart Outlet. Test thoroughly to make sure all of the outlet's functions are working as planned. You may need to open it back up to deal with some issues. If you do make sure the Smart Outlet is not plugged into the wall. Once finished you can move onto the final step!
Step 15: Control Any Appliance With Smart Outlet!
Finally you can live in the luxury of having a more tech automated home! You can say say goodbye to all your analog outlet timers and control any outlet a simpler way, with your Smart Outlet! I hope you have learned more about AC circuits, relays, infrared communication, and RTCs.
If you enjoyed this instructable, please support me by voting for this article in either the Remix, Tech, or Microcontroller Contest. Thank you for reading and enjoy your new device!