Syed Sanoor
Published © GPL3+

Windows IOT - Automate your power outlets

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

AdvancedFull instructions provided23,960
Windows IOT - Automate your power outlets

Things used in this project

Story

Read more

Schematics

Wire up relay

Wire up the power cord to relay

Code

Relay

C/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);
    }

}

Samples

Sample code

Credits

Syed Sanoor

Syed Sanoor

3 projects • 83 followers
Developer

Comments