Introduction: Home Automation System

About: Pursuing a B.S. in Computer Engineering at Georgia Tech.

Note: this project deals with high voltages, PROCEED WITH CAUTION!

Project Description

This is a simple tutorial for a Home Automation System developed using an Arduino UNO. This system allows a user to control a lamp through a custom website hosted on the Arduino (the Arduino is modeled as a server). On receiving a client request to turn on the lamp, the Arduino outputs a high signal to a relay circuit that connects the power source to the lamp. An off request signals the Arduino to output a low signal to the relay circuit, thereby cutting off the power source to the lamp.


My motivation for this project came from me having to get out of my bed every time I needed to turn off my lamp before sleeping. I decided to create a system that would not only allow me to control my lamp from my bed but also from anywhere in the world with internet access.

Why Home Automation

  • Due to the Internet of Things Home Automation is currently a very hot topic.
  • According to MarketsandMarkets, the home automation market is expected to grow from USD 32.11 Billion in 2015 to USD 78.27 Billion by 2022.
  • Having the convenience of accessing your home systems remotely can be a real time saver.
  • A complete and powerful system can provide energy saving and security benefits.

Step 1: Parts Needed

List of Parts and Purchase Links

  • Arduino UNO R3 ATmega328P (quantity: 1)

purchase link:


  • PowerSwitch Tail ii (quantity: 1)

purchase link:


  • RioRand (TM) Upgraded Ethernet Shield W5100 (quantity: 1)

purchase link:


  • NPN Transistor 2N3904 (quantity: 1)

purchase link:


  • Jumper Wires (quantity : 1 bunch)

purchase link:


Step 2: Circuit Schematic (Hardware)

Basic Hardware Principle

General Information on the Ethernet Shield

The RioRand Ethernet Shield allows an Arduino to connect to the internet. If purchased from the link provided in step 1, the shield will come with header pins that allow it to be directly stacked on top of the Arduino UNO. While the shield is stacked on top of the Arduino, digital pins 10, 11, 12, and 13 (SPI) cannot be used for general I/O, as these pins allow the two interfaces to communicate with each other. The Ethernet Shield should have the following MAC address: 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED; this information will be useful for developing the software of the system.

General Information on the PowerSwitch Tail

The PowerSwitch Tail ii is a relay circuit that has been designed for hobbyists. It provides a safe and isolated solution to connect a high voltage power supply to various devices. The Switch needs an actuating signal 3V dc (3ma) to 12V dc (30ma) for reliable results. The instruction in the PowerSwitch manual explains that the Switch can be connected to the Arduino by connecting the positive (digital pin from the Arduino) to terminal 1 (+in) and negative (ground) to terminal 2 (-in). However, this setup did not work for me. I believe the Ethernet Shield and Arduino stack had compromised the power being outputted from all my available digital pins. To solve this problem, I used the 5v power supply pin from the Arduino and an NPN transistor to control my Switch.

General Information on the NPN Transistor

The NPN transistor acts like a switch to control when a high signal is outputted to the PowerSwitch Tail ii. Because a transistor can drive a lot of current, the power required by the PowerSwitch Tail is sufficiently satisfied. The schematic shown above shows how the transistor should be connected to a 5v supply line on one end (collector) and ground on the other end (emitter). For more information on the orientation of the transistor, refer to the 2N3904 data sheet:

Steps to Follow

If you skipped reading everything above, these are the general steps you should follow:

Note: Do not power the Arduino or connect the PowerTail to a Power Source while carrying out these steps!

  1. Stack the Ethernet Shield on top of the Arduino UNO.
  2. Connect the Shield to an Ethernet port using an Ethernet cable.
  3. Use a 30mm flathead screwdriver to unscrew the +in and -in screws on the PowerSwitch Tail.
  4. Place jumper wires into the slots provides for +in and -in and tighten both screws to secure the wires in.
  5. Place the NPN transistor on the breadboard and connect it's base to Pin 8 of the Arduino.
  6. Use a jumper wire to connect the 5V pin and GND pin to the power rails of the breadboard.
  7. Connect the jumper wire of the +in terminal of the Switch to the +Ve hole of the breadboard (power rail).
  8. Connect the jumper wire of the -in terminal of the Switch to the collector of the transistor.
  9. Use a Jumper wire to connect the emitter of the transistor to the -Ve hole of the breadboard (power rail).
  10. Connect one of the AC terminals of the PowerSwitch to an outlet and the other to your lamp.

