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
Fairchild semiconductor 1n4004. image
1N4007 – High Voltage, High Current Rated Diode
×1
Mfr 25frf52 1k sml
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
266 04
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:
Ide web
Arduino IDE
Cayenne logo hi
myDevices Cayenne
KiCad EDA
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)
Pro dmm box 600  26129.1449785766.500.659
Digilent Mastech MS8217 Autorange Digital Multimeter
Wire Striper
Screwdriver Tool Set

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.inoArduino
// 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

Img 20150629 wa0005
Brijesh Singh

DIY Maker, Hobbyist Engineer and Tinkerer

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login