Turn any plug point into wireless switch

                                          

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.



                                           




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:

1x  Arduino Uno
4x  10A 220VAC, 5VDC activation Relay Board
1x  Extension board
1x  12v 2amp adapter

You can buy these online through below links



Step 2: Wiring CIRCIUT



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 Amazon 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;

//*********(CODE BEGINS)*******

#include <SoftwareSerial.h> // for bluetooth communication

int s1 = 4; // relay output
int s2 = 5; // relay output
int s3 = 6; // relay output
int s4 = 7; // relay output
int intdata;

SoftwareSerial mySerial(10, 11); //Communication pin defined for blurtooth


void setup()
{
pinMode(8,OUTPUT);
digitalWrite(8,HIGH); //For bluetooth power as arduino has only ony point for 5v supply
Serial.begin(9600);

 while (!Serial)
 { ;  }
mySerial.begin(9600);

pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT);
pinMode(s3,OUTPUT);
pinMode(s4,OUTPUT);
}


void loop()
{

if(mySerial.available())// It will read the serial data and store in the intdata
{
  intdata=mySerial.read();
 }


if (intdata == 'a') // Different conditions for controlling the relay to turn them on & off
{
  digitalWrite(s2,HIGH);
  }

  if (intdata == 's')
{
  digitalWrite(s2,LOW);
  }

  if (intdata == 'z')
{
  digitalWrite(s3,HIGH);
  }

  if (intdata == 'x')
{
  digitalWrite(s3,LOW);
  }

  if (intdata == 'q')
{
  digitalWrite(s1,HIGH);

 }

  if (intdata == 'w')
{
  digitalWrite(s1,LOW);
  }

  if (intdata == 'e')
{
  digitalWrite(s4,HIGH);
  }

  if (intdata == 'r')
{
  digitalWrite(s4,LOW);
  }

  if (intdata == 'g') // To turn all relays on
  {
  digitalWrite(s1,HIGH);
  digitalWrite(s2,HIGH);
  digitalWrite(s3,HIGH);
  digitalWrite(s4,HIGH);
  }

  if (intdata == 'f') // To turn all relays off
  {
  digitalWrite(s1,LOW);
  digitalWrite(s2,LOW);
  digitalWrite(s3,LOW);
  digitalWrite(s4,LOW);
  }

}


//*********( 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 " Bluetooth electronics", a very user friendly website that steps you through the code for the bluetooth.
The app is available on google play store. Below image, is the app  which i have used for the project.



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. 

Post a Comment

1 Comments

  1. Thanks for the valuable yet cheap project 😉

    ReplyDelete