Step 3: Software

General Information

The code for this system has been derived from the server skeleton code provided by the Arduino IDE. I have built on this system to model the Arduino to host my Home Automation website. The Arduino provides an Ethernet library that allows you to do this with ease. The MAC address of the the Ethernet Shield is: 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED. This character sequence acts like a network address for packet routing in the Link layer of the internet. The next two sub sections highlight important information relevant to this projects about using Arduino's Ethernet and Client-Server libraries.

Important Code for void setup () { }

  • Since our application is an HTTP application our server port should be 80. In other words, port 80 will be the port our server will listen to for incoming connections and requests from clients. The following lines of code would set this up:
EthernetServer server(80);
  • Every device that connects to the internet needs an IP address for network layer routing. The following allows your device to obtain an IP address via DHCP and enables your server to listen to incoming connections:
Ethernet.begin(mac); // obtain an IP address<br>server.begin(); // start listening for incoming connections
  • To register your domain name (the URL to access your website), you would require to know the IP address assigned to your Shield. The following lines of code accomplish this task by printing your assigned address onto the serial monitor:
Serial.print("server is at ");<br>Serial.println(Ethernet.localIP());

Important Code for void loop () { }

  • When assigned an IP address via DHCP, ethernet devices are given a lease on the address for a certain amount of time. With Ethernet.maintain(), it is possible to request a renewal from the DHCP server. You may receive the same address, a new one, or none at all. The following code handles error scenarios for you:
// if lease renewal fails<br>  if (status== 1 || status == 3) {

	Serial.print("server is at ");
  • When a client is connected to your server, the client will usually send requests by sending data to the server. the available() function of the Server class returns a client object. This client object will evaluate to true if the client has data available for reading and false otherwise.
EthernetClient client = server.available();  

if (client) {<br>    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    char line[100];
    int index = 0;

  • The available() function of the Client class returns the number of bytes available for reading in the buffer. In order to know who the client is and what the request is, you can print the data being received onto the serial monitor by using Serial.write():
    while (client.connected()) {
	accessDenied = true; // used for password protection for the site
	if (client.available()) {
		char c =; // read the next byte in the buffer
		if(index < 100) {
			line[index++] = c;
  • If the data received contains a newline character and the current line is blank, it means that the HTTP request has ended and the sever can respond back by sending the corresponding HTML text and carry out actions as described in the code attached.

Step 4: Getting a Domain Name for Your Website

Domain Name Registration

Now that you have a website working, you can simple access it by typing in the IP address of your server into the browser. However, this might not be the most convenient thing to do. You would probably want an alias web address for your website. In order to do this follow these steps:

1. Purchasing a Domain Name

  • Go to :

  • Enter your desired web address and see if if is available
  • Create an account and purchase the domain name (should be around $0.99/year)

2. Once you have purchased your domain name, you can edit your DNS settings to direct web traffic to your desired IP address.

3. Modifying DNS Settings

  • Log into your 1and1 account
  • Click on Manage Domain
  • Under Domains click on Edit DNS Settings
  • Under A/AAAA and CNAME Records Enter your IP address in the IPv4 or IPv6 box depending on the IP address you have been assigned

Step 5: Demonstration and Future Potential

Future Potential

There are a number of potential future projects that can be built on this system but I will outline two:

  • An important aspect of home automation is security. One potential project could include setting up email alerts using the following libraries:Client.h, Mail.h and SMTPClient.h. Using an IR sensor to sense movement in your room, you could potentially configure the Arduino to send email alerts if someone walks into your room.
  • Another project could involve expanding the system to control other devices. This can be done by using one Arduino as the automation master or the HUB. This HUB will be the main server communicating and responding to client requests (this would include an Arduino and Ethernet shield). For each device (lamp) that needs to be connected to the automation system, we would set up a system similar to that described by this instructable but without the Ethernet shield. The HUB can then communicate with all the other slave Arduinos using an XBee shield.