Brijesh Singh
Published © GPL3+

Smart Power Strip

No more energy loss. Easily switch ON/OFF individual appliances connected to a power strip with your smartphone or PC.

AdvancedFull instructions provided5 hours683
Smart Power Strip

Things used in this project

Hardware components

Node MCU 12E ESP8266
×1
PC817 optoisolator
×1
2n2222 NPN transistor
×1
Hi-Link AC-DC 5W 5V converter
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Screw terminal 2pin and 4pin
×1
Sugar cube Relay SPDT 5V
×1
3mm red led
×1
5mm blue led
×1
Resistor 220
×1
Male header strip
×1
Female header strip
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Electrical Wire 1.5mm Red and Yellow
×1
ready Electrical switch box
Arrange from local store, while make sure it have 4 socket support with one switch and indicator
×1
2-pin plug
any 2 pin plug will be ok
×1
3-pin Socket
Arrange from local store
×1

Software apps and online services

Arduino IDE
Arduino IDE
Cayenne
myDevices Cayenne
KiCad EDA

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter
Wire Striper
Screwdriver Tool Set

Story

Read more

Schematics

Power Module

Powermodule i04ch5y8hg

ESP8266 GPIO pins and Supply

since it was my first version of pcb, so kept these pins for debugging and testing more sensors.
Espgpio and supply pins kgubof7b43

Relay Drive Part

I have shown actual component in circuit, that is S8050 transistor and zener diode. But instead I have used 2n2222 npn transistor and 1N4007 diode as a replacement.
Relaysection moy33dkaej

Code

smartPowerStrip.ino

Arduino
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. 

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid[] = "L......rt";            //Add your home wifi network ssid 
char wifiPassword[] = "Au.......11";   //Add wifi password

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "38.....-7c...11e7-9d..b-f.......de";        //Add your username
char password[] = "f2......44d....................9c8";    //Add your password
char clientID[] = "53....ee0-af12-1...e7-b177-......599";        //Add your clientID

//GPIO pins used to drive relay
const int output1 = 14;           //NodeMCU GPIO14 pin 
const int output2 = 12;           //NodeMCU GPIO12 pin 
const int output3 = 13;           //NodeMCU GPIO13 pin 
const int output4 = 15;           //NodeMCU GPIO15 pin 

//GPIO pin to Test cloud connectivity(Blue Led)
const int cloudTestLed = 5;


void setup() {
  //configure GPIO pins as output
  pinMode(output1, OUTPUT);
  pinMode(output2, OUTPUT);
  pinMode(output3, OUTPUT);
  pinMode(output4, OUTPUT);

  //cloud connectivity test Blue LED 
  pinMode(cloudTestLed, OUTPUT);
  
  //Active low pins so 
  digitalWrite(output1, HIGH); 
  digitalWrite(output2, HIGH);
  digitalWrite(output3, HIGH);
  digitalWrite(output4, HIGH);
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  digitalWrite(cloudTestLed, HIGH);
  delay(500);
  digitalWrite(cloudTestLed, LOW);
  delay(500);
  digitalWrite(cloudTestLed, HIGH);
  delay(500);
  digitalWrite(cloudTestLed, LOW);
  delay(500);
}

void loop() {
  int num;
  Cayenne.loop();
}


CAYENNE_IN(0)
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
  digitalWrite(cloudTestLed, HIGH);
  delay(1000);
  digitalWrite(cloudTestLed, LOW);
  delay(1000);
  digitalWrite(cloudTestLed, HIGH);
  delay(1000);
  digitalWrite(cloudTestLed, LOW);
  delay(1000);
  
}

CAYENNE_IN(1)
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
  if(getValue.asInt()){
      Serial.println("SwitchON 1");
      digitalWrite(output1,0); //Device will be SwitchON since Active low switch
    }
  else {
      Serial.println("SwicthOff 1");
      digitalWrite(output1,1); //Device will be SwicthOff since Active low switch
    }
}

CAYENNE_IN(2)
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
  if(getValue.asInt()){
      Serial.println("SwitchON 2");
      digitalWrite(output2,0); //Device will be SwitchON since Active low switch
    }
  else {
      Serial.println("SwicthOff 2");
      digitalWrite(output2,1); //Device will be SwicthOff since Active low switch
    }
}

CAYENNE_IN(3)
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
  if(getValue.asInt()){
      Serial.println("SwitchON 3");
      digitalWrite(output3,0); //Device will be SwitchON since Active low switch
    }
  else {
      Serial.println("SwicthOff 3");
      digitalWrite(output3,1); //Device will be SwicthOff since Active low switch
    }
}

CAYENNE_IN(4)
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message"); 
  if(getValue.asInt()){
      Serial.println("SwitchON 4");
      digitalWrite(output4,0); //Device will be SwitchON since Active low switch
    }
  else {
      Serial.println("SwicthOff 4");
      digitalWrite(output4,1); //Device will be SwicthOff since Active low switch
    }
}

Credits

Brijesh Singh

Brijesh Singh

3 projects • 13 followers
Maker and Electronics Engineer likes to Make and share DIY Hardware projects. DM for business - Hardware Prototyping solution
Contact

Comments

Add projectSign up / Login