Introduction: GLO: IoT Smart Light

Picture of GLO: IoT Smart Light

Too lazy to turn on/off your bedroom light while in the night? or Stuck in the middle of the night searching for your bedroom light switches? Maybe you should try building GLO!

GLO: IoT Smart Light!

Here Comes The Story of How GLO Born

I am such a lazy person, who usually forgets to turn off my room light all the time when I am leaving the room. The light switches are little far away from my bed so it is a little bit hard to turn on /off my room light when I am in the bed, especially in the middle of nights. I am also a fan of colors, everyone like colors, right?!

So, I decided to solve this problem. Maybe you also in search of something that will solve this?!. I came up with an idea and named it 'GLO'!

FEATURES OF GLO

  • GLO Can be set to any colors as you wish.
  • GLO will automatically turn its light ON when anyone's presence in the room.
  • GLO can automatically turn its light ON when the room gets dark.
  • GLO is capable of sending emergency messages and activates alarm when any intruders breach into your room(in SECURITY MODE)
  • GLO can sense temperature and humidity if temperature or humidity rise rapidly, then it will send emergency messages and will activate the alarm.

HOW GLO WORKS:

GLO has three MODES:

1. AUTO MODE( DEFAULT)

GLO will automatically turn on the light when in dark and also in the presence of any person in the room. GLO will get automatically turned off while nobody present in the room or the room is in full of light.

2. LAMP MODE AUTO MODE

is not ideal in all the time because it depends on the situation. You can turn ON the LIGHT MODE in the GLO if you needed to use it in any condition. you can set the lights to any color as you wish.

3. SECURITY MODE

When you are not present in your home and busy in enjoying your vacation with your family in somewhere else, GLO will take care of your home from intruders. You can turn ON the SECURITY MODE. When PIR senses motion of any living beings, GLO will send an emergency E-mail and an SMS to you and related recipients and will activate the security alarm built in GLO. If someone pranks you, don't worry. There is a 'FALSE SAFE' button, just tap on it and the alarm will go silent. GLO will also monitor temperature and humidity, if any of them goes wrong then GLO will send emergency messages and will activate the security alarm.

Now, Enjoy making!

Step 1: Things You Needed

Picture of Things You Needed

Here is everything you will need to make GLO yourself.

Electronics Parts:

  • NODEMCU ESP8266
  • DHT11
  • NEOPIXEL RING(12 LEDs)
  • PIR sensor
  • LDR
  • BUZZER
  • 1K Resistor

For Making PCB

  • General Purpose PCB
  • Soldering Iron or Station
  • Female header(15 pins x 2)
  • Soldering Wire and Paste
  • Some Sort of HookUp Wires

General Components

  • General purpose BreadBoard
  • Some Jumper Wires
  • Multimeter(for fixing circuit problems)

For Making Enclosure

  • 3mm Transparent Acrylic Sheet
  • Araldite Epoxy Glue
  • Wooden Textured Vinyl Sheets
  • Utility Knife

The enclosure is made with the help of a laser cutter. I will provide the files for making the enclosure later.

The project is fully opensource you can find them here.

Step 2: Setting Up Your Arduino IDE

Picture of Setting Up Your Arduino IDE

What Is NodeMCU ESP8266

NodeMCU(ESP8266) is is a development board based on ESP8266 microcontroller. The esp8266 have an inbuilt WiFi feature, That can allow us to connect to nearby WiFi network and make cool IoT projects.

Note: For this Project, you can use any kind of ESP866 based board. I recommend using NodeMCU

First thing first. Download and install Arduino ide in your PC or Mac. After installing Arduino IDE. You need to set the additional board manager for the ESP8266 Board(NODEMCU).

 Goto Files => Preferences or simply CTRL + comma

You can see Additional Board Manager URLs. Copy and paste the below URL in there.

After that click 'OK'

Then

Go to Tools => Boards => Board Manager 

And search for "ESP8266 Community"

select 'esp8266 community' and install

After a successful install, Now You need Three Library.


Please Note: Without these libraries, your code will not compile, It is mandatory.

 Goto Sketch =>Include Library => Manage Library 

Search for 'DHT11'

Just install the library by the 'Adafruit'.


Not completed yet, still remaining two libraries to install.

  • Search again for 'Adafruit Neopixel' and then install it.
  • Search again for 'CayenneMQTTESP8266' and install it.

Now we successfully set up the Arduino IDE.

Step 3: Setting Up Cayenne(IoT Cloud Platform)

Picture of Setting Up Cayenne(IoT Cloud Platform)

Now you need to setup your cayenne account.

Are you thinking what is cayenne?

Here is my answer in a few word "Cayenne is an MQTT based drag and drop IoT platform to build IoT based projects.Like Blynk IoT platform"

In order to use cayenne first, you need to create a Cayenne account SignUp if you already have an account then login to your account. Click 'Add New '

add new

In the menu, list select 'Device/Widget' Scroll down and select 'Bring your own device'

'select bring your own thing'

Save MQTT USERNAME, MQTT PASSWORD, CLIENT ID (it is important).

Now it will show 'Waiting for the Device to Connect' leave the window there.

Step 4: Wire the Circuit

Picture of Wire the Circuit

Now its time for wiring your Circuits. Just follow the Wire diagram that I gave Above.

Connect everything carefully. Don't make wrong connections.

After successfully wired everything. Let us upload the code!

Step 5: Upload the Code Into NodeMCU(ESP8266)

Picture of Upload the Code Into NodeMCU(ESP8266)

Connect the NODMCU to your PC or MAC via a Micro-USB cable and copy/paste the below code into your Arduino IDE and save it.

