Street Light Automation Using IoT

Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Project Report

On

SMART STREET LIGHT AUTOMATION


USING ARDUINO UNO
Submitted to

ELECTRONICS CORPORATION OF INDIA LIMITED


Secunderabad, Telangana
Submitted by

Ashwin Vinod
17BES7042
School of Electronics Engineering
VIT-AP University
Amaravati, Andhra Pradesh.
Under the Guidance of

Ms. MONICA KAMERA


CED
Center & Resource Management
ECIL, Hyderabad
ABSTRACT
The main objective of this internship project was to create a street light monitoring
system. This system is to work automatically based on the sunlight falling on the
LDR sensor. This is coupled with an IR proximity sensor to activate lights
depending on the surroundings.
The working of this system is such that the input is taken from sunlight and any
vehicles in the vicinity. If there is no sunlight but vehicles are around, the light
would be activated. However, what makes this project even more special is that it
turns off the street lights when no other vehicles are around. The data from street
lights can be analyzed by making use of a ThingSpeak API.

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.

Major Aspects of the Project:

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.

Fig.1: Ideal base circuit of IR proximity sensor module

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

Working of Light Dependent Resistor(LDR):

● The resistivity factor of a light dependent resistor (LDR), also known as a


photoresistor, is a function of electromagnetic radiation. As a result, they are
light-sensitive sensors that are comparable to human eyes. They're composed
of high-resistance semiconductor materials.

Fig.2 Representative image of an LDR sensor


A photo conductivity principle governs the operation of an LDR. Photo
conductivity is an optical phenomena in which the conductivity of a
substance is diminished when light is absorbed by it. When light shines on
the LDR, however, its resistance reduces, and current flows into the first
transistor's base, then the second transistor's base.

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.

Guide to source illuminations:

Light Source Illumination LUX units


Moonlight 0.1
60W bulb at 1 meter distance 50
1W MES Bulb at 0.1 m 100
Fluorescent Lighting 500
Bright Sunlight 30,000

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.

Arduino Uno Pin Configuration:

Pin Category Pin Name Details

Power Vin, 3.3V, 5V, GND When using an external power source, Vin is

the voltage input to Arduino.

Microcontroller and other components on the

board are powered with a 5V regulated power

supply.

3.3V: voltage generated by the on-board

voltage regulator. The maximum current draw

is 50mA.

GND stands for ground pins.

Reset Reset Resets the microcontroller.

Analog Pins A0 – A5 Used to provide analog input in the range of

0-5V

Input/Output Pins Digital Pins 0 - 13 Can be used as input or output pins.

8
Serial 0(Rx), 1(Tx) Receives and transmits TTL serial data.

External Interrupts 2, 3 An interrupt is triggered.

PWM 3, 5, 6, 9, 11 Outputs 8-bit PWM.

SPI 10 (SS), 11 (MOSI), 12 This is used for SPI communication.

(MISO) and 13 (SCK)

Inbuilt LED 13 In order to turn on the built-in LED.

TWI A4 (SDA), A5 (SCA) This is used to communicate with TWI.

AREF AREF Reference voltages are provided for input

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)

Fig.4: Pin layout for ESP8266-01

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.

ESP-01 module pins:

Pin Pin Other Pin Use


Number Name Name

1 Ground - Connection with the ground of the circuit

2 TX GPIO _1 Connected to Rx pin of uC to upload program,

Can act as a GPIO pin when not used as TX

3 GPIO_2 - GPIO Pin

4 CH_EN - Chip Enable/Chip Power down – Active high,


used to enable the esp8266 chip

5 GPIO Flash GPIO pin, connect this pin to GND when


_0 programming the module

11
6 Reset - Resets the module

7 RX GPIO_3 Connected to Tx pin of uC to upload the


program, Can act as a GPIO pin when not used
as Rx

8 Vcc - Connect to +3.3V only

How to Flash ESP8266 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

Fig.6: A window will appear, after launching the flashing tool.

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.

● Crystal Frequency – 26M


● SPI Speed – 40 MHz
● SPI Mode – QI0
● Flash Size – 8-bit
● Baud rate - 115200
● Select the COM Port

Now, for configuring the download path include the files with the given address
from the firmware folder in the given sequence.

File Name Address

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:

Fig.7: Flashing ESP8266 board

15
Step 5:

As the flashing complete, the dialog box will look like the image below:

Fig.8: Flashing is successful

So, the ESP8266 module flashed successfully.

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:

Fig.9: Arduino serial monitor output

Step 7: To check if the ESP8266 module is connected successfully or not.

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:

Fig.12: Flow of Data through the System

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.

Fig.13: Adding ThingSpeak Library in Arduino IDE

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.

Fig.15: Read & Write API keys of the 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.

Fig.16: Successful compilation of the code(code in Appendix.1)

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.

Fig.17: ThinkSpeak channel working in correspondence to the code.


Apart from this, we can also consolidate the data in our desired time intervals into
.csv files or use MATLAB visualizations.

Fig.18: File export options in channel name Street Light.

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.

Because this is a simulation project, the sensors would be offline, subsequently


rendering the channel output as null due to COVID constraints; nonetheless, the
channel is linked to the IDE through the programme code. We can get actual data
for the project by uploading the code onto an Arduino Uno board that is wired in
accordance with the circuit diagram mentioned in the Hardware Design section.

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;

int ldr = A0;


int val =0;
/*We set pinmode for pins of LED and IR sensor on the NodeMCU using the
library functions*/
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ir1,INPUT);
pinMode(led1,OUTPUT);

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);
}
}

ESP8266 Wifi module datasheet:

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

Inspiration for this idea

● IoT Based Street Light Automation System


1 Jeetendra Swami, 2 Himanshu Patel, 3 Krishna Patel and 4Ms.Nisha Bhalse
http://www.ijtrd.com/papers/IJTRD20377.pdf

● Automatic Street Lights, Sakshee Srivastava Electronics And


Communication Engineering, Institute Of Technology And Management
AL-1, Sector-7, GIDA, Gorakhpur, U.P., INDIA.
https://www.ripublication.com/aeee/71_pp%20%20%20539-542.pdf

42

You might also like