Smart Street Light Using NodeMCU and IOT ThingSpea
Smart Street Light Using NodeMCU and IOT ThingSpea
Smart Street Light Using NodeMCU and IOT ThingSpea
by mohdfarhan
There have been a limited number of streets in smart societies, and over the last few decades, street lamps and
management regulation have been relatively simple. However, as the world has become a more prosperous community
and as urbanization has increased, the number of smart societies in modern cities has increased rapidly. As a result,
regulating and maintaining street lights for smart societies and cities became a problem. It is also considered to be the
rst generation of the original street light control, which is ine cient and wastes manpower. At the moment, street
lamps control much of the urban environment only through manual control, via a control switch installed in each street
lamp. A signi cant amount of electrical energy is lost. So we have created a solution for that problem which is an
automatic street light only using NodeMCU, LDR sensor and IR sensor. In this project, LDR sensor is function to glow only
when it in darkness and dark when only in brightness while for IR sensor is used to detect objects by sensing infrared
radiations re ected from the objects which means if there is an object passing by, the light will turn on and if there is no
object passing by, the light will turn o . This detection can be monitored through ThingSpeak and IoT platform on your
computer.
Supplies:
ESP8266 NodeMCU - 1
Micro USB cable - 1
LEDs -3
Jumper wires - Depends on connection
IR sensors - 3
LDR sensors -1
As showed on that video above, this step-by-step manufacturing of the project producing an output that will be save
and consume less energy which is the light will glow up only if there are any detection of an object. In fact, WiFi is used to
provide wireless communication, as ThingSpeak that we use in this project is to send the data in a graph gure toward
admin.
https://youtu.be/7_lOt-bkzqA
https://youtu.be/FbbTKxITW6E
Step 1: Open Arduino IDE and Go to Sketch -> Include Library -> Manage Libraries
Step2: Now search for ThingSpeak in library manager and install ThingSpeak library by MathWorks
Step 1: Now we will upload the LDR sensor, IR sensors and leds data on the ThingSpeak. Go to https://thingspeak.com/
and start by signing up if you don’t have account on it
Step 2: Replace SSID and password given in code with you Wi-Fi SSID and password
const char* ssid = "UniSZA-WiFi";
const char* password = "unisza2016";
Step 3: Copy channel number, read and write API keys from ThingSpeak as shown below
unsigned long myChannelNumber = 1778641;
const char * myWriteAPIKey = "CBWL1EPYK078WV49";
const char * myReadAPIKey = "HS82229EGKQ9IO2O";
Step 4: De ne variable for GPIO pins of leds and IR sensors, ADC channel
int ir1 = D0;
int led1 = D5;
Step 5: Set the pinMode for pins of led and IR sensor on the NodeMCU
pinMode(ir1,INPUT);
pinMode(led1,OUTPUT);
pinMode(ir2,INPUT);
pinMode(led2,OUTPUT);
pinMode(ir3,INPUT);
pinMode(led3,OUTPUT);
Step 7: Now we take digital value of the IR sensors and analog value of LDR sensor and store them in variables.
int s1 = digitalRead(ir1);
int s2 = digitalRead(ir2);
int s3 = digitalRead(ir3);
int l1 = digitalRead(led1);
int l2 = digitalRead(led2);
int l3 = digitalRead(led3);
val = analogRead(ldr);
Step 8: Initialize back the declaration of IR, LDR sensor reading and led to display at the serial monitor
Serial.print(s1);
Serial.print(":");
Serial.print(s2);
Serial.print(":");
Serial.print(s3);
Serial.print(":");
Serial.print(l1);
Serial.print(":");
Step 10: Finally upload the data on the ThingSpeak cloud by using function ThingSpeak.writeField(). It take channel
number, eld number, data (you want to upload in respective eld) and write API key. Here we are uploading LDR sensor
data, IR sensors data and LEDs data to the ThingSpeak cloud.
ThingSpeak.writeField(myChannelNumber, 1,val, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 2,s1, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 3,s2, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 4,s3, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 5,digitalRead(led1), myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 6,digitalRead(led2), myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 7,digitalRead(led3), myWriteAPIKey);