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 an IoT Smart Light.
GLO is Developed with ESP8266, an IoT development board and with Cayenne, a drag and drop IoT Cloud Platform.
GLO is not just a light, you can change it into any color you like, and GLO can also act as a security monitor in your home while you are not there. You can monitor and control GLO through Cayenne Web App and through your mobile app.
Behind the idea of GLOFirst of all, I would like to describe, how I came up with this idea. 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 or off my room light when I am in the bed, especially in the 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 activate alarm when any intruders breaches 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.
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 a 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.
Things you need!Here are the components and materials you needed to do this project. Take your time and collect everything!
Please Note: I Soldered everything on a general purpose PCB to minimalize size and for a neat look. If your planning to just do it on a BREADBOARD, its fine. you can skip some steps!
Primary components
- NODEMCU ESP8266(You can also use Sparkfun Thing Dev Board)
- DHT11
- NEOPIXEL RING(12 LEDs)
- PIR sensor
- LDR
- BUZZER
- 1K Resistor
General componenets
- General adBoard
- Some Jumper Wires
- Multimeter (for fixing circuit problems)
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
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 or Sparkfun Thing Development Board
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.
http://arduino.esp8266.com/stable/package_esp8266com_index.json
- After that click 'OK'
Then Go to Tools => Boards => Board Manager
- And search for "ESP8266 Community"
- Click on the 'ESP8266 Community' and Install it.
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 setup the Arduino IDE.
Setting up CayenneNow you need to setup your cayenne account.
Are you thinking what is cayenne?
Here is my answer in a few word "Cayenne is MQTT based drag and drop IoT platform to build IoT based projects."
In order to use cayenne first:
- You need to create a Cayenne account SignUp if you already have an account then SIgnIn
- Then login to your account.
- Click 'Add New '
- In the menu list select 'Device/Widget'
- Scroll down and select 'Bring your own device'
- Save MQTT USERNAME, MQTT PASSWORD, CLIENT ID (it is important).
Now it will show 'Waiting for the Device to Connect' leave the window there.
Wire the circuitNow its time for wiring your circuits. Just follow the wire diagram that I gave below.
After successfully wiring everything, lets upload the code!
Uploading Arduino code to NodeMCUConnect the NODMCU to your PC or MAC via a Micro-USB cable and copy/paste the code into your Arduino IDE and save it or (Download the code from the attachment section).
Note: You must need to change the SSID and PASSWORD into your WiFi network's SSID and PASSWORD. Also change the Cayenne credentials(MQTT USERNAME, MQTT PASSWORD, CLIENT ID) into that we got earlier from while setting up the Cayenne.
/*
===============================================================================
| 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.
Setting up Cayenne DashboardNow you need to add some controls into your cayenne DashBoard.
1. Adding Sliders
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 SECURITY MODE
- Data = Digital Actuator
- Channel = 7
- Choose Icon that you like
3. Adding lamp 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
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 e-mail)
1. Setting Temperature 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 = 40(for below value just give it 10)
- set as above
- In the right box select. notify and add recipient (give your e-mail)
1. 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 mail)
Note: The threshold must be set into according your environment. the above thresholds is set to my environment. so change it.TESTING AND DEBUGGING
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.
Making PCB (optional step)Note: This is a option 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 the 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 instead of it for matching the connectors. I tried 9-volt wall adapter before and fried my NodeMCU board. So, I recommend only a 5-volt.
Here is schematics below:
After soldering everything on the PCB. Make sure you are not making any mistakes.
Making enclosureI 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 was, I messed up on the clear parts of the acrylic with some glues that in my hand. But still, it looks good.
I provided the files in the attachment section of this project. you can download it and make one your own from any local services!
Great, we're done!Great You did it. If you like, Thumps up on the project!
Some truth about GLOThis project took two days to complete. First day coding and wiring the circuit second day designing the enclosure and testing.
GLO will give you a perfect Ambient Light!
The light is only effective in the night. But it is really helpful. I like warm light, like the flame color. I set into that color while in the evening.
If you have an idea to add into GLO or you found any bug, contribute it into GLO. in the GitHub.
Sponsor of this projectSeeed Fusion PCB Assembly Service offers one-stop prototyping for PCB manufacture, PCB assembly and as a result they produce superior quality PCBs and Fast Turnkey PCBA from 7 working days. When you prototype with Seeed Fusion, they can definitely provide Free DFA and Free functional tests for you! Check out their website to know about their manufacturing capabilities and service. Link to Seeed Fusion Service : https://www.seeedstudio.com/prototype-pcb-assembly.html
Happy making :)
Comments