suhail jr
Published © TAPR-OHL

GLO: IoT Smart Light

GLO is an IoT smart light, developed using ESP8266 and Cayenne IoT platform.

IntermediateFull instructions provided4 hours4,449
GLO: IoT Smart Light

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
SparkFun LDR
×1
SparkFun PIEZO BUZZER
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
SparkFun Female Header Pin
×1

Software apps and online services

Arduino IDE
Arduino IDE
Cayenne
myDevices Cayenne

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter

Story

Read more

Custom parts and enclosures

Download the files for laser cutting enclosure

the is the files you needed to cut out the enclosure parts.

Schematics

Wire Diagram

This is the Wire diagram of GLO

Schematics

This is the Schematics of GLO

Code

Arduino Code For GLO

Arduino
this the code you need to upload into your ESP8266 board using arduino IDE.
/*
===============================================================================
|                     GLO: IoT Smart Light   by suhail_jr                     |
===============================================================================
*/
// libraries

#include <CayenneMQTTESP8266.h>
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif


#define DHTPIN 4 // setting dht11 pin
#define DHTTYPE DHT11// setting type of the dht

#define PIN D5 // neopixel pin conected to d5
#define NUMPIXELS 12 // number of leds in neopixel ring
#define buzzer D7// set buzzer pin



DHT dht(DHTPIN, DHTTYPE);// object for dht11
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);// object for neopixel


 
char ssid[] = "your ssid"; 
char password[] = "wifi password";
char username[] = "cayenne-username"; 
char mqtt_password[] = "cayenne-mqtt-password";
char client_id[] = "cayenne-client-id";


const int LDRpin = A0;// ldr pin
const int PIRpin = D0;// pir pin
int LDRval = 0;// for reading ldr value
int PIRval = 0;// for reading pir value 
int temp;// for reading temperature value from dht11
int hum;// for reading humidity value from dht11

int r,g,b;// variables for storing red green and blue led mix values
int Cmode;// variable for storing security mode activate or deactivate
int TURN;// variable for manuale mode
int SAFE_MODE;// variable for false safe mode


void setup() 
  { 
pinMode(LDRpin,INPUT);// .....|
pinMode(PIRpin,INPUT);//......| Seting sensors and modules input or output
pinMode(buzzer,OUTPUT);//.....|
dht.begin();// starting dht11 sensor
Serial.begin(9600);
Cayenne.begin(username,mqtt_password,client_id,ssid,password);// starting cayenne 
pixels.begin(); // start neopixel ring
Serial.println("FIRE FLY BOOTED");
  
   }

  
void loop() 
{ 
   Cayenne.loop(); 
  
   // checking secuirity mode activated!
   
   if(Cmode==1)
  {
    buglerMode();// if secuirity mode active will call bugler mode function
  }
  else if(Cmode<1){
    setLight();// if not active then call setlight function
    
  }
  
hum = dht.readHumidity();// storing humidity value to hum variable
temp = dht.readTemperature();//storing temperature value to temp variable
LDRval = analogRead(LDRpin);// read and store ldr value
PIRval = digitalRead(PIRpin); // read and store pir value
Serial.println(PIRval);

// send all sensor values to cayenne
       Cayenne.virtualWrite(0,temp);
       Cayenne.virtualWrite(1,hum);
       Cayenne.virtualWrite(2,LDRval);
       Cayenne.virtualWrite(3,PIRval);
       
       
// checking temperature or humidity is in dangerous level       
if(hum>85&&hum<15){
  digitalWrite(buzzer,HIGH);
}
 if(temp>40&&temp<10)
  {
    digitalWrite(buzzer,HIGH);
  }

 // checking false safe mode      
 if(SAFE_MODE==1)
  {
    digitalWrite(buzzer,LOW);
  }
  
}

void setColor(int red,int green,int blue)
{
  for(int i =0;i<=NUMPIXELS;i++)// set every led into the color
  {
    pixels.setPixelColor(i,pixels.Color(red,green,blue));// seting color neopixel
 
    pixels.show();// activate neopixel
  }
}


void setLight()// checking manual mode active or not
{

if(TURN==1)
{
  manual();
}

  else
  {
     if(PIRval>0)
{
  setColor(r,g,b);
}
else if(LDRval<30)
{
  setColor(r,g,b);
}

else if(PIRval<1&&LDRval>10)
{
  setColor(0,0,0);
}

}
}


void buglerMode()// bugler mode's function
{

  if(SAFE_MODE==1)
  {
    digitalWrite(buzzer,LOW);
  }

  
  if(PIRval>0)

{
  
  digitalWrite(buzzer,HIGH);
  Serial.println("bugler on");
}

 
}


 void manual()// manual mod's function
 {

   setColor(r,g,b);
 }

//recieve values from cayenne
 
    CAYENNE_IN(4)
{

  r= getValue.asInt();// recieve red value for neopixel from cayenne
   
 
}
CAYENNE_IN(5)
{

  g= getValue.asInt();// recieve green value for neopixel from cayenne
  
   
}


 CAYENNE_IN(6)
{

  
   
    b= getValue.asInt();// recieve blue value for neopixel from cayenne

}

CAYENNE_IN(7)
{
  Cmode =getValue.asInt();// recieve commands for security mode
Serial.println(Cmode);
}

CAYENNE_IN(8)
{
  TURN = getValue.asInt();// recieve commands for manual mode
}

CAYENNE_IN(9)
{
  SAFE_MODE = getValue.asInt();// recieve commands for false safe
}

//------------------------GLO -v1.0---------------------------------------------- 

  

Credits

suhail jr

suhail jr

8 projects • 75 followers
Maker and electronics enthusiast

Comments