0% found this document useful (0 votes)
136 views

Street Light Glow On Detecting Vechile Movement Using Sensor.

This document describes a project to design a street lighting system that detects vehicle movement and switches lights on ahead of the vehicle. The system uses an IR sensor to detect vehicles and sends a signal to a microcontroller. The microcontroller then signals a relay to switch on LED street lights. As the vehicle passes, the lights will switch off or glow at a lower intensity to save energy. If a vehicle stops under a light, a GSM module will send a message to notify the system. The goal is to save energy by only illuminating streets where vehicles are present.

Uploaded by

Sajid Chohan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views

Street Light Glow On Detecting Vechile Movement Using Sensor.

This document describes a project to design a street lighting system that detects vehicle movement and switches lights on ahead of the vehicle. The system uses an IR sensor to detect vehicles and sends a signal to a microcontroller. The microcontroller then signals a relay to switch on LED street lights. As the vehicle passes, the lights will switch off or glow at a lower intensity to save energy. If a vehicle stops under a light, a GSM module will send a message to notify the system. The goal is to save energy by only illuminating streets where vehicles are present.

Uploaded by

Sajid Chohan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 59

Street Light that Glow on Detection Vehicle

Movement

Group Members

Sajid Ali Chohan Roll no.13EE24


Rao Hamza Roll no.13EE81
Sher Alma Malik Roll no.13EE38
Tayyaba Shehzadi Roll no.13EE02

Supervisor

Engr. Muhammad Yaseen Sheikh


Lecturer SCET-RYK
Department of Electrical Engineering (Power)

Department of Electronic Engineering


SWEDISH COLLEGE OF ENGINEERING AND TECHNOLOGY
2013 – 2017
Table of Contents

CERTIFICATE......................................................................................................................i
Abstract................................................................................................................................ii
Acknowledgements (optional)............................................................................................iii
List of Figures.....................................................................................................................vi
List of Tables.....................................................................................................................vii
Chapter 1 Introduction......................................................................................................1
1.1 Motivations...........................................................................................……….. 1
1.2 Objectives and Scope..........................................................................................1
1.3 Organisations.......................................................................................................1
Chapter 2 Literature Review.............................................................................................2
2.1 Introduction............................................................................................................2
2.2 List of Components used........................................................................................2
2.3 Microcontroller.......................................................................................................2
2.4 Physical Characteristics..........................................................................................2
2.5 IR Sensor Circuit Diagram and Working Principle................................................2

Chapter 3 Design and Operation......................................................................................3


3.1 Principle of Operation............................................................................................3
3.2 Circuit Design........................................................................................................3
3.3 Working..................................................................................................................3
Chapter 4 Conclusions and Future Work...........................................................................4
4.1 Conclusions....................................................................................................................4
4.2 Recommendation in Future Work..................................................................................4
References………………………………………………………………………………….
Appendix (optional)
………………………………………………………………………...
CERTIFICATE

Street Light that Glow on Detection Vehicle Movement

Group Members

Sajid Ali Chohan Roll no.13EE24


Rao Hamza Roll no.13EE81
Sher Alma Malik Roll no.13EE38
Tayyaba Shehzadi Roll no.13EE02

Supervisor

Engr. Muhammad Yaseen Sheikh


Lecturer SCET-RYK
Department of Electrical Engineering (Power)

HOD Signature

Supervisor Signature

Project In charge Signature

Swedish College of Engineering and Technology

i
UNDERTAKING

We certify that research work titled “ Street Light that Glow on Detection
Vehicle Movement” is our own work. The work has not been presented
elsewhere for assessment. Where material has been used from other
sources it has been properly acknowledged /referred.

ii
Abstract

The project is designed to detect vehicle movement on highways to switch ON only a


block of street lights ahead of vehicle, and to switch OFF the trailing lights to save
energy. During night all the lights on the highway remain ON for the vehicles, but lots of
energy is wasted when there is no vehicle movement. This proposed system provides a
solution for energy saving by switches ON a block of street lights ahead of the vehicle
and lights switch OFF automatically.
In this project we have used IR sensor which will sense the movement and then give
signal to the micro controller and then micro controller give signal to the relay and relay
will switch on the LEDs and as the vehicle passes the lights will switch off or glow at
10% intensity.
If the vehicle don’t pass and stop under light due to any reason the GSM will generate a
msg signal and send to the system or base.

iii
Acknowledgements

I am thankful to the creature of all Allah Subhan-Watala to have guided me


throughout this work at every step and for every new thought that was set up in
my mind to improve it. Indeed I could have done nothing without your precious
help and guidance. Who so ever helped me throughout course of my thesis,
whether my parents or any other individual was your will, so indeed none be
worthy of praise but you.

I am profusely thankful to my parents who raised my when I was not even


capable of walking and continued to support me throughout every step of my life.

I will also like to express special thanks to my supervisor Engr. Muhammad


Yaseen Shaikh for helping me throughout my project and thesis. I can safely say
that I haven’t learned any other subject in such depth than the ones which he has
taught.

I would also like to pay special thanks to HOD Electrical Dr. Fazli Qayum
Yousafzai for his tremendous support and cooperation. I appreciate his patience
and guidance throughout the whole thesis and project.
I would also like to thank Engr. Ahmad Bilal for being my thesis guidance and
evaluation committee.

DEDICATION

This is dedicated to our respected, supervisor, our inspiring teachers and HOD, those
who helped us and our prestigious institute

iv
v
List of Figures
Figure 2.1: Arduino mega2560..........................................................................................10
Figure 2.2: IR Sensor........................................................................................................13
Figure 2.3: IR Sensor 2.....................................................................................................16
Figure 2.4: IR Sensor circut .............................................................................................21
Figure 2.5: Gas Analyzer..................................................................................................25
Figure 2.6 Ir image device.................................................................................................26
Figure 2.7: Pin diagram of 16X2 line LCD.......................................................................36
Figure 2.8: SIM900 pin diagram.......................................................................................39
Figure 2.9: Voltage Regulator 7805..................................................................................43
Figure 2. 10: Relay “JQC-3FC (T73)”..............................................................................44
Figure 2.11: 4 - pin relay...................................................................................................53
Figure2.13 : JQC-3FC(T73)..............................................................................................54
Figure 2. 14:Back view of JQC-3FC(T73)........................................................................56
Figure 2.15:Relay driver ic circuit....................................................................................60
Figure 3.2.1: Circuit Design..............................................................................................61
Figure 3.2.2: Circuit Design with Relay............................................................................61
Figure 3.5: Virtual cellular network..................................................................................61
Figure 3.6: Two ways of constructing MCNs...................................................................63
Figure 3.7: Illustration of the UCAN architecture............................................................64
Figure 3.8: Illustration of the CMCN architecture............................................................66
Figure 3.9: Illustration of inter-microcell handoff in CMCN...........................................67
Figure 3.10: Cell and multihop cell in HMCN..................................................................69

vi
List of Tables
Table 2-1: Represents the Components of Street lights glow on detection of vehicle......30
Table 3-1: Comparison of selected MCN architectures....................................................74
Table 4-1: Call blocking with different (N0, N1) combinations at ρ=5 Erlangs...............103
Table 4-2: System capacity for uplink and downlink vs. channel combinations............107
Table 5-1: Interference Information Table for uplink......................................................113
Table 5-2: Interference Constraint Table for the simulated network...............................113
Table 5-3: Packing-based Channel Searching for uplink................................................116
Table 6-1: System parameters for TDD CDMA systems................................................139
Table 6-2: Supported number of simultaneous voice users.............................................146
Table A-1: Example of uplink call combinations for state (8,2,1,2,1,3,2)......................164
Table B-1: Example of downlink call combinations for state (24,2,1,2,1,3,2)...............168

vii
Chapter 1

Introduction

1.1 Motivations

