Introduction: Bluetooth Controlled Outlet (Home Automation)

Have you ever left the house and wondered if you forgot to turn off the lights or the TV? Or been driving home in the dark and wish the lights would be on before you get in the house with you hands full of groceries. A simple solution I have found is to create your very own smart outlet! A cheaper solution than leaving your lights on and easier than walking in the dark.

Home automation is a relatively new idea that security system companies are adding to their packages. This could prove to be expensive if you own an old home or impossible if you rent or live in a dorm room. One night I was laying in my bed in my college room and wished I had a way to turn off the lights instead of walking across the room flipping the switch and stumbling across my messy floor. While I laid in my bed that night I had the bright idea to see what other people were doing on YouTube to see how hard it would be to control my room with my phone. Imagine your galaxy phone (or iPhone, if your one of those people) being able to act as Jarvis from Iron Man. Here is a overview video of home automation; What is Home Automation?

Step 1: Materials and Parts

My project quickly changed from controlling my entire apartment (which would require a lot of parts and cutting of university wire, which would be frowned upon) to a very simple portable smart outlet. If I can learn how to control one outlet I can replicate the project into a full scale home automation project in a future house. For a college student this is perfect because I can turn my fan on lights off with out having to get out of bed. One thing I learned freshman year is that the single light you have in the middle of the room provides a very harsh light. A simple solution is to hang Christmas lights up around the room, using command hooks (these wont pull the paint off the walls and cause you to pay to fix it or loose your deposit). I did not want to start cutting the heads off my extension cords or from my fan so I decided to buy a new outlet that I can plug the cords into and wire directly to my relay board. The current version of my smart outlet uses the following parts:

Step 2: Wiring

CAUTION!!!

WIRING AC POWER CAN BE DANGEROUS AND LIFE THREATENING IF DONE IMPROPERLY!!!!!

IF YOU ARE UNSURE OF WHAT YOUR DOING ASK FOR HELP!!!

AC WIRING:

I went to Lowes and bought an extension cord, mine was about 10' if I remember correctly. Using a pair of wire cutters I cut the extension cord in two 5' sections. You will use the male end to wire into the smart outlet, and the female end is your extra wire for the relay board and wiring to the outlets. I used the black wire to connect to relay board. Since I have two outlets I first twisted the two ground wires and the ground coming in together and put a wire nut on them (I suggest also wrapping in electrical tape), than attached to the outlets. I did the same thing for the white (hot) wire. Here is the tricky part, wiring to the relay with the black wires. First attach the incoming neutral wire with two extensions like you did for the previous wires. Make sure these extension go into the middle position of the relay triplet. This is pretty standard from what I have seen from setting up relays. Than attach two more extensions to the NORMALLY OPEN parts of the relay triplet (unless you want whatever is plugged in to turn on if the system restarts). The two extensions you now have get attached to the outlet.

DC WIRING:

This wiring is to your arduino, this should come fairly easy to those who have attached anything to their arduino via the digital ports. Look at the picture above for a guide.

If you are ready to put everything in the enclosure you will need to attach the bluetooth chip now as well. This is even more straight forward than the relay board.

Step 3: Code

What I would suggest doing first is to buy the relay board along with the arduino because this is about the only part that could go wrong for the code aspect. I bought mine from ebay and used a relay test code I found on Arduino's website. When testing you can verify functionality visually and you should hear the relay click when it engages. Here is my test code;

/* YourDuino Example: Relay Control 1.10
Handles "Relay is active-low" to assure no relay activation from reset until application is ready. terry@yourduino.com *

*-----( Import needed libraries )-----*/ /*-----( Declare Constants )-----*/ #define RELAY_ON 0 #define RELAY_OFF 1 /*-----( Declare objects )-----*/ /*-----( Declare Variables )-----*/ #define Relay_1 7 // Arduino Digital I/O pin number #define Relay_2 8 #define Relay_3 9 #define Relay_4 10

void setup() /****** SETUP: RUNS ONCE ******/ { //-------( Initialize Pins so relays are inactive at reset)---- digitalWrite(Relay_1, RELAY_OFF); digitalWrite(Relay_2, RELAY_OFF); digitalWrite(Relay_3, RELAY_OFF); digitalWrite(Relay_4, RELAY_OFF); //---( THEN set pins as outputs )---- pinMode(Relay_1, OUTPUT); pinMode(Relay_2, OUTPUT); pinMode(Relay_3, OUTPUT); pinMode(Relay_4, OUTPUT); delay(4000); //Check that all relays are inactive at Reset

}//--(end setup )---

void loop() /****** LOOP: RUNS CONSTANTLY ******/ { //---( Turn all 4 relays ON in sequence)--- digitalWrite(Relay_1, RELAY_ON);// set the Relay ON delay(1000); // wait for a second digitalWrite(Relay_2, RELAY_ON);// set the Relay ON delay(1000); // wait for a second digitalWrite(Relay_3, RELAY_ON);// set the Relay ON delay(1000); // wait for a second digitalWrite(Relay_4, RELAY_ON);// set the Relay ON delay(4000); // wait see all relays ON //---( Turn all 4 relays OFF in sequence)--- digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF delay(1000); // wait for a second digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF delay(1000); // wait for a second digitalWrite(Relay_3, RELAY_OFF);// set the Relay OFF delay(1000); // wait for a second digitalWrite(Relay_4, RELAY_OFF);// set the Relay OFF delay(4000); // wait see all relays OFF

}//--(end main loop )---

//*********( THE END )***********

Because I am using a Bluetooth chip to connect my phone to the arduino the code is easy to grab from any website that has a corresponding app that is compatible with your phone. I found ArduDroid, a very user friendly website that steps you through the code for the bluetooth. I suggest reading this website and using his code and his app on the google play store. Thank you Hazim Bitar for making this easy to follow website!

Step 4: Conclusion

So I have concluded that this is a fairly easy project to do and a fairly cheap educational experience. I can lay in bed now and turn my lights off at night and turn my fan on so I can fall asleep. I have been using for a few weeks before writing this and I have not burnt the apartment down with this project and I have confidence to leave it plugged in while I am not in the building. In the future I want to add the ability to connect the arduino to the internet via WiFi or Ethernet. This will allow me to turn my lights on before I get into the apartment (Bluetooth range) and monitor what is on and off from where ever in the world I am located. Keep posted for updates, changes and adjustments! Please point out anything that needs to be addressed, changed, or altered. This is my first post, so please be easy on me!