Project tutorial
Windows IOT - Automate your power outlets

Windows IOT - Automate your power outlets © GPL3+

Control your home power outlet from anywhere in the world using raspberry pi, zigbee and arduino (Azure enabled)

  • 23,834 views
  • 13 comments
  • 51 respects

Components and supplies

Apps and online services

About this project

Introduction

In this project we will see how to control the power outlets of your home natively and in cloud using raspberry pi running on windows 10 iot, xbee and arduino. All the code samples are available in github.


Why automate power outlets?

Instead of controlling the devices from cloud, if you could automate the power outlets, we can connect any devices to the power outlet and control them. In this project, I have taken examples to control a fan and light.


Lets get started with Bees

I have taken Xbee to transfer radio signals. One Xbee called the Co ordinator is connected to raspberry pi and the other called Router connected to power outlet. The Coordinator sends the signals based on our input to Router to control the power outlets.


Configure Xbees in AT Mode

Download and install XCTU.

To update the Zigbee (Xbee) firmware, I used adafruit FTDI adapter 

Please watch this tutorial on configuring the Xbees in AT mode.

Configuring Bees


You need to make sure that these two Xbees talk to each other before we proceed to the next step.


Set up the Receiver

We need the Zigbee Router, Arduino UNO R3, Xbee Shield for Arduino and Arduino relay shield.

Arduino Sketch

If the data from CoOrdinator Zigbee is ON1, we turn on the relay1. If the data is ON2 we turn on the relay2. Similarly we turn of the relay for OFF1 and OFF2

You must compile this in arduino ide and burn to arduino uno:

#define RELAY1 7

#define RELAY2 5

String state = "OFF";

void setup()

{

Serial.begin(9600);

pinMode(RELAY1, OUTPUT);

}

void loop()

{

//Check if serial data is availble

if(Serial.available() > 0){

state = Serial.readString();

Serial.println(state);

}


//If text is ON1. Turn on the relay1

if(state == "ON1\r\n")

digitalWrite(RELAY1,1);

//If text is ON2. Turn on the relay2

else if(state == "ON2\r\n")

digitalWrite(RELAY2,1);

//If text is OFF1. Turn off the relay1

else if(state == "OFF1\r\n")

digitalWrite(RELAY1,0);

//If text is OFF2. Turn off the relay2

else if(state == "OFF2\r\n")

digitalWrite(RELAY2,0);

//Do Nothing

else{

digitalWrite(RELAY1,0);

digitalWrite(RELAY2,0);

}

} 

Configure the power outlet (Precaution we are playing with high voltage)

Relays are age old technologies in the field of electronics. It acts as a switch. The input to the relay can be ac voltage (110 to 240 V). Using a microcontroller such as arduino, we can turn the relay on/ off

We are going to connect high voltage to the relay, please respect ac current and take extreme precaution while connecting the wires to relay. This is too dangerous, proceed at your own risk

Instead of directly configuring the relay to the power outlet, I used extension cord. The concept is same though.

In the extension cord, leave one wire as it is and clip the other wire. Connect on end of the wire to Common (C) and the other to NO (Normally Open)

Connect the Relay shield to Arduino, stack the Xbee Shield on top or the relay shield. Plug in the Zigbee configured as Router on the Xbee Shield

I used Xbee Shield to Connect the Xbee to arduino. Make sure that the settings in the shield is set to Xbee. This shield along with arduino can also be used to write the firmware settings when we set the switch to usb. It uses arduino's build in FTDI chip to write the data to Xbee.

Plug in the cords and power up the arduino using external battery source. The receiver is done.


Configuring the Server

To setup up the server we need the Raspberry Pi 2 running on windows 10 IOT and Zigbee set up as coordinator.

Connect the Zigbee to FTDI adapter, and 6 pin FTDI RS 232 USB cable to raspberry pi usb port. We will set up a webserver on the raspberry pi using UWP. The server will wait for user input and based on the selection, it will write the serial data to usb port in which the FTDI RS 232 cable is connected, the Zigbee will transmit this message as radio waves. We have already set up the router's DH and DL in the coordinator Zigbee, so the message is sent to correct Zigbee Router.

To know more about FTDI drivers for raspberry pi please see https://github.com/jark/ftdisample

Please follow this video to setup the server on Raspberry Pi.

Web Server


All the code samples are available in github.


Enable Azure

To control our home from anywhere in the world, we enable cloud services to our application.

You need to create a website and host it in azure. Create a Azure SQL DB to authenticate/ authorize the users for your site. Create a Azure Cloud Storage Service to take up our commands. Process these commands from Raspberry PI Blinky App and control your home.

You need to refer this article to create storage tables:

https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-tables/

To create Sql tables, refer this article:

https://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started/

Please watch the video tutorial on how to use azure for our project:

Enable Azure

Demo

I tried to show how you can control the power outlets in two ways,

  1. Accessing the in network raspberry web server url
  2. Through aspnet5 web application hosted in Azure
Demo

Conclusion

  1. This kind of automation solves many real world problems. By attaching additional sensors like light and motion detector, we can turn on/ off the light or atleast provide the data to user to save energy.
  2. Elderly people can use remote to control their power outlets. In this case, we need to have additional RFID device.
  3. We can create schedule to turn light on/ off so that the power can be saved.
  4. If there are any intruder, all lights can be turned on.
  5. On a vacation, no need to worry.. we can just shut off our home within a click of a button.
  6. No need to maintain your room temperature all the time, do it when you feel appropriate. Saves energy.

Code

RelayC/C++
To Control Relay
                       

#define RELAY1  7     
#define RELAY2  5
String state = "OFF";
void setup()

{    


Serial.begin(9600);
  pinMode(RELAY1, OUTPUT);       

}

void loop()
{   
   //Check if serial data is availble
    if(Serial.available() > 0){
       state = Serial.readString();
       Serial.println(state);
    }
    
    //If text is ON1. Turn on the relay1
    if(state == "ON1\r\n")
      digitalWrite(RELAY1,1); 
    //If text is ON2. Turn on the relay2
    else if(state == "ON2\r\n")
       digitalWrite(RELAY2,1); 
    //If text is OFF1. Turn off the relay1
    else if(state == "OFF1\r\n")
      digitalWrite(RELAY1,0);
    //If text is OFF2. Turn off the relay2
    else if(state == "OFF2\r\n")
      digitalWrite(RELAY2,0);
    //Do Nothing  
    else{
      digitalWrite(RELAY1,0);
      digitalWrite(RELAY2,0);
    }

}

Schematics

Wire up relay
Wire up the power cord to relay
Relay 2

Comments

Similar projects you might like

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 318,631 views
  • 101 comments
  • 767 respects

Home Automation using Raspberry Pi 2 (Windows 10 IoT Core)

Project tutorial by Christian Kratky

  • 139,662 views
  • 34 comments
  • 443 respects

OH HAI! on Windows 10 IoT Core

Project in progress by BuddyC

  • 14,011 views
  • 3 comments
  • 50 respects

Windows 10 IoT Core: UltraSonic Distance Mapper

Project showcase by Anurag S. Vasanwala

  • 57,381 views
  • 23 comments
  • 152 respects

Solar Tracker with Live Data Feed - Windows IoT

Project tutorial by Jed Hodson

  • 13,784 views
  • 1 comment
  • 26 respects

Home Smart Home

Project tutorial by Syed Sanoor

  • 82,779 views
  • 11 comments
  • 216 respects
Add projectSign up / Login