Now a day the demand of electricity is increasing day by day and frequent
power cut is causing many problems in various areas like industries, hospitals
and houses. An alternative arrangement for power source is thus desirable.
Due to short fall of energy and power so we need to save energy as much we
can in all fields of utilization of power, our team has noticed that lot of energy
has been wasted in street light system. No of high voltage consuming bulbs
and lights are connected in street lights and working. These lights working
throughout the night even if there is no vehicle on the road so, when there is
no vehicle on the road lot of energy is wasted. Then we started to work on
such project in which we can save energy which is wasting in street lights.
After lot of research and hard work me and my team find solution and design
this project.

1. 1. 1 Energy Scenario in Pakistan:


Pakistan needs substantial amount of energy to develop its industry and to increase
the agriculture productivity. The available resources are limited. Like many
developing countries, the main issue of development is the limited energy sources.
The production of electricity is mainly based on thermal and hydro. A minor
contribution comes from a low power (137 MW) nuclear plant. The thermal power
station mostly uses the imported oil. The country seeks increased industrialization,

1
agriculture productivity & better quality of life of the people. This has increased the
demand for commercial energy considerably.
In order to improve the energy situation, some steps have been taken for efficient
utilization uninterrupted power supply. The solar and wind have received particular
attention [14-16]. Since 1981, eighteen PV systems for rural electrification and/or
water supplies have been installed. There are four desalination plants, including a
6000 gallon per day for Pakistan navy. Out of seven wind systems two generates
18kW and five are used for water pumping. Apart from solar and wind, biogas has
also made mentionable contribution. [17]

1.1.2 Electricity Crisis in Pakistan:


The power sector of Pakistan relies on conventional sources of generation. According
to Hydro Carbon Development Institute of Pakistan (HDIP) [18], 94, 63 GHz of
electricity was generated during 2013-14 the share of thermal power was 62.5%
followed by hydra (33.6%) and nuclear (3.9%). In thermal power, oil had the largest
share (35.1%) followed by natural gas (27.3%) and coil (0.1%). Solar and wind power
is planned to be integrated in the power system. The power sector of Pakistan mainly
depends on thermal power. Due to be rapid increase in population, the use of fossil
fuel has increased alarmingly.
Total commercial energy supply position for the year 1981-82 to 1986-87, the shaded
area marks the shortage. The present figure also demonstrates the oil, imported and
produced in the country. Total energy supplied during 1988-89 was 22.79 MTOE with
share from oil 40% oil production accounts for only 12% of total oil supplied the rest
being imported.

 The project is designed to detect vehicle movement on highways to switch ON

only a block of street lights ahead of vehicle, and to switch OFF the trailing

lights to save energy.

2
 During night all the lights on the highway remain ON for the vehicles, but lots

of energy is wasted when there is no vehicle movement.

1.2 Objectives and Scope

The main objective of this project is to save power or electricity. As here in Pakistan
load shedding is increasing day by day, and due to this interruption we cannot
complete our daily routine works. In universities, colleges, houses and hospitals
everywhere there is massive need of all the time presence of electricity. In universities
students need to complete their lectures or they need to do some practical works in
laboratories so there must be presence of electricity, because all the equipments works
on the electricity so if there is no electricity there will be no work in laboratories, or if
there is interruption in electricity there will be interruption in work or may be the
whole work done by student is lost.
In our hospitals we have huge machineries and medical equipments these all the
equipments works on electricity, and in hospitals patient are being admitted to recover
their health, and also operations are being done in hospitals and there we need all time
electricity we cannot afford a single minute of electricity because all the operation
accessories work on electricity so we need a 1complete electricity there, a single
minute of load shedding can damage a life there. The same case is for houses in our
houses we all have bought accessories that work on electricity, so we need
uninterrupted supply of electricity in our houses. Microwave oven, iron, washing
machines, stitching machines, computers etc all work on electricity so there a must
need of saving power.

3
Our main concern is to save electricity by this project. We use I.Cs and sensors in

street light systems to make it advance street lightning system. This system would we

more efficient and power saving.

Chapter 2

Hardware Architecture

2.1 Introduction
The main components of this project is AT mega2560, IR sensor (IR receiver and IR
Transmitter) and LED,s. During the development of hardware we had to face many
challenges e.g. design of a circuit and collection of components was one of the big
issue. We had to visit different markets inside and outside the city for this purpose.
Once all circuit components were collected then implementations of different circuits
becomes the next challenge. But all these hurdles were crossed by the passage of time
and with the help of our project supervisor. So under the scope of this chapter we will
see the different stages of hardware development. We will discuss the circuit
components with their role in the project and function.

4
2.2 List of Components used:
Following are the list of major components used for Street lights glow on detection of
vehicle, Table 2. 1 Represents the Components of Street lights glow on detection of
vehicle

Sr. No Component Model Quantity


Name

01 Microcontroller ATMEGA-2560 1

02 Relays JQC-3F(T73) 4

04 Transistor C945

05 LCD 16X2 01

06 Capacitor 100uf

07 Resistors 04

5
08 LED

12 Regulator 7805 01

13 Adopter 12volt 01

14 GSM Sim900

2.1 Microcontroller:

2.3.1: Introduction
A microcontroller is a self-contained system with peripherals, memory and a
processor that can be used as an embedded system. Most programmable
microcontrollers that are used today are embedded in other consumer products or
machinery including phones, peripherals, automobiles and household appliances for
computer systems. Due to that, another name for a microcontroller is "embedded
controller." Some embedded systems are more sophisticated, while others have
minimal requirements for memory and programming length and a low software
complexity. Input and output devices include solenoids, LCD displays, relays,
switches and sensors for data like humidity, temperature or light level, amongst
others.

2.3.2: Types of Micro Controller:


There are several different kinds of programmable microcontrollers at Future
Electronics. We stock many of the most common types categorized by several
parameters including Bits, Flash size, and RAM size, number of input/output lines,
packaging type, supply voltage and speed. Our parametric filters will allow you to

6
refine your search results according to the required specifications. Programmable
microcontrollers contain general purpose input/output pins. The number of these pins
varies depending on the microcontroller. They can be configured to an input or an
output state by software. When configured to an input state, these pins can be used to
read external signals or sensors. When they are configured to the output state, they
can drive external devices like LED displays and motors.

2.3.3 Applications for Microcontrollers:


Programmable microcontrollers are designed to be used for embedded applications,
unlike microprocessors that can be found in PCs. Microcontrollers are used in
automatically controlled devices including power tools, toys, implantable medical
devices, office machines, engine control systems, appliances, remote controls and
other types of embedded systems.
2.3.3.1: .Arduino Mega 2560:

The Arduino Mega 2560 is a microcontroller board based on the ATmega2560


(datasheet).

It has 54 digital input/output pins (of which 14 can be used as PWM outputs), 16
analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB
connection, a power jack, an ICSP header, and a reset button.

It contains everything needed to support the microcontroller; simply connect it to a


computer with a USB cable or power it with a AC-to-DC adapter or battery to get
started. The Mega is compatible with most shields designed for the Arduino
Duemilanove.

 Microcontroller ATmega2560 Operating Voltage 5V

 Input Voltage (recommended) 7-12V

 Input Voltage (limits) 6-20V

 Digital I/O Pins 54 (of which 14 provide PWM output)

7
 Analog Input Pins 16 DC

 Current per I/O Pin 40 mA DC

 Current for 3.3V Pin 50 mA

 Flash Memory 256 KB of which 8 KB used by boot loader

 SRAM 8 KB

 EEPROM 4 KB

 Clock Speed 16 MHz

Fig: Arduino mega2560

2.3.3.2: Power

The Arduino Mega can be powered via the USB connection or with an external power
supply. The power source is selected automatically.

External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or
battery. The adapter can be connected by plugging a 2.1mm centre-positive plug into