ARDUINO CODE:

=============================================================================== 
|                     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----------------------------------------------

Select the ' NodeMCU 1.0(ESP-12EModule) ' from the Tools=> Boards

Select the 'COM PORT', that your device has connected to your PC/MAC.Then Click Upload Button.
After successfully upload the code. Then the cayenne will redirect into your Dashboard. Then you can see the Temperature, Humidity, PIR, LDR values in the Dashboard. Change their names and Icons to as you wish.

Step 6: Setting Up Cayenne DashBoard

Picture of Setting Up Cayenne DashBoard

Now you need to add some controls into your cayenne DashBoard.

1. Adding Sliders For Controlling RGB Light

Go to Add new => Devices & Widgets scroll down and select Slider
  • Name it RED
  • Data = Analog Actuator Channel = 4
  • Min Value = 0
  • Max Value =255

then click 'Add Widget' Add two More Sliders For GREEN AND BLUE (green channel = 5, blue channel = 6).

2. Adding SECURITY MODE Button

Go to Add new Devices& Widgets => scroll down and click Button
  • Name it LAMP MODE
  • Data = Digital Actuator
  • Channel = 8

Choose Icon that you like.

3. Adding FALSE SAFE Button

Go to Add new Devices& Widgets => scroll down and click Button
  • Name it FALSE SAFE
  • Data = Digital Actuator
  • Channel = 9

Choose Icon that you like

Step 7: Adding Triggers for Notification

Picture of Adding Triggers for Notification

Now You need to add triggers for

Intruder

Temperature Below 10c

Temperature above 40c

Humidity above 85

Humidity below 15

Note if you need to skip any of these then skip it

1. Setting Intruder Trigger

Go to Add new Trigger => New Trigger

Drag and drop the device from left side to IF box

  • set minimum val = 0
  • max val = 1
  • value = 0
  • set as above

In the right box select, notify and add recipient (give your email id).

2. Setting Temperature Trigger

Go to Add new Trigger => New Trigger

Drag and drop the device from left side to IF box

enter details

  • set minimum val = 0
  • max val = 100
  • value = 40(for below value just give it 10)

set as above In the right box select. notify and add recipient (give your email)

3. Setting Humidity Trigger

Go to Add new Trigger => New Trigger

Drag and drop the device from left side to IF box

  • set minimum val = 0
  • max val = 100
  • value = 85(for below value just give it 15)
  • set as above

In the right box, select notify and add recipient (give your email)

Note: The threshold must be set into according to your environment. the above thresholds is set to my environment. so change it.

Step 8: Testing Everything

Picture of Testing Everything

After uploading code to ESP8266 and setting up the Cayenne dashboard. I power the circuit from a USB port of my laptop and check everything works correctly (If everything works correctly, you will get values of the sensors in Cayenne Dashboard). You also need to check everything before you make the PCB yourself.

Step 9: Making PCB(Optional Step)

Picture of Making PCB(Optional Step)
Note: This is an optional step unless you need to make everything on a PCB!


I'am decided to make my own enclosure for a sturdy and neat look. So, I need to maximum shrink my circuits to fit in the enclosure. I Soldered everything on a General Purpose PCB. It perfectly seats in my custom made enclosure.

For powering the board I use a JST SM(male/female) connector and soldered the RED wire into the VIN pin of the NodeMCU and BLACK wire into the GND pin. I've used the 5-volt wall adapter for the power source, I removed the adapter's 5-volt pin and connected a female JST SM connector. I tried 9-volt wall adapter before and fried my NodeMCU board. So, I recommend only a 5-volt.

I'm provided the schematics in the above images!

After soldering everything on the PCB. Make sure you are not made any mistake!



Step 10: MAKING ENCLOSURE

Picture of MAKING ENCLOSURE

I planned to use GLO in my daily life. A sturdy and beautiful enclosure is a primary concern of mine. So, I decided a box that doesn't need any screws to fix in Autodesk fusion360. And Cutout all the parts on a 3mm acrylic using a laser cutter machine from nearby FabLab in my town, who provide using machines services for a few bucks.

For a classy look, I got some wooden textured vinyl from a local shop. I just cut out the vinyl in the shape of the parts and stick them. I try my best on that! I took a LED bulb and take the glass part and place it on the top for fixing neopixel (the diameter is 60mm) The press fit is a little bit loose because I forget to set the laser beam size. I used Araldite epoxy glue to fix them in place. The fact that, I messed up on the clear parts of the acrylic with some excess glues that in my hand. But still, it looks good. I provided the files below for laser cutting.

Step 11: Enjoy!

Picture of Enjoy!

Great You did it.

Enjoy GLO

Comments

diy_bloke (author)2017-10-16

No trouble using the PIR sensor with nodemcu? I hear many, many people complain about problems between these sensors and ESP8166.
Other than that, looks great!

DIYmechanics (author)diy_bloke2017-10-16

Thanks for the comment. I don't get any problem until now. I usually use espxxx based development board more than arduino nowadays. I have little experience on that.So, if you face any problem when using pir with a esp board. Please let me know. may be i can help you on that!

diy_bloke (author)DIYmechanics2017-10-16

Thanks. I have not had any problems as I didnt combine the two yet, but it is something i hear from various sources, so i was just wondering what your experience was

About This Instructable

1,427views

38favorites

License:

Bio: . I'am currently Doing my degree in Computer Science . I really love making things from scratch and loves Hiking .
More by DIYmechanics:NEXA : Smart  StoveGLO: IoT Smart LightIR Remote Controlled Home Automation
Add instructable to: