Street Light Automation Using IoT
Street Light Automation Using IoT
Street Light Automation Using IoT
On
Ashwin Vinod
17BES7042
School of Electronics Engineering
VIT-AP University
Amaravati, Andhra Pradesh.
Under the Guidance of
1
CONTENT
1. INTRODUCTION 4
1.1 Motivation
1.2 Problem Statement
1.3 Major aspects of the projects
2. WORKING OF THE SYSTEM 5
3. HARDWARE USED AND SCHEMATICS 8
3.1 Components used
3.2 Functionality
3.3 Circuit Schematics
4. SOFTWARE ASPECT 22
5. CONCLUSION 27
6. APPENDIX 28
7. REFERENCES 43
2
INTRODUCTION
Motivation:
The street light is manually switched on and off by a shopkeeper, who is close to
the supply unit. However, being a busy person, he does tend to forget to switch off
the lights in the morning. Now, this may seem reckless, but to be fair to the
shopkeeper, he may also forget at times, and electricity is wasted in all this time.
Such is also the case in many such areas. The use of IoT for automation could
provide a solution for this issue.
Problem Statement:
The current street lamps present in Indian streets are controlled manually. This
process can be automated. Controlling light based on movement in the proximity
as a parameter would be an effective solution. Also, the lights are to be activated
only at night. Not in daylight.
The project will use many different procedures to reach the conclusion:
1. Real-time monitoring of the street lights using ThingSpeak.
2. Designing a circuit for the above application.
3. Remote access to System
3
WORKING OF THE SYSTEM
Working of IR proximity sensor:
● A sensor module is built around the following core components:
The flame and radiation stimuli are both picked up by this module. It can
also detect conventional light sources with wavelengths ranging from 760nm
to 1100nm, thanks to YG1006. The YG1006 phototransistor is a high-speed,
high-sensitivity NPN silicon phototransistor. The sensor is sensitive to
infrared radiation due to its black epoxy. A detection distance of up to 100
cm is possible. A digital or analogue signal can be produced by the Flame
sensor.
The reflected beam will be received by the receiver diode, confirming the
presence of the item and causing the associated LED to illuminate. The IR
4
sensor has three pins: two for VCC and ground, and one for output. If an
item is detected, the IR sensor's output increases.
For our application, Infrared sensors are used to determine whether or not
someone is crossing the roadway. It detects the presence of a barrier or
movement in the immediate vicinity. The transmitter will send out infrared
rays, which will be reflected back if they hit something like a human,
animal, or car. Because the street light will only turn on if someone is
present on the street, this strategy will save a large amount of power. We
have
5
Fig.3: Basic circuit logic for LDR connected to an MCU
The preset resistor can be increased or decreased in order to vary resistance,
making the circuit more or less sensitive. Arduino receives a response from
the LDR.
6
HARDWARE USED AND SCHEMATICS:
Microprocessor:
● Microprocessors are integrated circuits which only house a central
processing unit and don’t have peripherals like Random Access memory
(RAM), Read Only Memory (ROM), I/O ports or clock circuits and they
have to be connected externally.
Microcontroller:
● Microcontrollers consist of a CPU, which is a microprocessor and possess a
CPU along with RAM, ROM, and other peripherals on the same chip.
Embedded Systems:
● Because embedded systems are so prevalent in this world, it is important for
us to understand them. Many modern devices allow us to perform many
tasks effectively, despite ignoring the basis of their operation. For example,
we frequently use TVs, radios, microwave ovens, etc. An embedded
controller is a combination of microprocessor (or microcontroller) based
hardware and appropriate software or an interface to accomplish specific
tasks.
For our application we use the Arduino Uno Microcontroller.
Arduino Uno:
The Arduino Uno is an open-source microcontroller board designed by Arduino.cc
and based on the Microchip ATmega328P microprocessor. The board has a number
of digital and analogue input/output (I/O) pins that may be used to connect to other
expansion boards (shields) and other circuits. The board features 14 digital I/O pins
(six of which are capable of PWM output), 6 analogue I/O pins, and is
programmable through a type B USB cable using the Arduino IDE (Integrated
7
Development Environment). It may be powered by a USB cable or an external
9-volt battery, with voltages ranging from 7 to 20 volts.
Power Vin, 3.3V, 5V, GND When using an external power source, Vin is
supply.
is 50mA.
0-5V
8
Serial 0(Rx), 1(Tx) Receives and transmits TTL serial data.
voltages.
9
Working of ESP8266 Wifi module:
● Espressif's ESP8266 is a Wi-Fi enabled system on chip (SoC). It is mostly
used for development of IoT (Internet of Things) embedded applications.
ESP8266 comes with capabilities of:
● 2.4 GHz Wi-Fi (802.11 b/g/n, supporting WPA/WPA2)
● General purpose input/output (16 GPIO)
● Inter-integrated circuit (I²C) serial communication protocol
● Analog-to-digital conversion (10-bit ADC)
● Serial peripheral interface (SPI) serial communication protocol
● I²S (inter-IC sound) interfaces with DMA (direct memory access)
(sharing pins with GPIO)
● UART (on dedicated pins, plus a transmit-only UART can be enabled
on GPIO2)
● Pulse-width modulation (PWM)
It employs a 32-bit RISC CPU based on the Tensilica Xtensa L106 running
at 80 MHz (or overclocked to 160 MHz). It has a 64 KB boot ROM, 64 KB
instructionRAM and 96 KB data RAM. External flash memory can be
accessed through SPI. ESP8266 module is a low cost standalone wireless
10
transceiver that can be used forend-point IoT developments. To
communicate with the ESP8266 module, the microcontroller needs to use a
set of AT commands. Microcontroller communicates with the ESP8266-01
module using UART having a specified Baud rate.
11
6 Reset - Resets the module
Not only for AT commands but while getting started with ESP8266, we face
several problems and might want to flash the ESP8266.
Step 1:
First, you have to download the flashing tool and the firmware.
Step 2:
Unzip the folder and launch the Flashing tool from the folder, as shown below
12
Fig.5: This window appears on initializing setup
13
Step 3:
Now, a dialog box will open, as shown in the above image. The parameters are to
be set and to be configured the download path before starting flashing ESP8266.
Now, for configuring the download path include the files with the given address
from the firmware folder in the given sequence.
esp_init_data_default.bin 0xFC000
blank.bin 0xFE000
boot_V1.4.bin 0x00000
14
user1.1024.new.2.bin 0x01000
User2.1024.new.2.bin 0x81000
Step 4:
Now, turn ON the adapter to power the designed circuit. And, set the hardware to
Flash Mode. Press the reset button (pushbutton), then click on START to flash your
ESP8266. However, we do not have available hardware currently. Now, your
ESP8266 start flashing, and it will look like the below image:
15
Step 5:
As the flashing complete, the dialog box will look like the image below:
Step 6:
Now, open the Arduino IDE software, and select the PORT on which ther hardware
is connected.
16
After opening the serial monitor in Arduino and pressing the reset button, it will
show ready with some garbage value, on the output screen, like as the image
below:
Send ‘AT’ using the serial monitor, the ESP will respond with output ‘OK’, as
shown in the below image.
Fig.10: The output “ready” shows that ESP module responded to the board
17
Hence, the ESP8266 is flashed successfully for using AT commands with Arduino
IDE. These are representational values as this project is a simulation-based project,
real values are not available to show.
Circuit Description:
Connect the Arduino’s 3v3 (3.3V) output to ESP8266. The ESP8266 works with
3.3V and not 5V, so this is necessary. Connect the RES or RESET pin, When you
ground the reset pin, the Arduino works as a dumb USB to serial connector, which
is what we want to talk to the ESP8266. Connect the RXD pin of the Arduino to
the RX pin of the ESP8266. Connect the TXD pin of the Arduino to the TX pin of
the ESP. When we want two things to talk to each other over serial, we connect the
TX pin of one to the RX of the other (send goes to receive and the opposite). Here
we do not have the Arduino talk to the ESP8266 though, our computer is talking to
it via the Arduino. Connect GND and VCC. Finally CH_PD connects.
Circuit Schematic of the Smart Street Light automation system:
We are to connect the pins of the Arduino Uno to all the components. This requires
a schematic to ensure a closed and functioning circuit.
First, for the wifi module, we must ensure Tx and Rx UART pins are available for
use in the Arduino board. These would be connected to the ESP8266 wifi module.
Then, we must ensure 6 digital GPIO pins are set aside 3 of these would be for the
IR sensors, which will detect any vehicular motion on the street. The rest would be
for street lights, which will be connected to 1k ohm resistors. Lastly, we are to
connect the LDR to an analog GPIO pin. Apart from these connections, we must
18
connect the Vcc pins to the +5V for the 3 IR sensors. However, the Wifi module
requires a +3.3V supply. So, we are to use the pins accordingly.
Pins assigned to each component:
For LEDs:
D2 - LED3
D5 - LED2
D6 - LED1
For IR sensor modules:
D8 - IR sensor 2
D9 - IR sensor 3
D11 - IR sensor 1
For Wifi sensor:
D0- ESP8266 Rx
D1 - ESP8266 Tx
For LDR sensor:
A0 - LDR
19
Fig.11: Circuit Schematic for the Street Light Automation system
20
SOFTWARE ASPECT:
The software aspect of this project is just as essential as the hardware
component. To build a proper code, it is essential to have an idea of how the
flow of data works out. Creating an algorithm through a flow chart can give
a clearer insight to one while coding.
Flow of data:
21
Thingspeak API:
ThingSpeak is an open-source Internet of Things (IoT) application and API
to store and retrieve data from things using the HTTP and MQTT protocol
over the Internet or via a Local Area Network.
After this, we are to set up the data upload to the thingspeak website. For this, a
channel is needed to be created.
22
Fig.14: Creating a Channel with all fields of the sensors
After creating the channel, we go on to obtain the API keys for writing to or
reading from this channel.
23
After this we set up the ESP8266 - wifi module. What makes this an ideal
choice for our project is that it is easy to interface with various
microcontrollers and it can be programmed through the Arduino IDE itself.
Doing this will enable it to connect to any available wifi network.
The working code is attached in the Appendix.1 of this report. The serial
monitor result is attached below.
Since this is a simulation project, the graph screens on the channel would be blank,
as no real sensors are in place, however, the channel is linked to the IDE through
the program code and can be remotely accessed from the link provided below.
https://thingspeak.com/channels/1407207/private_show
(P.S: login with a ThingSpeak account is necessary to access channel)
24
Uploading the code onto an Arduino Uno board which is connected in
correspondence to the circuit schematic, we can obtain actual figures of the project.
25
CONCLUSION:
This project is the solution to saving electricity on a rather larger scale. The
arduino section of the code allows the system to remain autonomous and operate
based on the condition of sunlight falling on the LDR. Remote access to the system
through the Thingspeak API, which is connected with the Wifi module, enables a
user to monitor and control the switches for the lights from afar.
APPENDIX:
Code:
26
The working code from the Arduino IDE:
#include <ESP8266wifi.h>
#include <WiFiClient.h>
#include <WiFi.h>
#include <ThingSpeak.h>
/*Wifi credentials of LAN system to connect wifi module to it */
/*const char* ssid = "wifiSSID";
const char* password = "wifiPassword";*/
WiFiClient client;
/*API read and write keys from thingspeak*/
unsigned long myChannelNumber = 1407207;
const char * myWriteAPIKey = "0QPDW7082VX8TW93";
const char * myReadAPIKey = "Z4H0CZGOYBYRPSLD";
/*declaring variables */
27
/*LEDs*/
int led_1;
int led_2;
int led_3;
/*assigning GPIO pins to LDR, lights and IR sensors*/
int ir1 = 11;
int led1 = 5;
int ir2 = 8;
int led2 = 6;
int ir3 = 9;
int led3 = 2;
pinMode(ir2,INPUT);
pinMode(led2,OUTPUT);
28
pinMode(ir3,INPUT);
pinMode(led3,OUTPUT);
WiFi.begin("ssidname","ssidpassowrd");
ThingSpeak.begin(client);
}
/*digital value of IR sensors and analog of LDR*/
void loop() {
int s1 = digitalRead(ir1);
int s2 = digitalRead(ir2);
int s3 = digitalRead(ir3);
s3 = not(s3);
val = analogRead(ldr);
Serial.print(s1);
Serial.print(":");
Serial.print(s2);
Serial.print(":");
Serial.print(s3);
Serial.print(" ");
Serial.println(val);
/*if analog value of LDR<800, it is set into nightmode and IR sensors
conditional statements active*/
if(val<800)
{
if(s1==0)
29
{
digitalWrite(led1,LOW);
}
else
{
digitalWrite(led1,HIGH);
}
if(s2==0)
{
digitalWrite(led2,LOW);
}
else
{
digitalWrite(led2,HIGH);
}
if(s3==0)
{
digitalWrite(led3,LOW);
}
else
{
digitalWrite(led3,HIGH);
}
}
else
{
30
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
}
/*all the data is uploaded to the assigned fields in ThingSpeak API*/
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,led1, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 6,led2, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 7,led3, myWriteAPIKey);
/*We can control LEDs from the ThingSpeak website using read function
from ThingSpeak Library*/
led_1 = ThingSpeak.readIntField(myChannelNumber, 5, myReadAPIKey);
led_2 = ThingSpeak.readIntField(myChannelNumber, 6, myReadAPIKey);
led_3 = ThingSpeak.readIntField(myChannelNumber, 7, myReadAPIKey);
if(led_1==1)
{
digitalWrite(led1,HIGH);
}
else
{
digitalWrite(led1,LOW);
}
31
if(led_2==1)
{
digitalWrite(led2,HIGH);
}
else
{
digitalWrite(led2,LOW);
}
if(led_3==1)
{
digitalWrite(led3,HIGH);
}
else
{
digitalWrite(led3,LOW);
}
}
32
33
34
35
36
37
LDR Sensor datasheet:
38
39
IR sensor module:
40
41
REFERENCES:
● LDR datasheet:
https://www.sunrom.com/get/443700
● IR sensor module datasheet:
https://components101.com/asset/sites/default/files/component_datasheet/Datashee
t%20of%20IR%20%20Sensor.pdf
● Arduino Uno datasheet:
https://www.farnell.com/datasheets/1682209.pdf
● ESP 8266 Wifi module:
https://www.espressif.com/sites/default/files/documentation/0a-esp8266ex_datashe
et_en.pdf
42