8
the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin
headers of the POWER connector.

The board can operate on an external supply of 6 to 15 volts. If supplied with less than
7V, however, the 5V pin may supply less than five volts and the board may be
unstable. If using more than 12V, the voltage regulator may overheat and damage the
board. The recommended range is 7 to 12 volts.

The power pins are as follows:

 VIN. The input voltage to the Arduino board when it's using an external power
source (as opposed to 5 volts from the USB connection or other regulated
power source). You can supply voltage through this pin, or, if supplying
voltage via the power jack, access it through this pin.
 5V. this pin outputs a regulated 5V from the regulator on the board. The board
can be supplied with power either from the DC power jack (7 - 12V), the USB
connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via
the 5V or 3.3V pins bypasses the regulator, and can damage your board. We
don't advise it.
 3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current
draw is 50 mA.
 GND. Ground pins.
 IOREF. This pin on the Arduino board provides the voltage reference with
which the microcontroller operates. A properly configured shield can read the
IOREF pin voltage and select the appropriate power source or enable voltage
translators on the outputs for working with the 5V or 3.3V.

2.3.3.3: Memory

The ATmega2560 has 256 KB of flash memory for storing code (of which 8 KB is
used for the boot loader), 8 KB of SRAM and 4 KB of EEPROM (which can be read

9
and written with the EEPROM library).

2.3.3.4: Input and Output

Each of the 54 digital pins on the Mega can be used as an input or output, using pin
Mode (), digital Write (), and digital Read () functions. They operate at 5 volts. Each
pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor
(disconnected by default) of 20-50 kohms. In addition, some pins have specialized
functions:

 Serial 0: (RX) and 1 (TX);


 Serial 1: 19 (RX) and 18 (TX);
 Serial 2: 17 (RX) and 16 (TX);
 Serial 3: 15 (RX) and 14 (TX). Used to receive (RX) and transmit (TX) TTL
serial data. Pins 0 and 1 are also connected to the corresponding pins of the
ATmega16U2 USB-to-TTL Serial chip.
 External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19
(interrupt 4), 20 (interrupt 3), and 21 (interrupt 2). These pins can be
configured to trigger an interrupt on a low value, a rising or falling edge, or a
change in value. See the attach Interrupt () function for details.
 PWM: 2 to 13 and 44 to 46. Provide 8-bit PWM output with the analogWrite
() function.
 SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI
communication using the SPI library. The SPI pins are also broken out on the
ICSP header, which is physically compatible with the Uno, Duemilanove and
Diecimila.
 LED: 13. There is a built-in LED connected to digital pin 13. When the pin is
HIGH value, the LED is on, when the pin is LOW, it's off.
 TWI: 20 (SDA) and 21 (SCL). Support TWI communication using the Wire
library. Note that these pins are not in the same location as the TWI pins on the
Duemilanove or Diecimila.

10
The Mega2560 has 16 analog inputs, each of which provides 10 bits of resolution (i.e.
1024 different values). By default they measure from ground to 5 volts, though is it
possible to change the upper end of their range using the AREF pin and
analogReference () function.

There are a couple of other pins on the board:

 AREF. Reference voltage for the analog inputs. Used with analogReference().
 Reset. Bring this line LOW to reset the microcontroller. Typically used to add
a reset button to shields which block the one on the board.

2.3.3.5: Communication

The Arduino Mega2560 has a number of facilities for communicating with a


computer, another Arduino, or other microcontrollers. The ATmega2560 provides four
hardware UARTs for TTL (5V) serial communication. An ATmega16U2 (ATmega
8U2 on the revision 1 and revision 2 boards) on the board channels one of these over
USB and provides a virtual com port to software on the computer (Windows machines
will need a .inf file, but OSX and Linux machines will recognize the board as a COM
port automatically. The Arduino software includes a serial monitor which allows
simple textual data to be sent to and from the board. The RX and TX LEDs on the
board will flash when data is being transmitted via the ATmega8U2/ATmega16U2
chip and USB connection to the computer (but not for serial communication on pins 0
and 1).

A Software Serial library allows for serial communication on any of the Mega2560's
digital pins.

The ATmega2560 also supports TWI and SPI communication. The Arduino software
includes a Wire library to simplify use of the TWI bus; For SPI communication, use
the SPI library.

11
2.3.3.6: Programming

The Arduino Mega can be programmed with the Arduino software (download).
The ATmega2560 on the Arduino Mega comes preburned with a boot loader that
allows you to upload new code to it without the use of an external hardware
programmer. It communicates using the original STK500 protocol.

You can also bypass the boot loader and program the microcontroller through the
ICSP (In-Circuit Serial Programming) header using Arduino ISP or similar;
The ATmega16U2 (or 8U2 in the rev1 and rev2 boards) firmware source code is
available in the Arduino repository. The ATmega16U2/8U2 is loaded with a DFU
boot loader, which can be activated by:

 On Rev1 boards: connecting the solder jumper on the back of the board (near
the map of Italy) and then resetting the 8U2.

 On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB
line to ground, making it easier to put into DFU mode. You can then
use Atmel's FLIP software (Windows) or the DFU programmer (Mac OS X
and Linux) to load a new firmware. Or you can use the ISP header with an
external programmer (overwriting the DFU boot loader).

2.3.3.7: Automatic (Software) Reset

Rather than requiring a physical press of the reset button before an upload, the
Arduino Mega2560 is designed in a way that allows it to be reset by software running
on a connected computer. One of the hardware flow control lines (DTR) of the
ATmega8U2 is connected to the reset line of the ATmega2560 via a 100 Nano farad
capacitor. When this line is asserted (taken low), the reset line drops long enough to
reset the chip. The Arduino software uses this capability to allow you to upload code
by simply pressing the upload button in the Arduino environment. This means that the

12
boot loader can have a shorter timeout, as the lowering of DTR can be well-
coordinated with the start of the upload.
This setup has other implications. When the Mega2560 is connected to either a
computer running Mac OS X or Linux, it resets each time a connection is made to it
from software (via USB). For the following half-second or so, the boot loader is
running on the Mega2560. While it is programmed to ignore malformed data (i.e.
anything besides an upload of new code), it will intercept the first few bytes of data
sent to the board after a connection is opened. If a sketch running on the board
receives one-time configuration or other data when it first starts, make sure that the
software with which it communicates waits a second after opening the connection and
before sending this data.
The Mega2560 contains a trace that can be cut to disable the auto-reset. The pads on
either side of the trace can be soldered together to re-enable it. It's labelled "RESET-
EN". You may also be able to disable the auto-reset by connecting a 110 ohm resistor
from 5V to the reset line.

2.3.3.8: USB Over current Protection

The Arduino Mega2560 has a resettable poly fuse that protects your computer's USB
ports from shorts and over current. Although most computers provide their own
internal protection, the fuse provides an extra layer of protection. If more than 500
mA is applied to the USB port, the fuse will automatically break the connection until
the short or overload is removed.

2.4: Physical Characteristics


