A while ago, I came across https://www.instructables.com/id/Yet-Another-Arduino-110v-Power-Controller/ and was inspired to make one of my own, which can be called an enhanced variant of maewert's unit. I, however, have written programs for Arduino and client so that you can issue command like `scheduler -d 15/7 -t 14:00 -l 1h20m -p 1` from the client to make Arduino let power (household AC) flow to receptacle #1 at 14:00 for 1 1/3 hour.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Disclaimer & Limitation
I do not purport to be an expert on electrical wiring or electrical system in general. Do understand that messing with household AC is potentially dangerous and may result in damage to (a) your circuit (b) your hardware (c) yourself. I make no guarantee about any of the consequence and damage that may ensue in an attempt to follow my guide Undertake this project AT YOUR OWN RISK. Also, any product I reference in this instructable is by no mean an advocacy. Do source you own materials if it suits you.
Due to physical limitation, I used 16 awg wire to hook the receptacle relay module. Hence, for safety purpose, you should stick to low-wattage appliance (<500w). This is ideal for things like lighting or rice cooker.
Step 2: Tools and Materials
- soldering iron,stand,sponge
- helping hands
- wire cutter
- needle nose pliers
- screw drivers
- 2 gang receptacle (select depending on country you live in)
- Arduino board
- 2 or 4 channel 5v dc relay (I got mine from http://www.amazon.com/gp/product/B00KTEN3TM?psc=1&redirect=true&ref_=oh_aui_detailpage_o01_s03)
- electrical tape
- 21 M-M breadboard jumper
- 4 M-F dupont head jumper
- assortment of screw
- 2 gang receptacle box
- epoxy resin (optional)
- DS3231 RTC
- 10k pot
- basic lcd (preferably 16*2)
- AC to DC converter with 5-12v output with barrel connector for Arduino
- USB A to USB B connector
- a 10 uF capacitor
- M-F AC extension cord (3 feet or more)
- a feet of 16 awg copper wire
Step 3: Wiring Up Arduino
Wire up Arduino according to the diagram. It is important that you connect black wires from lcd to the pin directly, otherwise, strangely enough, the lcd will pick up some garbage and produc corrupted out put. Connect Arduino to your computer and upload hello world sketch from https://www.arduino.cc/en/Tutorial/LiquidCrystal. If the lcd powers up but you cannot see anything, adjust the pot until hello world! contrasts nicely.
Step 4: Getting the Code
This is a Java client which you will run from your intelligent system (master). It will (a) provide Arduino with time for initial syncing (b) issue command (c) interpret response from Arduino and display on your terminal. The source is available at https://github.com/mellongreen/scheduler. Note that my code uses rxtx from gnu.io. If you do not have it installed on your system, download it at http://rxtx.qbang.org/wiki/index.php/Download. After you have JARed the code, you are encouraged to make your native wrapper for convenience. Call with `-h` to see help. All time you use must be in 24-hr format.
This is an Arduino code which you will compile and upload to Arduino (slave). I used Arduino ERW 1.0.5. The source is available at https://github.com/mellongreen/schedule_handler ("schedule_handler.ino"). If your wiring differs from my diagram, do take time to understand the code and change the values in define directive. Additionally, you should also change the timezone offset (below "//timezone offset") and DST offset to reflect on change in DST. If you do not live in the US, you might want to change the rule in DST* macros. I have set up the macros according to US DST rule. If your country does not use DST, simply have "isindst()" return 0. DST change should be automatic.
Step 5: Relay and Receptacle
Using M-F jumper, connect relay's VCC and ground to the breadboard. Connect IN1 to digital pin 7 and IN2 to digital pin 8. You can change these values, but be sure to change values in "schedule_handler.ino".
Now cut the extension cord such that the male connector has desired length of cable attached (3 feet should suffice for indoor use). Strip around 10 cm of outer sheath off the wires from the cable end. Break the bridge connecting the live terminals together with the plier (in US, the one with brass screw) like shown here http://i.stack.imgur.com/r3AGlm.jpg. At about 5 cm from the end of the live wire (black in US), cut out about 1.5 cm of insulation, twist the 16 awg wire (with the ends exposed) around this area in the extension cord and solder them together. If you have epoxy glue, you can coat the soldered area with it for additional protection. After the epoxy is set (about 10 min), wrap up this area with electrical tape. You should get -
Put the receptacle in the box and make sure that the neutral and ground wire would comfortably sit in it when connected to their terminals. Adjust the length of the wires as needed. Strip around 1-1.5 cm off the ground and neutral wires (if your wire is stranded, solder their ends to make them solid) and connect them to the appropriate receptacle terminals (GND to green, NEUTRAL to silver in US). Prepare 2 pieces of 16 awg wire measuring about 1.5-2 cm greater than the height of your receptacle box. For each of them, strip 1-1.5 cm off one and and 0.5 cm off the other ((if your wire is stranded, solder the ends). Connect the long end to the live terminal and short end to the common terminal in channel 1 of relay module. You will find that 16 awg barely fit in the terminal and some fiddling is required. Do the same for channel 2, connect the common for channel 2 to the other live terminal in the receptacle.
Now strip the 0.5cm ends off the live wires and solder them if necessary. Connect the first one to Normally-open of the first channel. Connect the second one to Normally-open of the second channel. After making sure that all contacts are secure, put the relay in the box and secure it to the box (I used screw since) I had wooden enclosure. Put the receptacle cover on the box and secure it.
Step 6: Initialization
Insert AC-DC converter into the outlet and supply Arduino with power via barrel jack. 5-6v will do. Connect the Arduino to you computer and upload schedule_handler to it (note that you need to change the name of the extracted directory to schedule_handler if you downloaded zip from github and use Arduino IDE). The lcd should display the datetime and `0 schedule, 0 IP`. This means 0 schedule entry that is not expired exists in the registry, and 0 schedule entry is in progress (meaning no current flows through either of the socket). Resetting or losing power will cause Arduino to empty the registry. You may notice that the time is wrong (should be something along the line of 0:00 1/1/0 ). To sync the time with your system time, you need to call 'java -jar scheduler.jar -s' or `--sync`. If you have wrapper, you can just do `scheduler -s`. This should sync the Arduino time to the system time. This time is maintained by DS3231, which is very reliable (it takes about 6 hour to drift a millisecond from real time). Simple math tells us that it takes 250 days to lose a second.
I remind you to use `-h` or `--help` to see help page, and that all time uses 24-hr format.
A schedule must have (1) port number (which corresponds to the channel # in the relay) (2)length of time for which it should be on (3) the time at which it should turn on. Optionally you can supply it with date. Absence of date argument will be interpreted as `today`.
Disconnect the usb connector from you computer. The Arduino should draw power from dc converter and stay on. Should you want to make Arduino power schedule entry, you can just connect you computer to usb and call scheduler (which communicates via serial port).
Step 7: Preventing Automatic Arduino Reset on Serial Port Opening
For some reason, I found that setdtr() does nothing to prevent Arduino from resetting as a result of opening serial port in Java. This can be fixed by sticking the 10 uF capacitor between ground and rest pin. Note that you should remove the capacitor if you want to upload to Arduino in the future. You can also reset Arduino by pressing the reset button.
View the video for usage example. Jump to *.15 to see some actions.