Karthick
Created October 12, 2017 © GPL3+

IoT My home lighting device

ESP8266 Thing dev kit control home appliances like lights, fans, geezer, Coffee maker, etc to turn ON/OFF remotely using Cayenne My devices.

IntermediateFull instructions provided10 hours108
IoT My home lighting device

Things used in this project

Hardware components

SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
Grove - Relay
Seeed Studio Grove - Relay
×2
2AA Battery Holder for RTC
UDOO 2AA Battery Holder for RTC
×1
Seeed Studio Grove Servomotor
×1
Mp3 player
×1
Jumper wires (generic)
Jumper wires (generic)
×1
PCB board
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Cayenne
myDevices Cayenne
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
scissors
hacksaw
Screw driver kit
Gum
Allout waste box
Sparkfun ESP8266 box

Story

Read more

Schematics

Schematic

Circuit diagram for the IoT my home lighting device to turn On/OFF home appliances remotely Using ESP8266 WiFi module and Cayenne my devices dashboard.

Code

IoT Home lighting device program

Arduino
This program is to control the relay and servomotor for IoT home lighting.
// Project shows step-by-step program to connect to Cayenne using an ESP8266 to ON/OFF home appliances remotely.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.
// Be sure you had conneted ESP8266 board to your PC/LAPTOP system. 

#include <CayenneMQTTESP8266.h>   // Header files selsection to include ESP8266 Board
#include <Servo.h>                // Header files for servo motor
#define CAYENNE_PRINT Serial      // Serial communication.
#define SERVO_DIGITAL_PIN 0       // Pin 0 in defined for servo motor interface 
#define ESP8266_LED 15            // Pin 15 in defined to interface relay to ON/OFF home light/street light/table lamp. 
#define SONG 2                    // Pin  2 is defined to interface relay to ON/OFF Mp3/Fan/Mosquito jet.
 
// a flag to keep track of servos last position
int pos = 0;

// WiFi network info.
char ssid[] = "AndroidAP";   // Network SSID
char wifiPassword[] = "";   // No network password

Servo myservo;  // create servo object to control a servo


// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "4aebf510-ac8e-11e6-bb76-1157597ded22";
char password[] = "1d8edd969b5e12728f5d9293106bd9bbe8ab20bf";
char clientID[] = "ee02d690-a75d-11e7-98fe-97ee227ec16c";

void setup() {
  pinMode(ESP8266_LED, OUTPUT);             // Digital Channel 15 mode output 
   pinMode(SONG, OUTPUT);                   // Digital Channel 2 mode output 
  myservo.attach(SERVO_DIGITAL_PIN);        // Servo motor channel 0 for PWM signal  
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}


// Data read from Cayenne dashbord configurations
void loop() {
  Cayenne.loop();
}


// Channel 0 is asigned to control servo motor position  to point the table lamp towards the reader.
  CAYENNE_IN(0)  
{
   int pos = getValue.asInt();       // Read the position value from Cayeene dashboard
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // wait for next position
}


// Channel 15 is asigned to control relay which can ON/OFF the home appliances
// like Street lights/corridor lights/home lights/pendant lights/table lamp etc.
CAYENNE_IN(15)
{
  // get value sent from dashboard
  int V = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (V == 1) {
    digitalWrite(ESP8266_LED, HIGH);   // ON light
  } else {
    digitalWrite(ESP8266_LED, LOW);    // OFF light
  }
}


// Channel 2  is asigned to control relay which can ON/OFF 
// Music system/Fan/ Mosquito jet/Water geezzer/Cofee maker. 
CAYENNE_IN(2)
{
  // get value sent from dashboard
  int cV = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (cV == 1) {
    digitalWrite(SONG, HIGH);   // play Music or ON appliance
  } else {
    digitalWrite(SONG, LOW);    // Stop music or OFF appliances
  }
}

// ESP8266 can support upto 10 channels so we can interface Ten different home appliances.
// IoT home lighting device and can acess remotely.
// End.

Credits

Karthick

Karthick

12 projects • 13 followers
Hobbyist

Comments