The maximum length and width of the Mega2560 PCB are 4 and 2.1 inches
respectively, with the USB connector and power jack extending beyond the former
dimension. Three screw holes allow the board to be attached to a surface or case. Note
that the distance between digital pins 7 and 8 is 160 mil (0.16") not an even multiple
of the 100 mil spacing of the other pins.
The Mega2560 is designed to be compatible with most shields designed for the Uno,

13
Diecimila or Duemilanove. Digital pins 0 to 13 (and the adjacent AREF and GND
pins), analog inputs 0 to 5, the power header, and ICSP header are all in equivalent
locations. Further the main UART (serial port) is located on the same pins (0 and 1),
as are external interrupts 0 and 1 (pins 2 and 3 respectively). SPI is available through
the ICSP header on the Mega2560 and Duemilanove / Diecimila. Please note that I2C
is not located on the same pins on the Mega (20 and 2) as the Duemilanove /
Diecimila (analog inputs 4 and 5).

Fig: 1.2 IR Sensors:

An infrared sensor is an electronic device that emits in order to sense some


aspects of the surroundings. An IR sensor can measure the heat of an object as
well as detects the motion. These type of sensors measures only infrared
radiation, rather than emitting it that is called as a passive IR sensor. Usually
in the infrared spectrum, all the objects radiate some form of thermal
radiations. These types of radiations are invisible to our eyes that can be

14
detected by an infrared sensor. The emitter is simply an IR LED (Light
Emitting Diode) and the detector is simply an IR photodiode which is
sensitive to IR light of the same wavelength as that emitted by the IR LED.
When IR light falls on the photodiode, the resistances and these output
voltages, change in proportion to the magnitude of the IR light received.

IR Sensor

2.5: IR Sensor Circuit Diagram and Working Principle


An infrared sensor circuit is one of the basic and popular sensor module in an
electronic device. This sensor is analogous to human’s visionary senses, which can be
used to detect obstacles and it is one of the common applications in real time. This
circuit comprises of the following components
• LM358 IC 2 IR transmitter and receiver pair
• Resistors of the range of kilo ohms.
• Variable resistors.
• LED (Light Emitting Diode).

15
IR Sensor Circuit
In this project, the transmitter section includes an IR sensor, which transmits
continuous IR rays to be received by an IR receiver module. An IR output terminal of
the receiver varies depending upon its receiving of IR rays. Since this variation cannot
be analyzed as such, therefore this output can be fed to a comparator circuit. Here an
operational amplifier (op-amp) of LM 339 is used as comparator circuit.
When the IR receiver does not receive a signal, the potential at the inverting input
goes higher than that non-inverting input of the comparator IC (LM339). Thus the
output of the comparator goes low, but the LED does not glow. When the IR receiver
module receives signal to the potential at the inverting input goes low. Thus the output
of the comparator (LM 339) goes high and the LED starts glowing. Resistor R1
(100 ), R2 (10k ) and R3 (330) are used to ensure that minimum 10 mA current passes
through the IR LED Devices like Photodiode and normal LEDs respectively. Resistor
VR2 (preset=5k ) is used to adjust the output terminals. Resistor VR1 (preset=10k ) is
used to set the sensitivity of the circuit Diagram. Read more about IR sensors.
2.5.1:Different Types of IR Sensors and Their Applications

IR sensors are classified into different types depending on the applications. Some of the typical
applications of different types of sensors are

The speed sensor is used for synchronizing the speed of multiple motors. The temperature sensor is
used for industrial temperature control. PIR sensor is used for automatic door opening system and
Ultrasonic sensor are used for distance measurement.

2.5.2: IR Sensor Applications

IR sensors are used in various Sensor based projects and also in various electronic devices which
measures the temperature that are discussed in the below.

2.5.2: .Radiation Thermometers

16
IR sensors are used in radiation thermometers to measure the temperature depend
upon the temperature and the material of the object and these thermometers have
some of the following features

• Measurement without direct contact with the object

• Faster response

• Easy pattern measurements

Flame Monitors

These types of devices are used for detecting the light emitted from the flames and to
monitor how the flames are burning. The Light emitted from flames extend from UV
to IR region types. PbS, PbSe, Two-color detector, pyro electric detector are some of
the commonly employed detector used in flame monitors.

1.1.1.1 Moisture Analyzers

Moisture analyzers use wavelengths which are absorbed by the moisture in the IR
region. Objects are irradiated with light having these wavelengths(1.1 µm, 1.4 µm, 1.9
µm, and 2.7µm) and also with reference wavelengths. The Lights reflected from the
objects depend upon the moisture content and is detected by analyzer to measure
moisture (ratio of reflected light at these wavelengths to the reflected light at
reference wavelength). In GaAs PIN photodiodes, Pbs photoconductive detectors are
employed in moisture analyzer circuits.

1.1.1.1 Gas Analyzers

IR sensors are used in gas analyzers which use absorption characteristics of gases in
the IR region. Two types of methods are used to measure the density of gas such as
dispersive and non dispersive.

17
Fig: 2.4 Gas Analyzer

Dispersive: An Emitted light is spectroscopically divided and their absorption


characteristics are used to analyze the gas ingredients and the sample quantity.
Non dispersive: It is most commonly used method and it uses absorption characteristics without
dividing the emitted light. Non dispersive types use discrete optical band pass filters, similar to
sunglasses that are used for eye protection to filter out unwanted UV radiation.

This type of configuration is commonly referred to as non dispersive infrared (NDIR) technology. This
type of analyzer is used for carbonated drinks, whereas non dispersive analyzer is used in most of the
commercial IR instruments, for an automobile exhaust gas fuel leakages.

1.1.1.1 IR Imaging Devices


IR image device is one of the major applications of IR waves, primarily by virtue of its property
that is not visible. It is used for thermal imagers, night vision devices, etc.

Fig: 2.5 IR Imaging Devices

For examples Water, rocks, soil, vegetation, an atmosphere, and human tissue all
features emit IR radiation. The Thermal infrared detectors measure these radiations in
IR range and map the spatial temperature distributions of the object/area on an image.
Thermal imagers usually composed of a Sb (indium antimonite), Gd Hg (mercury-
doped germanium), Hg Cd Te (mercury-cadmium-telluride) sensors.

An electronic detector is cooled to low temperatures using liquid helium or liquid


nitrogen’s. Then the Cooling the detectors ensures that the radiant energy (photons)
recorded by the detectors comes from the terrain and not from the ambient
temperature of objects within the scanner itself an IR imaging electronic devices.

18
Thus, this is all about IR sensor circuit with working and applications. These sensors
are used in many sensor based electronics projects.

LCD:
A liquid crystal display (LCD) is a thin, flat display device made up of any number of
color or monochrome pixels arrayed in front of a light source or reflector. Each pixel
consists of a column of liquid crystal molecules suspended between two transparent
electrodes, and two polarizing filters, the axes of polarity of which are perpendicular
to each other. Without the liquid crystals between them, light passing through one
would be blocked by the other. The liquid crystal twists the polarization of light
entering one filter to allow it to pass through the other.
Many microcontroller devices use 'smart LCD' displays to output visual information.
LCD displays designed around Hitachi's LCD HD44780 module, are inexpensive,
easy to use, and it is even possible to produce a readout using the 8x80 pixels of the
display. They have a standard ASCII set of characters and mathematical symbols. For
an 8-bit data bus, the display requires a +5V supply plus 11 I/O lines. For a 4-bit data
bus it only requires the supply lines plus seven extra lines. When the LCD display is
not enabled, data lines are tri-state and they do not interfere with the operation of the
microcontroller. Data can be placed at any location on the LCD. For 16×2 LCD, the
address locations are:
First line 80 81 82 83 84 85 86 through 8F
Second line C0 C1 C2 C3 C4 C5 C6 through CF

Pins detail of the LCD:


The LCD also requires 3 control lines from the microcontroller:

1) Enable (E)
This line allows access to the display through R/W and RS lines. When this line is

19
low, the LCD is disabled and ignores signals from R/W and RS. When (E) line is
high, the LCD checks the state of the two control lines and responds accordingly.

2) Read/Write (R/W)
This line determines the direction of data between the LCD and microcontroller.
When it is low, data is written to the LCD. When it is high, data is read from the LCD.

3) Register selects (RS)


With the help of this line, the LCD interprets the type of data on data lines. When it is
low, an instruction is being written to the LCD. When it is high, a character is being
written to the LCD.

Logic status on control lines:


 E - 0 Access to LCD disabled
- 1 Access to LCD enabled
 R/W - 0 Writing data to LCD
- 1 Reading data from LCD
 RS - 0 Instructions
