Introduction: 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
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
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)
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
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)
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
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
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
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)
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
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.
Attachments
Step 11: Enjoy!
Great You did it.
Enjoy GLO

Runner Up in the
Automation Contest 2017

Participated in the
Plastics Contest
11 Comments
Question 3 years ago
Hello sir when did this project realse and wat is rate of this
Question 3 years ago
Can we add a new program with relay to turn on/off the lamp? Please kindly reply it ASAP
Question 5 years ago on Step 5
In file included from /Users/mac/Documents/Arduino/glo/glo.ino:7:0:
/Users/mac/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTESP8266Shield.h:31:34: fatal error: ESP8266SerialLibrary.h: No such file or directory
#include "ESP8266SerialLibrary.h"
^
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
I'm getting this error. I don't know what is wrong in the code
please help
Answer 4 years ago
Hi. I've given the same problem that someone can help
Reply 4 years ago
install cayenne library from package provided by cayenne website. then go to sketch>install .zip library. the code has only headerfile names written in incorrect cases i.e dht.h should be DHT.h search the header file name and conver them to upper or lower case as needed.
Reply 4 years ago
can u please provide the link for "install cayenne library from package provided by cayenne website."
4 years ago
got errors while uploading the code. says : cayennemqttesp8266.h no file or directory found
#include <cayennemqttesp8266.h>
compilation terminated
-------------------------------------------
please help me in solving this error. i urgently need it
please do the needful pleaseeee
Question 4 years ago on Step 5
Sir, I couldn't connect nodemcu to cayenne . Cayenne keeps on displaying waiting for device. my only concern is conection to cayenne . everything else is fine.so i ran a new script by adel kasseh on youtube {to check connection it is as follows:
/////////////////////////////////
// Generated with a lot of love//
// with TUNIOT FOR ESP8266 //
// Website: Easycoding.tn //
/////////////////////////////////
#include
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include //IMPPORT LIBRARY FROM http://easycoding.tn/index.php/resources/
char Cayenneusername[] = "zzzzzzzzzzzzzzzzzzzzzzzz";
char Cayennepassword[] = "zzzzzzzzzzzzzzzzzzzzzzzzzz";
char CayenneclientID[] = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
void setup()
{
Serial.begin(9600);
WiFi.disconnect();
delay(3000);
Serial.println("START");
WiFi.begin("mywifi","williamx");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(3000);
Serial.print("..");
}
Serial.println("Connected");
Serial.println("Your IP is");
Serial.println((WiFi.localIP().toString()));
Cayenne.begin(Cayenneusername, Cayennepassword, CayenneclientID);
}
void loop()
{
Cayenne.virtualWrite(0,(random(10,20)));
delay(5000);
Cayenne.virtualWrite(1,(random(2000,3000)));
delay(5000);
}
the output of serial monitor is in image:
1) connection error;
2) your code runs flawlessly but couldn't connect to cayenne:
output:
Sketch uses 285468 bytes (27%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28128 bytes (34%) of dynamic memory, leaving 53792 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.6
2.6
esptool.py v2.6
Serial port COM6
Connecting....
Chip is ESP8266EX
Features: WiFi
MAC: cc:50:e3:56:2a:1d
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 289616 bytes to 208784...
Writing at 0x00000000... (7 %)
Writing at 0x00004000... (15 %)
Writing at 0x00008000... (23 %)
Writing at 0x0000c000... (30 %)
Writing at 0x00010000... (38 %)
Writing at 0x00014000... (46 %)
Writing at 0x00018000... (53 %)
Writing at 0x0001c000... (61 %)
Writing at 0x00020000... (69 %)
Writing at 0x00024000... (76 %)
Writing at 0x00028000... (84 %)
Writing at 0x0002c000... (92 %)
Writing at 0x00030000... (100 %)
Wrote 289616 bytes (208784 compressed) at 0x00000000 in 18.6 seconds (effective 124.3 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
6 years ago
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!
Reply 6 years ago
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!
Reply 6 years ago
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