- 1 Character

Writing and reading the data from the LCD:


1. Writing data to the LCD is done in several steps:
1) Set R/W bit to low
2) Set RS bit to logic 0 or 1 (instruction or character)
3) Set data to data lines (if it is writing)
4) Set E line to high
5) Set E line to low
2. Read data from data lines (if it is reading):
1) Set R/W bit to high
2) Set RS bit to logic 0 or 1 (instruction or character)
3) Set data to data lines (if it is writing)
4) Set E line to high

20
5) Set E line to low

Pin Description:
Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins
(Two pins are extra in both for back-light LED connections).

Fig: 2.6 Pin diagram of 16X2 line LCD

Opto-coupler (PC817):
PC817 is a standard optocoupler; we use this IC to isolate two parts of a circuit.
Isolation prevents ground loops and transmission of unwanted noise.
Input LED has a forward voltage of 1.2 V and a forward current of 50mA. A current
limiting resistor must be used to prevent input LED to be blow out.
Frequency depends on the pull up resistor we use on the output transistor.

Features of PC817:
1. Current transfer ratio

(Min. 50% at If=5mA, Vce=5V)


2. High isolation voltage between input and output (Viso:500V rms)
3. Compact dual-in-line package, 1-Channel type.
4. Recognized by UL, file no. E64380.

21
Applications:
1. Computer terminals.
2. System appliances, measuring instruments.
3. Registers, copiers, automatic vending machines.
4. Electric home appliances such as fan, heaters etc.
5. Signal transmission between circuits of different potentials and impedances.

GPS (sim 900):

Description:

GPRS module is a breakout board and minimum system of SIM900 Quad-


band/SIM900A Dual-band GSM/GPRS module. It can communicate with controllers
via AT commands (GSM 07.07, 07.05 and SIMCOM enhanced AT Commands). This
module supports software power on and reset.

SIMCom presents an ultra compact and reliable wireless module. The SIM900A is a
complete Dual-band GSM/GPRS module in a SMT type which is designed especially
for Chinese market, allowing you to benefit from small dimensions and cost-effective
solutions.

Featuring an industry-standard interface, the SIM900A delivers GSM/GPRS


900/1800MHz performance for voice, SMS, Data, and Fax in a small form factor and
with low power consumption. With a tiny configuration of 24mm x 24mm x 3 mm,
SIM900A can fit almost all the space requirements in your applications, especially for
slim and compact demand of design.

22
Fig: 2.8 SIM900 pin diagram

Features:

 Quad-Band 850/ 900/ 1800/ 1900 MHz

 Dual-Band 900/ 1900 MHz

 GPRS multi-slot class 10/8GPRS mobile station class B

 Compliant to GSM phase 2/2+Class 4 (2 W @850/ 900 MHz)

 Class 1 (1 W @ 1800/1900MHz)

 Control via AT commands (GSM 07.07 ,07.05 and SIMCOM enhanced AT

23
Commands)

 Low power consumption: 1.5mA(sleep mode)

 Operation temperature: -40°C to +85 °C

Regulator (7805):

7805 is a voltage regulator integrated circuit.

It is a member of 78xx series of fixed linear voltage regulator ICs.

The voltage source in a circuit may have fluctuations and would not give the fixed
voltage output.

The voltage regulator IC maintains the output voltage at a constant value.

The xx in 78xx indicates the fixed output voltage it is designed to provide.

Fig: 2.9 Voltage Regulators 7805

7805 provides +5V regulated power supply.

Capacitors of suitable values can be connected at input and output pins depending
upon the respective voltage levels.

Name

24
1 Input voltage (5V-18V) Input

2 Ground (0V) Ground

3 Regulated output; 5V (4.8V- Output


5.2V)

Relay (SPDT):

The Single Pole Double Throw SPDT relay is quite useful in certain applications
because of its internal configuration.

It has one common terminal and 2 contacts in 2 different configurations:

 one can be Normally Closed and the other one is opened or it can be
Normally Open and the other one closed.

So basically you can see the SPDT relay as a way of switching between 2 circuits:

 when there is no voltage applied to the coil one circuit “receives” current, the
other one doesn’t and when the coil gets energized the opposite is happening.
In this project we are using the relay JQC-3FC (T73). This relay has
following properties.

Fig: 2. 10 Relay “JQC-3FC (T73)”

25
Relay Operations:
All relays operate using the same basic principle. Our example will use a commonly
used 4 - pin relay. Relays have two circuits: A control circuit (shown in GREEN) and
a load circuit (shown in RED). The control circuit has a small control coil while the
load circuit has a switch. The coil controls the operation of the switch.

When no voltage is applied to pin 1, there is no current flow through the coil. No
current means no magnetic field is developed, and the switch is open. When voltage is
supplied to pin 1, current flow though the coil creates the magnetic field needed to
close the switch allowing continuity between pins 2 and 4.

Fig: 2.11 4 - pin relay

Relay Energized (ON):


Current flowing through the control circuit coil (pins 1 and 3) creates a small
magnetic field which causes the switch to close, pins 2 and 4. The switch, which is
part of the load circuit, is used to control an electrical circuit that may connect to it.
Current now flows through pins 2 and 4 shown in RED, when the relay in energized.

26
Relay De Energized (OFF):
When current stops flowing through the control circuit, pins 1 and 3, the relay
becomes de- energized. Without the magnetic field, the switch opens and current is
prevented from flowing through pins 2 and 4. The relay is now OFF.

Relay Applications:
Relays are remote control electrical switches that are controlled by another switch,
such as a horn switch or a computer as in a power train control module. Relays allow
a small current flow circuit to control a higher current circuit. Several designs of
relays are in use today, 3- pin, 4-pin, 5-pin, and 6-pin, single switch or dual switches.

Fig: 2.13 JQC-3FC(T73)

27
Properties of JQC-3FC(T73):
 MAX. SWITCHING CURRENT:7A, 10A
 MAX. SWITCHING VOLTAGE:28V DC/ 250V AC
 DIELECTRIC STRENGTH VR.M.S: BETWEEN OPEN CONTACTS
=750VAC; BETWEEN COIL AND CONTACTS =1000VAC; BETWEEN
CONTACTS FORM =1000VAC
 AMBIENT TEMPERATURE: -40°C to +85°C
 OPERATION/RELEASE TIME:=10/8MS
 CONTACT CAPACITY: 10A 125V, 7A 250V

Back view of JQC-3FC (T73):

Fig: 2.14 Back view of JQC-3FC(T73)

Relay Driver IC:


Relays are used mostly interfaced with microcontrollers and digital systems. But
microcontroller usually cannot provide enough current to drive relays.
Microcontrollers pins usually provide maximum current of 1-2 mA per pin which is
not enough o operate relay. The circuits which are used to derive relays are called
relay driver circuits. Therefore relay driver circuits using ULN2003 is used to drive

28
relays.
While working on electronics projects which used microcontroller, we need to use
relays to control AC loads or high voltage loads. Relays are used to provide isolation
between microcontroller’s circuits and high voltage operating loads. Microcontrollers
are only used to provide on/off signals to relays. Microcontrollers don’t have enough
current sourcing ability to derive relays. Therefore relay driver circuits IC is used to
derive relays properly. There are many ways to design relay driver circuits. But
dedicated relay driver circuits integrated circuits are available which serve the
purpose of relay driver IC. Relay driver circuit IC ULN2003 is one of popular relay
driver circuits.

Fig: 2.15Relay driver IC circuit

29
30
Chapter 3

Design and Operation

3.1 Principle of Operation

The principle behind the working of the project lies in the functioning of IR Sensor. We
are going to use a Transmissive type IR Sensor in this project.

In Transmissive IR Sensor, the IR transmitter and receiver are placed facing each other so
that IR receiver always detects IR Rays emitted by the IR Transmitter.

If there is an obstacle between the IR Transmitter and Receiver, the IR Rays are blocked
by the obstacle and the IR Receiver stops detecting the IR Rays.

This can be configured to turn ON or OFF the LEDs (or street lights) with the help of
microcontroller.

3.2 Circuit Design

31
FIGURE 3.2.1

FIGURE 3.2.2

The main components of the project are AT89C52 Microcontroller, IR Sensor (IR
Transmitter and IR Receiver) and LEDs.

The basic connections required for 8051 Microcontroller involve crystal, reset and
External Access.

In order to use the on-chip oscillator, the 8051 microcontroller requires an external clock.
This is provided by a crystal oscillator. An 11.0592MHz quartz crystal is connected to
XTAL1 and XTAL2 pins with two 22pF ceramic capacitors connected to it.

The reset circuit of the microcontroller consists of a 10K resistor, 10uF capacitor and a
push button. All the connections of the reset circuit are shown in the circuit diagram.

External access Pin is used to access external memory when it is connected to ground.
Anyway, we are not going to use any external memory here. So, connect this pin to Vcc
via a 10K resistor.

32
The next hard ware we are going to connect is the IR Receiver. We are going to connect
the 8 IR receivers to port 0 pins of the microcontroller. In order to use the PORT0 as I/O
port, we need to connect external pullup resistors to the port 0 pins.

After that, connect the output of the IR receiver i.e. anode terminal of the photo diode to
port 0 pins. Cathode terminals of the photo diodes are connected to supply. Also, a 3.3k
Resistor is connected between the anode terminal and ground.

The next part of the circuit is IR transmitter. IR transmitter is not a part of the
microcontroller connections as the only job of the IR transmitter is to continuously emit
infrared rays.

Hence, connect the 8 IR transmitters with corresponding 8 current limiting resistors of


470 ohms with a power supply.

Finally, we need to connect the LEDs. We need to connect the LED’s with the help of
transistors to the PORT2 of the microcontroller. The base of the 8 2N2222 transistors is
connected to the PORT 2 of the microcontroller while the emitters of the transistors are
connected to ground.

An LED along with a series current limiting resistor of 100 ohms is connected to the each
of the collector terminal of the transistor.

3.3 Working

The aim of this project is to design a street light control system using 8051
microcontroller, which automatically turns on or off the street lights by detecting the
movement of vehicles.

The IR transmitter is placed directly in line of sight with IR receiver, so that the IR
receiver continuously receives infrared rays. Once the IR receiver receives infrared rays,
the microcontroller will detect Logic 1. If the infrared rays are blocked by some means,
the microcontroller will detect logic 0.

So, the program for the microcontroller must be written in such a way that it will turn ON
the LEDs, which means here the street lamp, when it detects Logic 0 and it will turn OFF
the LEDs, when it detects Logic 1.

33
Consider the two IR sensors i.e. IR Transmitter and IR Receiver are placed on the either
side of the road. As per the circuit diagram, the IR receivers are connected to the PORT0
and the LEDs are connected to the PORT2 of the microcontroller.

At the beginning, when there is no obstacle, the IR receiver continuously detects IR light
transmitted by the IR Transmitter. When a car or any other vehicle blocks any of the IR
sensor, the microcontroller will turn ON the immediate three LEDs.

If the car blocks the first IR sensor, the first three LEDs are turned ON by the
microcontroller. As the car moves forward and blocks the second IR sensor, the
corresponding next three LEDs will be turned ON and the first LED of the previous set is
turned OFF. The process continues this way for all the IR Sensors and LEDs.

Chapter 4

Conclusions and Future Work

4.1 Conclusions

This project smart power consumption system is a cost effective, eco-friendly and the
safest way to utilization of solar energy.
It clearly tackles the two problems that world is facing today, saving of energy & global
warming, very efficiently.
According to statistical data we can save more that 70 % of electrical energy that is now
consumed by the street light.
Initial cost and maintenance can be the draw backs of this project.
With the advances in renewable technology and good resource planning the cost of the
project can be cut down and also with the use of good equipment the maintenance can
also be reduced in terms of periodic checks.
The LEDs have long life, emit cool light, donor have any toxic material and can be used
for fast switching.
For these reasons our project presents far more advantages which can over shadow the

34
present limitations.
Keeping in view the long term benefits and the initial cost would never be a problem as
the investment return time is very less.
The project has scope in various other applications like for providing lighting in
industries, campuses, office and parking lots of huge shopping malls.
This can also be used for surveillance in corporate campuses and industries
Street-lights are a large consumer of energy for cities using up to 50 percent of a city's
energy budget.
If every city installs the proposed system then a lot of power can be saved.
Proposed system is power saving mechanism for street lights by using LED lamps as
replacement of normal lamps and using special power savings mechanism for
microcontroller rand ZigBee modules.
It turns out most reliable and time efficient way to switch ON/OFF streetlights.
It provides an effective measure to save energy by preventing unnecessary wastage of
electricity, caused due to manual switching or lighting of street-lights when it is not
required.
It adopts a dynamic control methodology for traffic flow.
The proposed system is especially appropriate for street lighting in remote urban and
rural areas where the traffic is low at times.
The system is versatile, extendable and totally adjustable to user needs.

4.2 Recommendation in Future Work

 Add to the Smart Grid to monitoring all the lights and energy backup purposes
 With adding other renewable energy sources
 Railway signaling aspects
 We can LDR circuits for automatically operation in night.
 We can use solar panels for supply.

35

36
Chapter 4 References

[1]Suganya, S., Sinduja, R., Sowmiya, T., & Senthilkumar, S. STREET LIGHT GLOW
ON DETECTING VECHILE MOVEMENT USING SENSOR.

[2] Schwab, R.N., Walton, N.E., Mounce, J.M., and Rosenbaum, M.J. (1982) Synthesis of
Safety Research Related to Traffic Control and Roadway Elements-Volume 2,
Chapter 12: Highway Lighting. Report No. FHWA-TS-82233. Federal Highway
Administration.

[3] Elvik, R. (1995) “Meta-Analysis of Evaluations of Public Lighting as Accident


Countermeasure.” Transportation Research Record 1485, TRB, National Research
Council, Washington, D.C., pp. 112-123.

[4] Electrical Safety of Street Light Systems,Giuseppe Parise, Fellow, IEEE, Luigi
Martirano, Senior Member, IEEE, and Massimo Mitolo, Senior Member, IEEE,
VOL. 26, NO. 3, JULY 2011.

[5] Energy Efficient Lighting Control System Design For Corridor illumination, Jayashri
A.Bangali, Arvind D.Shaligram International Journal of Scientific & Engineering
Research Volume 3, Issue 4, April-2012 ,ISSN 2229-5518.

[6] Wireless Streetlight Control System, Deepak Kapgate, G.H. Raisoni College of
engineering, Nagpur University, International Journal of Computer Applications
(0975 –8887),Volume 41– No.2, March 2012

[7] Design and fabrication of automatic street light control system, M. A. Wazed, N.
Nafis, M. T. Islam and, Vol. 5, No. 1,June 2010, pp 27-34

[8] "The Saracens themselves were the originators not only of algebra, chemistry, and
geology, but of many of the so-called improvements or refinements of
civilization, such as street lamps, window-panes, firework, stringed instruments,
cultivated fruits, perfumes, spices, etc."

[9] Scott, S. P. (1904). History of the Moorish Empire in Europe. Philadelphia and
London.: J. B. Lippincott Company. p. 3 vols. Artz, F. B. (1980). The Mind of the
Middle Ages. Third edition revised. University of Chicago Press. pp. 148–50.

37
[10] "Sir Joseph Wilson Swan". home.frognet.net. Retrieved 16 October 2010.

38
Appendix
Code of Entire Project
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,10,11,12,13);

///-FAWAD BUTT MicroEmbeddedLab


///-03204077096 (MicroElab.com)
////////////////////////////////////////////////////////////////////////
char N[]="+923204077096"; //my number
////////////////////////////////////////////////
char sendMsg[10]; //
char rxChar; //
char ResponceData[10]; //
////////////////////////////////////////////////
char msgDetail[30]; //
char msgText[30]; //
char gsmBuff[25]; //
char rxNumber[15]; //
char rxCommand[15]; //
//String ignitionString = "";// a string to hold incoming data //
unsigned char msgComplete=0; // whether the string is complete //
//char rongNumber; //
unsigned char lineFlag; //
unsigned char aa,bb,cc; //
//////////////////////////////////////////////////////////////
const int smsLed=5;
//////////////////////////////
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 3000;
////////////////////////////////////////////
char rssiValue[10];
boolean rssiFlag;
//////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
boolean RssiSend=LOW;
boolean MsgSendFlag=LOW;
bool newData = false;

39
boolean msgComeFlag;
int moduleReady;
/////////////////////////
void gsmInit();
void gsmSend(char n[],char m0[],String m1,char m2[],String m3,char m4[]);
void msgReceive(); //
void arrayShift(); //
///////////////////////////////////
void SendSms();
void gsmStable();

int out1=22;
int out2=23;
int out3=24;
int out4=25;
int out5=26;

int in1=31;
int in2=28;
int in3=29;
int in4=30;
int in5=32;

int read1;
int read2;
int read3;
int read4;
int read5;

boolean in1Flag;
boolean in2Flag;
boolean in3Flag;
boolean in4Flag;
boolean in5Flag;

int countTime1;
int countTime2;
int countTime3;

40
int countTime4;
int countTime5;

boolean timeOut1;
boolean timeOut2;
boolean timeOut3;
boolean timeOut4;
boolean timeOut5;

boolean in1Send;
boolean in2Send;
boolean in3Send;
boolean in4Send;
boolean in5Send;

void setup()
{
Serial.begin(9600);
Serial1.begin(9600);

lcd.begin(16,2);

lcd.setCursor(0,0);
lcd.print("Project Start");

pinMode(smsLed,OUTPUT);

pinMode(in1,INPUT);
pinMode(in2,INPUT);
pinMode(in3,INPUT);
pinMode(in4,INPUT);
pinMode(in5,INPUT);

pinMode(out1,OUTPUT);
pinMode(out2,OUTPUT);
pinMode(out3,OUTPUT);
pinMode(out4,OUTPUT);
pinMode(out5,OUTPUT);

41
digitalWrite(out1,HIGH);
digitalWrite(out2,HIGH);
digitalWrite(out3,HIGH);
digitalWrite(out4,HIGH);
digitalWrite(out5,HIGH);

///////////////////////////////////////////////////// /////////////////////
gsmStable();
///////////////////////////////////////////////////
//Serial.println("Initilizing Complete:");
///////////////////////////////////////////////////
Serial.print("RSSI: ");Serial.println(rssiValue);
gsmSend(N,"Street Light Detection \n","RSSI ",rssiValue,"","");
lineFlag==LOW;
///////////////////////////////////////////////////
}
void loop()
{
//////////////////////////-GPS Receiving-/////////////////////////////////////
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
//////////////////////////////////////////

if(in1Flag==HIGH){countTime1++;}
if(in2Flag==HIGH){countTime2++;}
if(in3Flag==HIGH){countTime3++;}
if(in4Flag==HIGH){countTime4++;}
if(in5Flag==HIGH){countTime5++;}

lcd.setCursor(1,0);
if(countTime1>10)

42
{
countTime1=0;in1Send=HIGH;MsgSendFlag=HIGH;
lcd.print("Ligit 1 Hold");
}
if(countTime2>10)
{
countTime2=0;in2Send=HIGH;MsgSendFlag=HIGH;
lcd.print("Ligit 2 Hold");
}
if(countTime3>10)
{
countTime3=0;in3Send=HIGH;MsgSendFlag=HIGH;
lcd.print("Ligit 3 Hold");
}

if(countTime4>10)
{
countTime4=0;in4Send=HIGH;MsgSendFlag=HIGH;
lcd.print("Ligit 4 Hold");
}
if(countTime5>10)
{
countTime5=0;in5Send=HIGH;MsgSendFlag=HIGH;
lcd.print("Ligit 5 Hold");
}

Serial.println(countTime1);
Serial.println(countTime2);
Serial.println(countTime3);
Serial.println(countTime4);
Serial.println(countTime5);

timeOut1=LOW;
timeOut2=LOW;
timeOut3=LOW;
timeOut4=LOW;
timeOut5=LOW;

43
}

read1=digitalRead(in1);
read2=digitalRead(in2);
read3=digitalRead(in3);
read4=digitalRead(in4);
read5=digitalRead(in5);

if(read1==LOW){digitalWrite(out1,LOW);timeOut1=HIGH;in1Flag=HIGH;}
if(read2==LOW){digitalWrite(out2,LOW);timeOut2=HIGH;in2Flag=HIGH;}
if(read3==LOW){digitalWrite(out3,LOW);timeOut3=HIGH;in3Flag=HIGH;}
if(read4==LOW){digitalWrite(out4,LOW);timeOut4=HIGH;in4Flag=HIGH;}
if(read5==LOW){digitalWrite(out5,LOW);timeOut5=HIGH;in5Flag=HIGH;}

if(read1==HIGH & timeOut1==LOW)


{digitalWrite(out1,HIGH);in1Flag=LOW;countTime1=0;}
if(read2==HIGH & timeOut2==LOW)
{digitalWrite(out2,HIGH);in2Flag=LOW;countTime2=0;}
if(read3==HIGH & timeOut3==LOW)
{digitalWrite(out3,HIGH);in3Flag=LOW;countTime3=0;}
if(read4==HIGH & timeOut4==LOW)
{digitalWrite(out4,HIGH);in4Flag=LOW;countTime4=0;}
if(read5==HIGH & timeOut5==LOW)
{digitalWrite(out5,HIGH);in5Flag=LOW;countTime5=0;}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
////////////-Send All Sms-//////////////////////////////
if(MsgSendFlag==HIGH){MsgSendFlag=LOW;
SendSms();}
////////////////////////////////////////////////////////////
msgReceive(); //
////////////////////////////////////////////////////////////
if(msgComeFlag==HIGH)
{msgComeFlag=LOW;
///////-shift Data from data Array-////////////

44
arrayShift();}
//////////////////////////////////////////////-Msg
Responce-////////////////////////////////////////////////////////////////////////
if(msgComplete==HIGH)
{
msgComplete=LOW;
if(rxCommand[0]=='s'){Serial.println("Reset");}
if(rxCommand[0]=='r'){RssiSend=HIGH;MsgSendFlag=HIGH;}

if(rxCommand[0]=='1'){in1Send=HIGH;MsgSendFlag=HIGH;}
if(rxCommand[0]=='2'){in2Send=HIGH;MsgSendFlag=HIGH;}
if(rxCommand[0]=='3'){in3Send=HIGH;MsgSendFlag=HIGH;}
if(rxCommand[0]=='4'){in4Send=HIGH;MsgSendFlag=HIGH;}
if(rxCommand[0]=='5'){in5Send=HIGH;MsgSendFlag=HIGH;}

rxCommand[0]=0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////-Testing-//////////////////////////////////////////////////////////////
if(Serial.available() >0)
{
char a=Serial.read();
if(a=='a'){Serial.println("-Msg Send-");gsmSend(N,"Sending","","","","");}
if(a=='b'){Serial.println("-Number-");Serial.println(rxNumber);}
if(a=='c'){Serial.println("-Command-");Serial.println(rxCommand);}
if(a=='r'){Serial.print("RSSI: ");Serial.println(rssiValue);}

if(a=='1'){Serial.println("Out1 ON");digitalWrite(out1,LOW);}
if(a=='2'){Serial.println("Out2 ON");digitalWrite(out2,LOW);}
if(a=='3'){Serial.println("Out3 ON");digitalWrite(out3,LOW);}
if(a=='4'){Serial.println("Out4 ON");digitalWrite(out4,LOW);}
if(a=='5'){Serial.println("Out5 ON");digitalWrite(out5,LOW);}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}////-Main End
void gsmStable()
{
///////GSM Inizilizing-////////////////////////////
while(1)
{

45
/////////////////////////-Module ON-/////////////////////////////
Serial1.println("AT");
//if(gsmResponse()==0){Serial.println("Module is Already
ON");}else{Serial.println("Module
ON");digitalWrite(gsmPKey,HIGH);delay(500);digitalWrite(gsmPKey,LOW
);}
////////////////-Wating for module Stablization-////////////////
////////////////-Apply AT Command-////////////////////////////////////////////////
gsmInit();
///////////////-Check Module is Ready-///////////////////////////////
if(moduleReady==0){Serial.println("Module Get Signal");break;}
Serial.println("Waiting For Module Signal");
/////////////////////////-Module OFF-/////////////////////////////
Serial.println("Module OFF");
//digitalWrite(gsmPKey,HIGH);delay(2000);digitalWrite(gsmPKey,LOW);
////////////////-Wating for module Stablization-////////////////
}
}
void SendSms()
{
if(RssiSend ==HIGH){RssiSend
=LOW;Serial1.println("AT+CSQ");gsmResponse();gsmResponse();gsmSend
(N,"","RSSI ",rssiValue,"","");Serial.print("RSSI:
");Serial.println(rssiValue);}
if(in1Send==HIGH){in1Send=LOW;Serial.println("Light One
Hold");gsmSend(N,"","Light 1 Hold ","","","");}
if(in2Send==HIGH){in2Send=LOW;Serial.println("Light Two
Hold");gsmSend(N,"","Light 2 Hold ","","","");}
if(in3Send==HIGH){in3Send=LOW;Serial.println("Light Three
Hold");gsmSend(N,"","Light 3 Hold ","","","");}
if(in4Send==HIGH){in4Send=LOW;Serial.println("Light Four
Hold");gsmSend(N,"","Light 4 Hold ","","","");}
if(in5Send==HIGH){in5Send=LOW;Serial.println("Light Five
Hold");gsmSend(N,"","Light 5 Hold ","","","");}

////////////////-Wating for module Sending Msg-////////////////


for(int i=0;i<10;i++){digitalWrite(smsLed,!digitalRead(smsLed));delay(50);}
digitalWrite(smsLed,HIGH);///LED OFF
}

46
void arrayShift()
{
// memset(rxNumber,0, sizeof(rxNumber));
// memset(rxCommand,0, sizeof(rxCommand));
/////////////////////-Array Shift-//////////////////////////////////////////
/*
N[0]=rxNumber[0]=msgDetail[7];
N[1]=rxNumber[1]=msgDetail[8];
N[2]=rxNumber[2]=msgDetail[9];
N[3]=rxNumber[3]=msgDetail[10];
N[4]=rxNumber[4]=msgDetail[11];
N[5]=rxNumber[5]=msgDetail[12];
N[6]=rxNumber[6]=msgDetail[13];
N[7]=rxNumber[7]=msgDetail[14];
N[8]=rxNumber[8]=msgDetail[15];
N[9]=rxNumber[9]=msgDetail[16];
N[10]=rxNumber[10]=msgDetail[17];
N[11]=rxNumber[11]=msgDetail[18];
N[12]=rxNumber[12]=msgDetail[19];
//rxNumber[13]=msgDetail[20];
*/
////////////////////////////
rxCommand[0]=msgText[1];
rxCommand[1]=msgText[2];
rxCommand[2]=msgText[3];
rxCommand[3]=msgText[4];
//rxCommand[4]=msgText[5];
//rxCommand[5]=msgText[6];
//rxCommand[6]=msgText[7];
//rxCommand[7]=msgText[8];
//rxCommand[8]=msgText[9];
//rxCommand[9]=msgText[10];
}

//////////////////- GSM Functions -/////////////////////////


///////////////////-Msg Receive-/////////////////////////////////////////////////////////////////////
void msgReceive()
{
if(Serial1.available() >0)
{
// Serial.println(".");

47
cc=Serial1.read();
if(cc=='+')
{
msgComeFlag=HIGH;
while(1)
{
digitalWrite(smsLed,!digitalRead(smsLed));
if(lineFlag==LOW)
{
//Serial.print(cc);
msgDetail[aa++]=cc;
delay(50);
cc=Serial1.read();
if(cc==0x0d){aa=0;lineFlag=HIGH;break;}
}}}
if(lineFlag==HIGH)
{
while(1)
{
cc=Serial1.read();
//Serial.print(cc);
msgText[bb++]=cc;
if(cc==0x0d){bb=0;lineFlag=LOW; msgComplete=HIGH;break;}
}}}
digitalWrite(smsLed,LOW);///LED OFF
}
/////////////////////-READ GSM RESPONCE-///////////////////////
int gsmResponse()
{
int count = 0;
char data;
int moduleStatus;
int getCount=0;
while(1)
{
if(Serial1.available())
{
data =Serial1.read();
Serial.print(data);

if(data=='Q'){rssiFlag=HIGH;}

48
if(rssiFlag==HIGH){rssiValue[getCount++]=data; }

if(data == 'K'){moduleStatus=0;Serial.println("OK");}
if(data == 'R'){moduleStatus=1;Serial.println("GSM Not Working");}
if(data == 'E'){moduleStatus=2;Serial.println("Error");}
//delay(5);
//if(data==0x0D){EnterCount=1;}
}
count++;
delay(1);
if(count == 1000){if(data!=0){}else{Serial.println("GSM not Found");}break;}
}
rssiFlag=LOW;

return moduleStatus;
}
///////////////////////////////////////////////////
/////////////////////////////////////////////////////
void gsmInit()
{
Serial.println("AT");
Serial1.println("AT");
gsmResponse();
delay(1000);
Serial.println("ATE0"); // sets the SMS mode to text
Serial1.println("ATE0"); // sets the SMS mode to text
gsmResponse();
delay(1000);
///////////////////////////
//Serial1.println("AT+CFUN"); // check module is ready or not
//gsmResponse();
Serial.println("AT+CMGF=1"); // sets the SMS mode to text
Serial1.println("AT+CMGF=1"); // sets the SMS mode to text
gsmResponse();
delay(1000);
Serial.println("AT+CNMI=2,2,0,0,0"); // sets the SMS mode to text
Serial1.println("AT+CNMI=2,2,0,0,0"); // sets the SMS mode to text
gsmResponse();
delay(1000);
//Serial1.println("AT+CMGD");////delede all message reference.
//gsmResponse();

49
Serial.println("AT+CSQ"); // sets the SMS mode to text
Serial1.println("AT+CSQ");
//Serial1.println("AT+CSQ=?");////check signal Strength
gsmResponse();
gsmResponse();
delay(1000);
Serial.println("AT+CPIN=?");
Serial1.println("AT+CPIN=?");////
moduleReady=gsmResponse();

}
/////////////////////////////////////////////////////
void gsmSend(char n[],char m0[],String m1,char m2[],String m3,char m4[])
{
Serial1.print("AT+CMGS=\""); // send the SMS number
Serial1.print(n);
Serial1.println("\"");
delay(200);
Serial1.print(m0);
Serial1.print(m1);
Serial1.print(m2);
Serial1.print(m3);
Serial1.print(m4);
Serial1.write(0x1A);
delay(1000);
}
/////////////////////////////////////////////////////

50

You might also like