Politehnica University of Bucharest [622659]
P a g e | 1
“Politehnica” University of Bucharest
Faculty of Electronics, Telecommunications and Information Technology
Weather Based Intelligent Street Lightning System
Diploma Thesis
presented as a partial request in order to obtain the title of
Engineer in d omain of Electronics and Telecommunications
Bachelors program Applied Electronics
Scientific Coordinator Graduate
Ș. l. dr. ing. Marius ENĂCHESCU Mihnea -Dan SĂVOIU
Year 2019
P a g e | 2
P a g e | 3
P a g e | 4
P a g e | 5
P a g e | 6
P a g e | 7
TABLE OF CONTENTS
Chapter 1 . Intelligent Street Lightning System Background ………………………………….11
Chapt er 2. Improvements brought for the existing system ……………………………………17
Chapter 3 . Openweather .org website …………………………………………………………19
3.1. API (Application Programming Interface )…………………………………………………..19
3.2. Call current weather data for one lo cation …………………………………………..19
3.3. JSON (JavaScript Object Notation )………………………………………………….27
Chapt er 4. Hardware Imp lementation ………………………………………………………..32
4.1. Transformer ………………………………………………………………………….36
4.2. Voltage Regulator 78 05………………………………………………………………38
4.3. Rectifier………………………………………………………………………………39
4.4. Filter …………………………………………………………………………………40
4.5. Microcontroller AT89S52 ……………………………………………………………41
4.6. IR Led ……………………………………………………………………………….45
4.7. Photodi odes………………………………………………………………………….46
4.8. Led’s…………………………………………………………………………………47
4.9. BC547 Transistor …………………………………………………………………….52
4.10. 1N4007 Diode ………………………………………………………………………54
4.11. Resistors ……………………………………………………………………………58
4.12. Capacitors …………………………………………………………………………..60
4.13. D1 ESP 8266 WiFi B OARD ………………………………………………………..63
Chapter 5. Software implement ation………………………………………………………….64
5.1. Introduction to Keil Micro Vision (IDE )…………………………………………….64
5.2. Concept of compiler ………………………………………………………………….64
5.3. Concept of cross compiler …………………………………………………………….65
5.4. Kei l C cross compiler …………………………………………………………………65
5.5. Creating our application in µVision2 …………………………………………………65
5.6. Debugging an App lication in µ Vision2 ………………………………………………66
5.7. Starting µVision2 and Creating a Project …………………………………………….66
5.8. Building Pro jects and Cr eating a HEX Files ………………………………………….67
5.9. Start Debugging ….……………………………………………………………………67
5.10. Embedded C …………………………………………………………………………67
Chapter 6. De monst rator of the pro ject……………………………………………………….68
6.1. Functionality ………………………………………………………………………….68
6.2. Data processing ………………………………………………………………………69
Conclusions …………………………………………………………………………………..73
Bibliography ………………………………………………………………………………….74
Annex A ………………………………………………………………………………………77
Annex B ………………………………………………………………………………………80
Annex C ………………………………………………………………………………………89
P a g e | 8
List of figures
Chap ter 1
Figure 1.1. AAEON system schematic……. …………….. ……………….. …………………………. .. 12
Figure 1.2. Tvilight system overview application …………………. ……………………………….. .13
Figure 1. 3. Tvilight remote control application CityManager …………………….. ………. ……14
Figure 1.4. inteliLIGHT system principle of workin g……………………………………………… 15
Chap ter 2
Figure 2.1 . Vehicle Movement Based Street Light ……………………………………..17
Figure 2. 2. Weather Based Intelligent Street Li ghtning Syst em………………………..18
Chapter 3
Figure 3.1 . Main Da y Fore cast…………………………………………………………..22
Figure 3.2. Daily Forecast ……………………………………………………………….23
Figure 3 .3. Hourly Foreca st……………………………………………………………..24
Figure 3.4. Temperature fluctuations ……………………………………………………25
Figure 3.5. Wind fluctuati ons……………………………………………………………25
Figure 3.6 . Press ure fluctuations …………………………………………………………26
Figure 3. 7. Map of temperatures and precipi tations ……………………………………..26
Figure 3.8. ID's for a sky with thunderstorms ……………………………………………29
Figure 3.9. ID's for a drizz ly weather ……………………………………………………29
Figure 3.10. ID's for a rainy weather ……………………………………………………30
Figure 3.11. ID’s for a snowy weather ………………………………………………….30
Figure 3.12. ID’s for a clear and cloudy weather ……………………………………….31
P a g e | 9
Chap ter 4
Figure 4.1. System Design Calls…………………………………………………………33
Figure 4.2. “V Diagram” ………………………………………………………………..34
Figure 4.3 . Transform er …………………………………………………………………37
Figure 4.4 . Transform er under load ……………………………………………………..38
Figure 4.5 . Voltage Regulat or 7805……………………………………………………..39
Figure 4.6. Rectifier schematic ………………………………………………………….40
Figure 4.7. Resulta nt wa veform outp ut of a rectifier ……………………………………41
Figure 4.8 . Block Diagram of AT8 9S52 ………………………………………………..43
Figure 4.9. Pin Diagram of AT89S52 ……………………………………………………………44
Figure 4.1 0. IR LED ……………………………………………………………………..45
Figur e 4.1 1. Photodiode …………………………………………………………………46
Figure 4.12. Typical LED ……………………………………………………………….48
Figure 4.13. Different types of LED’S ………………………………………………….48
Figure 4.1 4. White LED spectrum ………………………………………………………..49
Figure 4. 15. BC 547 Transistor Pinout …………………………………………………..53
Figure 4.1 6. NPN Transistor Configuration ……………………………………………..53
Figure 4.1 7. 1N4007 diodes …………………………………………………………….54
Figure 4. 18. PN Junction diode …………………………………………………………54
Figure 4.19. Zero B ias connection ………………………………………………………55
Figure 4.20. Forward Bias connection …………………………………………………..56
Figure 4.2 1. Reverse Bias con nection …………………………………………………..57
Figure 4.22 Resistors ……………………………………………………………………59
Figure 4.2 3 Variable Resistors – Potenti ometers………………………………………..60
Figure 4.2 4 Electrolytic Capacitors ……………………………………………………..61
Figure 4.2 5 Capacitor schematic with dielect ric…………………………………………62
Figure 4.26. D1 ESP8266 Wi Fi BOARD ……………………………………………….63
P a g e | 10
Chap ter 6
Figure 6. 1 Functionality of the project…………………………………………………….. …………… .68
Figure 6. 2a Code upload to ESP8266 …………………………………………………….69
Figure 6. 2b Code upload to ESP8266 ……………………………………………………69
Figure 6. 3 Code in API format ……………………………………………………………70
Figure 6. 4 Last digit change f ormat ………………………………………………………71
Figure 6. 5 Uploading HEX file ………………………………………………………….72
P a g e | 11
Chapter 1. Intelligent Street Lightning System Background
Intelligent street lighting refers to public street lighting that adapts to movement by
pede strian s, cyclists and cars. Inte lligent stree t lighting, also referred to as adaptive street
lightin g, dims when no activity is detected, but br ightens when mo vement is detected. This type
of lighting is different from traditional, stationary illumination , or dimmable street lighting that
dims at pre -determined tim es. Bright street lighting improves road safety, helps to reduce crime,
and makes cities more vib rant a nd attractive places for b oth businesse s and communities.
Traditional street lights, however, are a massive drain on publ ic finances and a major contribu tor
toward s climate change.
To save money and meet a growing public demand for energy efficiency, cities around
the world are in the process o f replacing old street lights with low -power LEDs. But this upgrade
can’t be the e nd of the story f or 21st century lighting systems. Even if modern cities never sleep,
the people who live in them do, and lights don’t need to shine at the same intensity thr oughout
the night.
Types of Intelligent street lightin g systems:
• AAEON Street Li ght Control:
This is a versatil e software application that helps operators manage street lighting
networks. The tool is effectiv e with networks of all sizes, an d it can even handle
networks comprising street light systems in sep arate municipalities. Even with very large
projects, AAEON Street Lig ht Control makes it easy to manage small groups of street
lights or specified actions. Throug h the application’s notifi cation services, operators will
be informed in real time about hardw are malfunctions, and they can also take adv antage
of the a pplication ’s powerful management tools to more efficiently and cost -effectively
ensure that netwo rks ru n as designed.
P a g e | 12
AAEON Stree t Lighting Control can be based on either a server or the cloud, and
it supports LoRa, NB -IoT, and Sub -GHz commu nication channe ls.
Figu re 1.1 – AAEON System
• Tvilight CitySense
This system is desig ned fo r harsh outdoor environmen ts, a combination of smart
sensors within it can detects pedestrians , cyclists, and vehicles, a nd then brings th e lamp
to a hig her bright ness level. After a pre -determined period (once the occupant leaves the
area), the lamp s auto matically return to the pr e-defined lower levels of brightness.
Using the Tvilight CityManager software, we can create li ght profiles that match
the illu mination r equirements of each particular location. For example, on the main roads
of the industry park, the lights dim down to 20 % of their capacity when there is no one
around, and return to 100% brightness as soon as human presence is dete cted. While at
the railwa y crossing, the lights are kept at 70% of brightness. Thanks to the in -built
P a g e | 13
wireless c ommuni cation, each CitySense uni t simultaneously triggers a number of
streetlights in front of the p assing user, also Tvilight connected streetl ights do not tr igger
sudd en flashes of light. The gradual yet quick brightening of lights results in a creation of
a safe circle of light around an occupant and delivers a seamless experience to the passing
drive rs, cyclists, and pedestria ns.
The combinat ion of Tvilight wireless light controls and remote light management
software CityManager enables monitoring, man aging, and controlling its entir e outdoor
lighting infrastructure from a single computer dashboard. For example if a light poin t
fails, CityMana ger immediately sends an e-mail report specifying which luminaire has
malfunctioned and what was the cause (e.g. lamp/ ballast failure), in order for the on-shift
engineer to provide maintenance to the specific pr oblem.
Figure 1.2 – Tvilight s ystem over view application
P a g e | 14
Figure 1.3 – Tvilight remote control appli cation CityManager
• inteliLIGHT
Is a street lighting remote management solution that ensures that the right amount
of light i s provided where and when needed . In-depth grid management gives an accurate
real-time feedback of any change occurring along the grid, reduces energy loss and o ffers
advanced maintenance optimization tools. Using the existing in frastructure, this system
helps us saving mo ney and transfo rm the exi sting distribution level network into an
intelligent infrastructure of the future.
Street lig hting operates autonomousl y, using smart scheduling algorithms based
on astronomical calendar, light level sensors or mot ion detectors – for any lamps wi th
electro nic or electromagnetic ballasts and also architectural lighting.
Malfunctions are repor ted in real time and automatic p rocesses inform the
maintenance teams about the ongoing problems wit h complete details, includi ng
necessary repa irs, spare part s manageme nt and GPS coordinates., it also allows
P a g e | 15
subsequent management of compatible sensors and IoT a pplications. Furthermore, it
integrates with other city systems and smart city platforms throu gh northbound and
southboun d API connectivit y.
Figure 1.4 – inteliLIGHT system principle of wo rking
• inteliLIGHT vs Tvilight CitySense
Tvilight smart street ligh ting systems that feature r emote management and
wireless con trol of o utdoor lights. Their patented presence technology is an adaptive
control feature that p rovides on -demand lighting, meani ng that the right amount of light
is produced when and where it is needed, on the other hand i nteliLIGHT offers detailed
lamp -level tool s of every light in a city to ensure that the right amount of light is provided
when an d where it is required.
Also inte liLIGHT is a sophisticated street lighting system for smart cities that can
turn lights ON and OFF automaticall y, dim the bulbs as requi red, show consumption
P a g e | 16
levels, allow third -party communication through the lighting grid , and generally sense the
city us ing inbuilt wireless sensors.
This technology has proven that it is possible for cities to cut power consumptio n
by up to 80% a nd reduce maintenance costs by up to 50% , both of them using solar
panels to charge the LED from the sun.
• Advantages:
o Automatic Switching of Street lights
o Maintenance Cost Reduction
o Reduction of light pollution
o Wireless C ommunication
o Energy Saving
o Reduc tion of m anpower
o 24/7 Instant reports
o 24/7 Control and programming
o Lamp diagnostics and real -time fault detection as well as prov ision of alarms
• Disadvantages:
o Higher initial investment
o Depende ncy upon the climatic condi tions
o Risk of harm
o Hindering ener gy produc tion from solar panels by accumulating snow, dust,
moisture
P a g e | 17
Chapt er 2. Improvements bro ught for the existing system
The purpose of this chapter is to provide an overview of the additiona l tools used in this
paper . The soluti on wit h which I came up is the introducing of rain, wind and fog sensors . Based
on data collecte d from them, the syste m will ma ke a decision and adapt the street light to road
conditions. Also the system will collect d ata from a weather forecast site and w ill
increase/decrease the light according to weather conditons.
Block diagram of the existing i mplementation :
Figu re 2.1 – Vehicle Movement Based Street Light
P a g e | 18
Block diagram of the improved system :
Figure 2. 2 – Weathe r Based I ntelligent Street Lightni ng Syste m
P a g e | 19
Chapter 3. Ope nweather .org website
The data for the weather forecast will be collected through WiFi Module – ESP8266 and
from https://openweathermap.org/ , also the lights w ill be adapt ed based o n data collected from
the websit e, which has a 5 seconds refresh rate .
The re fresh of data is show n by the blinking LED on the main board at every 5 seconds .
As long as the weather forecast is going to be bad, a certai n amount of LED ’s will be turned on .
For e xample if it is cloudy outside a number of 4 or 5 LED ’s will be turned on , if it is a s unny
day 3 or less LED ’s will be tu rned on.
3.1 API (Application Programming Interface ):
In compute r programming, an applicati on programming in terface (API) is a set of
subroutine definitions, protocols, and tools for building software and applications. Generally
speaking, when we refer to APIs today, we are referring more specifically to web APIs , thos e
delivered over HyperText Transfer Protocol (HTTP).
3.2 Call curren t weather data for one location .
General p arameter s:
• coord
o coord.lon – City geo locatio n, longitude
o coord.lat – City geo location, latitude
• weather
o weather.id – Weather condition id
o weat her.main – Group of weather parameters (Rain , Snow, Extreme e tc.)
o weather.description – Weather condition within the group
o weather.icon – Weather icon id
• base Internal parameter
• main
P a g e | 20
o main.temp – Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial:
Fahrenheit.
o main.pressure – Atmospheric pr essure (on the sea level, if there is no
sea_level or grnd_level data), hPa
o main.humidity – Humidity, %
o main.tem p_min – Minimum temperature at the moment. This is deviation from
current temp that is possible for large cities and megalopoli ses geographicall y
expanded (use these par amete r optionally). Unit Default: Kelvin, Metric:
Celsius, Imperial: Fahrenheit.
o main.t emp_max – Maximum temperature at the moment. This is deviation
from current temp that is possible fo r large cities and megalopo lises
geographica lly expanded (use these p arameter optionally). Unit Default:
Kelvin, Metric: Celsius, Imperial: Fahrenheit.
o main .sea_level – Atmospheric pressure on the sea level, hPa
o main.grnd_level – Atmospheric pressure on th e ground level, hPa
• wind
o wind.speed – Wind s peed. Unit Default: meter /sec, Metric: meter/sec,
Imperial: miles/hour.
o wind.deg – Wind direction, degrees (mete orological)
• clouds
o clouds.all – Cloudiness, %
• rain
o rain.1h – Rain volume for the last 1 hour, mm
o rain.3h – Rain volume for the last 3 hours, mm
• snow
o snow.1h – Snow volum e for the last 1 hour, mm
o snow.3h – Snow volume for the last 3 hours , mm
• dt – Time of d ata calculation, unix, UTC
• sys
P a g e | 21
o sys.type – Internal parameter
o sys.id – Internal parameter
o sys.message – Internal parameter
o sys.c ountry – Country code (GB, JP etc.)
o sys.su nrise – Sunrise time, unix, UTC
o sys.sunset – Sunset time, unix, UTC
• timezone – Shift in seconds from UTC
• id – City ID
• name – City name
• cod – Internal parameter
By city name
We can call b y city name or city name an d country code. A PI responds with a list o f
results that match a searching word. There is a possibility to receive a central dist rict of the
city/town with its own parameters (geographic coordinates/id/name) in API response. For
example API call:
api.openweathermap.org/data/2.5/weather?q={city name}
api.openweathermap.org/data/2.5/weather?q={city name},{country code}
Param eters:
q city nam e and country code divide d by comma, use ISO 3166 country codes
Examples of API calls:
api.openweathermap.org/ data/2.5/weather? q=Bucharest
api.openweathermap.org/da ta/2.5/weather?q=London,uk
P a g e | 22
We can choo se the wa y we visualize the data, such as:
• Main
Figure 3.1 – Main Da y Fore cast
P a g e | 23
• Daily
Figure 3.2 D aily Forecast
P a g e | 24
• Hourly
Figure 3.3 – Hourly Forecast
Also we have acces s to a temp erature map and to a daily basis chart from which we can observe
the temperature , wind , and atmospheri c pressu re fluctuations from the days b efore .
P a g e | 25
Figure 3.4 Temperature fluctuations
Figure 3.5 – Wind fluctuations
P a g e | 26
Figure 3.6 Pre ssure fluctuations
Figure 3.7 – Map of temperatures and pr ecipitations
P a g e | 27
3.3 JSON (JavaScript Object Notation ):
JSON is a lightweight format for st oring and transporting data and stands
for JavaScript Object Notation , it is often used when data is sent from a server to a we b page and
also “self-describing" and easy to understand .
Example of API response:
{
"coord": {
"lon": -122.08,
"lat": 37.39
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clea r sky",
"icon": "01d"
}
],
"base": "stations",
"main" : {
"temp": 296.71,
"pressure": 1013,
"humidity": 53,
"temp_min": 294.8 2,
"temp_max": 298.71
},
"visibility": 16093,
P a g e | 28
"wind": {
"speed": 1 .5,
"deg": 350
},
"clouds": {
"all": 1
},
"dt": 1560350645,
"sys": {
"type": 1,
"id": 5122,
"message": 0.0139,
"country": "US",
"sunrise": 1560343627,
"sunset": 1560396563
},
"timezone": -25200,
"id": 420006353,
"name": "Mount ain View",
"cod": 200
}
P a g e | 29
The number of LEDs lit will be base d on the IDs collected in real time below :
• Thunderstorm
Figure 3.8 – ID's for a sky with thunderstorms
• Drizzle
Figure 3.9 – ID's for a drizz ly weather
P a g e | 30
• Rain
Figure 3.10 – ID’s for a rainy weather
• Snow
Figure 3.11 – ID’s for a snowy weather
P a g e | 31
• Clear and cloudy
Figure 3 .12 – ID's for a clear or a cloud y weather
P a g e | 32
Chapt er 4. Hardware Imp lementation
INTRODUCTION TO EMBEDDED SYSTEMS
What is Embed ded system?
An Em bedded System is a combination of computer hardware and software designed to
perform a specific func tion. An embedded system is a microcontrolle r-based, software driven,
reliable, real -time control system, autonomous, or human or network interactive, opera ting on
diverse physical variables and in diverse environments and sold into a competitive and cost
conscious market.
Embedded systems are comp uting systems, but they c an range from having no user
interface (UI) on devices in which the s ystem is designed to perform a sin gle task to complex
graphical user interfaces (GUIs), such as in mobile devices. Use r interfaces can include bu ttons,
LEDs, touc hscreen sensing and more. Some systems use remote user interfaces as well.
Embedded system har dwar e can be micro processor – or mi crocontroller -based. In either
case, an integrated circuit is at the heart of the pr oduct that is generally des igned to carry ou t
computation for real -time operations. Microprocessors are visually indistinguishable from
microcontrollers, bu t while the micr oprocessor only implements a central processing unit (CPU)
and, thus, requires the a ddition of other components such as memory c hips, microcontrollers ar e
designed as self -contained systems.
P a g e | 33
SYSTEM DESIGN CALLS:
Figure 4.1 System Design Calls
P a g e | 34
EMBEDDED SYSTEM DESIGN CY CLE
Figure 4.2 “V Diagram”
Characteristics of Embedded System
• All E mbed ded Syste ms are task specifi c, they do the same task repeatedly /continuously
over their lifetime. For example: an mp3 player will funct ion only as an mp 3 player.
• Embedded systems are created to perform the task within a certain time frame. It must
therefore perfor m fast enough. . Fo r example: A car’s brake system, if exceeds the time
limit, may cause accidents.
• They have minimal or no use r interface (UI). For example: A fully autom atic washing
machine works on its own after the programme is set and sto ps once the t ask is over.
• Some o f them are designed to react to external stimuli and react accordingly. For
example : A thermometer, a GPS tr acking device.
• Embedded systems are built to achieve certain efficiency levels, they are small sized, can
work with less power an d are not too expen sive.
• They cannot be changed or upgraded by the users. Hence, they must rank high o n
reliability and stabili ty. They are expe cted to function for long d urations without the user
experiencing any difficulties.
• Microcontroller or microproc essors are used to design embedded systems.
P a g e | 35
• They need connected peripherals to attach input & output d evices.
• The hardware of a n embedded -system is used for security and p erformance. The
Software is used for features.
APPLICATIONS
1) Military and aerospace embedded software applications
2) Communication Applications
3) Industrial automation and process control s oftware
4) Mastering the com plexity of applic ations.
5) Reduction of produc t design time.
6) Real time processing of ever increasing amounts of data.
7) Intelligent, autonomous sensors.
CLASSIFICATION
• Real Time Embedded Systems
• Stand -Alone Embedded Systems
• Networked Embedded Systems
• Mobile Embedded Systems
HARDWARE COMP ONENTS :
4.1. TRANSFORMER
4.2. VOLTAGE REGULATO R
P a g e | 36
4.3. RECTIFIER
4.4. FILTER
4.5. MICROCONTROLLE R AT89S52
4.6. IR LED
4.7. PHOTODIODES
4.8. LED s
4.9. BC547 TRANSISTOR
4.10. 1N4007 DIODE
4.11. RESISTORS
4.12. CAPACITO RS
4.13. D1 ESP8266 WiFi B OARD
4.1 TRANSFORMER
A transformer is an electrical device which transfers electrical energy from one electri c
circuit to another, without changing the frequency. The energy tr ansfer usually takes place with a
change of voltage and curr ent with a little loss of power . Step -up tran sformers increase voltage,
step-down transformers reduce voltage. Most power supplie s use a step -down transformer to
reduce the dangerously high voltag e to a safer low voltage.
P a g e | 37
Figure 4.3 Transformer
The inp ut coil is cal led the primary and the output coil is called the secondary . There is
no electrical connection be tween the two coils; instead they are linked by an alt ernating magnetic
field created in the soft -iron core of t he transfo rmer. The two lines in the middle of the circuit
symbol represent the core. Transformers waste very little power so the power out is (almost)
equal to the power in. Note that as voltage i s stepped down and current is stepp ed up.
The ratio of the number of turns on each coil, cal led the turn’s ratio , determines the ratio
of the voltages. A ste p-down transformer has a large n umber of turns on its primary (input) coil
which is co nnected to the high voltage mains s upply, and a small numb er of turn s on its
secondary (out put) coil to g ive a low output voltage.
TURNS RATIO = (Vp / Vs) = ( Np / Ns )
Where,
Vp = primar y (input) voltage.
Vs = secondary (output) voltage
Np = number of turns on primary coil
Ns = number of turns on secondary coil
Ip = primary (inp ut) current
Is = secondary (output) current.
P a g e | 38
Ideal power equation
Figure 4.4 Transfor mer under load
If the secondary coil is attache d to a load that a llows c urrent to flow, electrical powe r is
transmitted from the primary circuit to the secondary circuit. Ideally, the tra nsformer is perfectly
efficient; all the incoming energy is transfo rmed from the primary circuit to the magnetic field
and into the secondary circuit. If this condition is met, the incomin g electri c power must eq ual
the out going p ower:
4.2 VOLTAGE R EGULATOR 7805
The LM78XX/LM78XXA series of three -terminal positi ve regu lators are ava ilable in the
TO-220/D -PAK package and with several fixed output voltages, making th em useful in a Wide
range of applications. Ea ch type employs internal current limiti ng, thermal shutdown and safe
operating area protection, making it essenti ally indestruc tible. If ade quate heat sinking is
provided, they can deliver over 1A output Current . Although designed primarily as fixed voltag e
P a g e | 39
regulators, these devices can be used with external components to obtain adjustabl e voltages and
current s.
Features
• Output Current up to 1A.
• Output Voltages of 5, 6, 8, 9, 10, 12 , 15, 18, 24V.
• Therma l Overl oad Protection.
• Short Circuit Protection.
• Output Transistor Safe Oper ating Area Protection.
Figure 4.5 Voltage Regulat or 7805
4.3 RECTIFIER
A rectifier is an elect rical device that converts alternating current (AC) to direct current
(DC), current th at flows in o nly one direction, a process known as rectification . Rectifiers have
many u ses inclu ding as components of power supplies and as detectors of radio signals.
Rectifiers may be ma de of solid s tate diodes , vacuum tube diodes, mercury arc valves , and other
components. The output from the tr ansformer i s fed to the rectifier. It converts A.C. into
P a g e | 40
pulsating D.C. The re ctifier may be a half wave or a full wave rectifier. In this project, a bridge
rectifier is used beca use of its me rits like good stab ility and full wave rect ification. In positiv e
half cycl e only tw o diodes (1 set of parallel diodes) will conduct, in negat ive ha lf cycle
remaining two diodes will conduct and they will conduc t only in forward bias only.
Figure 4.6 Rectifier schematic
4.4 FILTER
Capacitive filter is used in this project in order to remov e the ripples from the output of
rectifier and for smooth ing the D.C. Output received f rom this f ilter which is cons tant until the
main voltage and load is maintained const ant.
The simple capaci tor filter is the most basic type of power s upply filter. The use of this
filter is very limited . It is sometimes used on extremely high -voltage, lo w-current power supplies
for cathode -ray and similar ele ctron tubes that require very little l oad current fr om t he supply.
This filter is also used in c ircuits where the power -supply ripple frequency is not critical and c an
be relatively high. Below figure can show how the capacitor c hanges and discharges.
P a g e | 41
Figure 4.7 Resulta nt waveform outp ut of a rectifier
4.5 MICROCONTROLLER AT89 S52
The AT89S52 is a low-power, high -performance CMOS 8 -bit microco ntroller with 8 K
bytes of in -system pr ogramma ble Flash memory. The device is manufactured usin g Atmel’s
high-density non volatile memory technology and is compatible with the industry standa rd
80C51 instruction set and pin out. The on -chip Flash allows the program memory to be
reprogrammed in -system or by a conventional n on volatile memory programm er. By combining
a versati le 8-bit CPU with in -system programmable Flash on a monolithic chip, t he A tmel
AT89S52 is a po werful microcontroller which provides a hi ghly-flexible a nd cost -effective
solut ion to many embedded control applications. The AT89S52 p rovides the following stan dard
features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watc hdog timer, two data pointers,
three 16 -bit timer/counters, a six -vector two -level interrupt architectur e, a fu ll duplex serial port,
on-chip oscillator, and cl ock circuitry. In addition , the AT8 9S52 is designed with static logic for
operation down to zero frequency and suppo rts two software selectable power saving modes . The
P a g e | 42
Idle Mode stops the CPU while al lowing the RAM, timer/counter s, serial port, and interru pt
system to continue func tioning. The Power -down mode saves the RAM contents but freezes the
oscillator, disabling all other chip functions until the next interr upt or hardware reset.
Features:
• Compat ible with MCS -51 Prod ucts
• 8K Bytes of In -System Programmable (ISP) Flash Memory
• 4.0V to 5.5V Operatin g Rang e
• Fully Stat ic Operation: 0 Hz to 33 MHz
• Three -level Program Memory Loc k
• 256 x 8 -bit Internal RAM
• 32 Programmable I/O L ines
• Three 16-bit Timer/Counters
• Eight Interrupt Sources
• Full Duplex UART Serial Channel
• Low -power Idle and Power -down Mo des
• Interrup t Recovery from Power -down Mode
• Watchdog Timer
• Dual Data Pointer
• Power -off Flag
• Fas t Programming Time
• Flexible ISP Programming (Byte and Page Mode)
• Green (Pb/Halide -free) Packaging Option
P a g e | 43
Block Diagra m of AT89 S52:
Figure 4.8 Block Diagram of AT89S52
P a g e | 44
Pin Configuratio ns of A T89S52
Figure 4.9 Pin Diagram of AT89 S52
P a g e | 45
4.6 IR LED
An IR (Infrared ) LED, also known as IR transmitter, is a specia l purpose LED that
transmits i nfrared rays in the range of 7 60 nm wavelength. Such LEDs are usu ally made of
gallium arsenide or aluminum gallium arsenide. They, along with IR receivers, are commo nly
used as sensors.
The appeara nce is same as a common LED. Since the human eye cannot se e the infrared
radiations, it is not possible for a person to ide ntify whe ther the IR LED is working or not, unlike
a common LED. To overcome this problem, the camer a on a cell phone can be used. Th e camera
can show us the IR rays being emanated f rom the I R LED in a circuit.
Figure 4.1 0 IR LED
Featur es
• Extra high radiant power
• Low forward voltage
• Suitable for high pulse current operation intensity
• High reliability
P a g e | 46
Chip Materials
• Dice Ma terial : GaA1As /GaAs
• Lens Color : Water Clear
4.7 PHOT ODIODES
A photodiode is a dev ice that helps in conversion of light into electric current. Made of
semi -conductor material and containing a P-N junction, it is d esigned to function in reverse bi as.
Current is pr oduced in the photodiode when photons a re ab sorbed and a small amount of cu rrent
is also produced when the re is no light present. With increase of the surface area, pho todiodes
have slower response times. P hotodiode technology has been suc cessfully and wid ely us ed due
to its simple and low -cost rugged structure
Principle of opera tion
Figur e 4.1 1 Photodio de
The working principle of a photodiode is, when a photon of ample energy strikes the
diode, it ma kes a couple of an electron -hole. This mechanism i s also called as the inner
photoelectri c effect. If the absorption arises in the de pletion region junction , then the carriers are
removed from the junction by the inbui lt electric field of the depletion reg ion. Therefore, holes in
the region move toward th e anod e, and electrons move toward the cathode, and a photocurrent
will be generate d. The entire current t hrough the diode is the sum of the absence of light and the
photocurrent. So the absent current must be reduced to maximize the sensitivity of the dev ice.
P a g e | 47
Photovo ltaic mode
When used in ze ro bias or photovoltaic mode, the f low of ph otocurrent out of the d evice
is restricted and a voltage builds up. The diode becomes forward biased and "dark current"
begins to flow across the junction in the direction o pposit e to th e photocurrent. This mode is
responsible for the photovoltaic effect, which is the basis for solar cells —in fact, a solar cell is
just a large area photodi ode.
Photoconductive mode
In this mod e the diode is often reverse biased, dramatically reduci ng the response time at
the expen se of increased noise. This increas es the wi dth of the depletion la yer, which decreases
the junction's capacitance resulting in f aster response times. The reverse bias induces only a
small amount of current (known as satura tion or back current) along its d irection while the
photocurrent rem ains virt ually the same. The pho tocurrent is linearly proportional to the
luminance
Although t his mode is faster, the photoconductiv e mode tends to exhibit more electronic
noise. The leaka ge curr ent of a good PIN diode is so low (< 1nA) that the Johnson –Nyquist noi se
of the load resistan ce in a typical circuit often dominates.
4.8 LED
LEDs are semiconductor devices. Like transistor s, and other diodes, LEDs are made out
of silicon. What make s an LED give off light are t he small amounts of chemical imp urities that
are added to the silic on, such as gallium, arsenide, indium, and nitride.
When curr ent passes thr ough t he LED, it emits photons as a byp roduct. Normal light
bulbs produce l ight by heating a metal filamen t until it is white hot. LEDs produce photons
directly and no t via heat, they are far more efficien t than incandescent bulbs.
P a g e | 48
Figure 4.12 Typical LED
Not long ago LEDs were only bright enough to be used as indicators on dashboards or
electronic equipment. But recent advances h ave made LEDs bright enough to rival traditional
lightin g technologies. Mod ern LEDs can replace incandescent bulbs in almost any app lication.
Types of LED’ S
LEDs are produced in an array of shapes and si zes. The 5 mm cylindrical package is th e most
common, estimated at 80% of world producti on. The color of the plast ic lens is of ten the same as the
actual color of light em itted, but not always. F or instance, purple plastic is often used for infrared
LEDs, and most blue devices have clear housin gs. There are also LEDs in extremely tiny package s,
such as those found on blinkers and on cell phone keypads. The main type s of LED s are miniature,
high po wer devices and custom designs such as alphanumeric or multi -color.
Figure 4.13 Different types of LED’S
P a g e | 49
White L ED’S
Light Emitting Diodes (LED) have recently become available that are white and bright,
so bright that they seriously compete wit h incandesc ent lamps in lighting applications. Th ey are
still pretty exp ensive as compar ed to a GOW lamp but draw much less current and project a
fairly wel l focused beam.
The diode in the photo came with a neat litt le reflector that tends to sharpen the beam a
little but doesn't seem to add much to the overal l intensity.
When run within the ir ratings, they are more reliable t han lamp s as well. Red LEDs are
now being used in automotive and truck tail lights and in red traffic signal lights. You will be
able to dete ct them because they look like an array of poin t sources and they go on and off
instantly as compared to convention al incan descent lamps.
Figure 4.1 4 White LED spectrum
LEDs are mono chromatic (one color) devices. The colo r is determined by the band gap of
the semicond uctor use d to make them. Red, green, yell ow and blue LEDs are fairly common.
P a g e | 50
White li ght contains all colors and cannot be directly created by a single LED. The most
comm on form of "white" LED really isn't whi te. It is a Gallium Nitride blue LED coated wit h a
phosp hor that, when excited by the bl ue LED light, emits a broad range sp ectrum t hat in addition
to the b lue emission, makes a fairly white light.
There is a claim that these white LED's ha ve a limit ed life. After 1000 hours or so of
operation, they tend to yellow an d dim to some extent. Running th e LEDs at more than their
rated current will certainly accele rate this process.
There are two primar y ways of producing high intensity white -light using LED ’S. One is
to use individual LED ’S that emit three primary colours —red, green, and blue—and then mix all
the colours to fo rm white light. The other is to use a phospho r ma terial to convert
monochromatic light f rom a blue or UV L ED to broad -spectr um white light, much in the same
way a fluorescent light bulb works. Due to metamerism , it is possib le to have quite different
spect ra that appear whi te.
Advantages of using L EDs
• Efficiency:
LEDs p roduce more light per watt than incandescent bulbs; this is u seful in
battery powered or energy -saving devices.
• Size:
LEDs can be very small ( smal ler tha n 2 mm2) and are easily populate d onto
printed cir cuit boards.
• On/Off time :
LEDs light up very qu ickly. A typical red indicator LED will achieve full
brightne ss in microseconds. LEDs used in commun ications devices can have even
faster respons e times.
P a g e | 51
• Cycling:
LEDs are ideal for us e in applications th at are subject t o freque nt on -off cycling,
unlike fluorescent lamps that burn out more quickly when cycled fr equently, or
HID lamps that require a l ong time before restarting.
• Cool light:
In co ntrast to m ost light sources, LEDs radiat e very little heat i n the form of IR
that ca n cause damage to sensitiv e objects or fabrics. Wasted energy is dispersed
as heat th rough the base of the LED.
• Lifetime:
LEDs can have a relatively long useful life. One report e stimates 35,000 to 50,000
hours of useful life, though time to com plete fa ilure may be longer.
• No Toxicity:
LEDs do not contain mercury, unlike fluorescent lamps.
Disadvantages of using LEDs
• High price:
LEDs are currently more expensive , price per l umen, on an initial capital co st
basis, than mos t conventional lig hting te chnologies.
• Temperature dependence:
LED performance largely depends on the ambient temperature of the operating
environme nt. Over -driving the LED in high ambient temp eratures may result in
overheating of the L ED package, eventu ally leading to de vice fai lure.
P a g e | 52
• Voltage sensitivit y:
LEDs must be supplied with the voltage above the thresho ld and a current below
the rating. This can involve series resistors or current -regul ated power s upplies.
• Area light source:
LEDs do not appro ximate a “point s ource” o f light, but rather a lamb ertian
distribution. So LEDs are difficult to use in applic ations requiring a spherical light
field. LEDs are not capable of providing divergenc e below a fe w degrees. This is
contrasted with lasers, which can produce beams with di vergences of 0.2 degrees
or less.
• Blue Haz ard:
There is increasing concern that blu e LEDs and cool -white LEDs are now capa ble
of exceeding safe limits of the so -called blue-light h azard as defined in eye safety .
4.9 BC547 Transi stor
TECHNICAL S PECIFICAT IONS:
BC547 is an NPN Bip olar Junction Transistor. Similar to the other transistors BC547 is
also used for the amplificatio n of current. The smaller amount of current a t the base i s used to
control the larger am ount of currents a t collector and e mitter as well. Its basic applicati ons are
switching and amplification BC847/BC547 series 45 V , 100 mA NPN general -purpose
transistor s.
P a g e | 53
Figure 4. 15 BC 547 T ransistor Pinout
An NPN Tra nsistor Configuration
Figure 4.1 6 NPN Transist or Configuration
P a g e | 54
4.10 1N4007 DIODE
A diode is a semicond uctor device that essentially acts as a one -way switch for current. It
allows current to flow easi ly in one direction, but severely restricts curren t from flowing in the
opposite direction, als o diodes are used t o convert AC into DC the se are used as half wave
rectifier or full wave rectifier. Thre e points must he kept in mind while using any type of d iode.
1.Maximum forward current capacity
2.Maximum r everse voltage capacity
3.Maximum forward volt age ca pacity
Figure 4.17 1N4007 diode s
IN4007 ha s maximum reverse bias voltage capacity of 50V and maximum forward current
capacity of 1 Amp.
Figure 4.18 PN Junction diode
P a g e | 55
PN JUNCTION OPERATION
Ther e are two oper ating regions: P -type a nd N -type. And based on the applied vo ltage, there
are three po ssible “biasing” conditions for the P -N Junction Diode, which are as follows:
1) Zero Bias – No external v oltage is applied to the PN junction diode.
Whe n a di ode is connect ed in a Zero Bias condi tion, no external potential energy is applied
to the PN junctio n. However if the diodes terminals are shorted together, a few holes (majority
carriers) in the P -type material with enough energy to overcome the pot ential barrier will move
across the junctio n against this barrier potential. This is known as the “ Forward Current ” and is
referenced as IF
Likewise, holes generated in the N -type material (minority carriers), find this situation
favourable and move across the junction in the opposite direction. Th is is known as the “ Reverse
Current ” and is referenced as IR. This transfer of electrons and holes back and forth across the
PN junction is known as diffusion, as sho wn below.
Figure 4.19 Zero Bias conne ction
P a g e | 56
2) Forward Bias– The voltage pote ntial is connected positively to the P -type
terminal and negati vely to the N -type terminal of the Diode.
When a diode is connected in a Forward Bias condition, a negat ive voltage is
applied to the N -type material and a positive volta ge is applied to the P -type material. If
this external voltage becomes greater than th e value of the pot ential barrier, approx. 0.7
volts for silicon and 0.3 volts for germanium, the potenti al barriers opposition will be
overcome and cu rrent will start to flow.
This is because t he negative voltage pushes or repels electrons towards the junc tion
giving them t he energy to cross over and combine with the holes being pushed in the
opposite direct ion towards the junction by the positive volta ge. Th is results in a
characteristics curve of zero current flowing up to this voltage point, called the “ knee” on
the stati c curves and then a high current flow through the diode with little increase in the
external voltage as shown below.
Figure 4.2 0 Forw ard Bias conne ction
P a g e | 57
3) Reverse Bias – The voltage potential is connected negatively to the P -type
terminal and positively to the N -type terminal of the Diode.
When a diode is connected in a Reverse Bias condition, a positive voltage is applied
to the N -type material and a negative voltage is ap plied to the P -type material.
The positive voltage applied to t he N -type material attracts electrons towards the
positi ve electrode and away from the junction, while t he holes in the P -type end are also
attracted away f rom the juncti on towards the negative electrode.
The net result is that the depletion layer grows wi der due to a lack of electrons and
holes and presents a high impedance path, almost an insulator. The re sult is that a high
potential barrier is creat ed thu s preventing c urrent from flowing thr ough the
semiconductor material.
Figure 4.2 1 Reverse Bias connection
P a g e | 58
4.11 RESISTORS
A resistor is a two -terminal elec tronic component designed to oppose an el ectric
current by producing a voltage drop between its terminals in proportion to the current, that is, in
accordanc e with Ohm' s law:
V = IR
Resistors are used as part of electrical networks and electronic ci rcuits. They are
extremely commonplace in most electron ic equipment. Practical resistors can be made of various
compo unds and fi lms, as well as resistance wire (wire made of a high -resistivity alloy, such as
nickel/c hrome).
The primary characteristics of resistors are their resistance and the power they can
dissipate. Other characteristics include temperature coefficie nt, noise, and inductance. Less well –
known is critical r esistance, the value below which power diss ipation limits the maximum
permitted cur rent flow, and above which the limit is applied voltage . Critical resistance depends
upon the materials constituting the resisto r as well as its physical d imensions; it's de termined by
design.
Resistors can be inte grated into hybrid and printed circuits, as well as integrated
circuits. Size, and position of leads (or terminals) are relevant to equipment designers; resi stors
must be physically large enough not to overheat wh en dissipating their power.
P a g e | 59
Figure 4.22 Resistors
VARIABLE RESISTORS
Potenti ometer
A potentiometer is a manually adjustabl e resistor . The way this device works is relatively simple.
One terminal of the potentiometer is con nected to a power source. Another is hooked up to ground (a
point with no voltage or resista nce and w hich serves as a neutral reference point), while the th ird
terminal runs across a strip of resistive material. This resistive strip generally has a low res istance at
one end; its resistance gradually increases to a maximum resistance at the other end. The third terminal
serves as the connection between the pow er source and ground, and is usually interfaced to the user by
means of a knob or lever. The user ca n adjust the position of the third terminal along the resistive strip
in order to manually i ncrease o r decrease resistance. By controlling resistance, a pot entiometer can
determine how much current flow through a circuit. When used to regulate current, the potentiometer
is limited by the maximum resistivity of the strip.
P a g e | 60
The power of th is simple device is not to be underestimated. In most analog dev ices, a
potentiometer is what establishes the levels of output. In a loud speaker, for example, a po tentiometer
directly adjusts volume; in a television monitor, it controls brightness.
Figure 4.2 3 Variable Resistors – Potenti ometers
A potentiometer can also be used to control the potential difference, or voltage, across a ci rcuit.
The setup involved in utilizing a potentiometer for this purpose is a little bit more complica ted. It
involves two circuits: the first circu it consis ts of a cell and a resistor. At one end, the cell is connected
in series to the second circuit, and at the other end it is connected to a potentiometer in parallel with
the second circuit. The potentio meter in this arrangement drops the voltage by an amoun t equal to the
ratio between the resistance allowed by the position of the third terminal and the hi ghest possible
resistivity of the strip. In other words, if the knob controlling the resista nce is po sitioned at the exact
halfway point on the res istive st rip, then the output voltage will drop by exactly fifty percent, no
matter how high the potentiomete r's input voltage. Unlike with current regulation, voltage regulation is
not limited by the maximum r esistivity of the strip
4.12 CAPACITORS
A capacitor or condenser is a passive electronic component consisting of a pair of
conductors separated by a die lectric. When a voltage potential difference exists between the
conductors, an electric field is pres ent in the dielectric. This field stores energ y and pro duces a
P a g e | 61
mechanical force between the plates. The effect is greatest between wide, flat, parallel, na rrowly
separated conductors.
An ideal capacitor is characterized by a single constant value, capacit ance, which is
measured in farads. This is the ratio of the electric charge on each conductor to the potential
difference between them. In practice, the di electric between the plates passes a small amount of
leakage current. The conductors and lead s introd uce an equivalent series resistance and the
dielectric has an electric field strength limit resulting in a breakdown voltage.
The properties of capacitors in a circuit may determine the resonant frequency and quality factor
of a resonant circuit, p ower dis sipation and operating frequency in a digital logic cir cuit, energy
capacity in a high -power system, and many other important aspects.
Figure 4.24 Electrolytic Capacitors
P a g e | 62
Capacitance
Figure 4.25 Capacitor schematic with dielectric
Charge separation in a parallel -plate capacitor causes an internal electric field. A di electric
(orange) reduces the field and increases the capacitance.
A capacitor consists of two conductors separated by a non -conductive region. The non –
conductive r egion is called the dielectri c or sometimes the dielectric medium . In simpler terms,
the dielectric is just an electrical insulator . Example s of dielectric mediums are glass, air, paper,
vacuum , and even a semiconduc tor depletion region chemically identical to the conductors. A
capacitor is assumed to be self -contained an d isolated, with no net electric charge and no
influen ce from any external electric field. The conductors thus hold equal and opposite charges
on their facing surfaces, and the dielectric develop s an electric field. In SI units, a capacitance of
one farad means that one coulomb of charge on each conductor causes a voltage of one volt
across the device.
The capacitor is a reasonably general mod el for electric fields within electric circuits. An
ideal capacitor is wholly characterized by a con stant capacitance C, defined as the ratio of charge
±Q on each conductor to the voltag e V between them:
Sometime s charge build -up affects the capacitor m echanically, causing its capacitance to vary. In
this case, capacitance is defined in terms of incre mental changes:
P a g e | 63
4.13 D1 ESP 8266 WiFi B OARD
The WeMos D1 is a ESP8 266 WiFi based board that uses the Arduino layout with a
operating voltage of 3.3V. ESP8266 with 32 MiB of built -in flas h, allowing for single -chip
devices capab le of connecting to Wi -Fi.
Figure 4. 26 – D1 ESP8266 WiFi BOARD
The development board also includes a CH340 USB to seri al interface giving it the
ability to be connected and programmed directly fro m your computer and requiring only a
comm on micro USB cable – no additional interface hardware or configuring is required. Once
connected to the computer, and drivers have been i nstalled, the ESP82 66-D1 will appear as a
standard serial COM port.
P a g e | 64
Chapt er 5. Software imple mentation
5.1 INTRODUCTION TO KEI L MICRO VI SION (IDE )
Keil is an AR M Company who makes C compilers, macro ass emblers, real -time kernels,
debuggers, simulators, integrated environments, evaluation boards, and e mulators for
ARM7/ARM9/Cortex -M3, XC16x /C16x/ST10, 251, and 8051 MCU families .
Keil d evelopmen t tools for the 80 51 Microcontroller Architecture support ev ery level of
software developer from the professional applications engineer to the student just lear ning about
embedded software developme nt. When starting a new project, we simply select the
microcontroller we are using from the Device Database and the µV ision IDE sets all compiler,
assembler, linker, and memory options for us.
5.2 CONCEPT OF COMPILER
Compilers are programs used to convert a High Level Language to object code . Desktop
compilers produce an output object code for the underlying microproce ssor, but not for other
microprocessors. The programs written in one of the HLL like ‘C’ will compil e the code to run
on the system for a particular processor like x86 (underlyi ng micropr ocessor i n the computer).
The compiler derives its name from the way it works, looking at the ent ire piece of
source code and collecting and reorganizing the instructio n. See there is a bit little difference
between compiler and an interpreter . Interprete r just in terprets whole pro gram at a time while
compiler analyses and execute each line of source code in succession, without looking at the
entire program.
The advant age of interpreters is that they can execute a program immediately. Secondly
programs p roduced b y compilers run mu ch faster than the same programs executed by an
interpreter. However c ompilers require some time before an executable program emerges. Now
P a g e | 65
as compilers translate source code into object code, which is unique for each ty pe of comp uter,
many compilers are av ailable for the same language.
5.3 CONC EPT OF CROSS COMPILER
A cross compiler is similar to the compilers but we write a program for the t arget
processor (like 8051 and its derivatives) on the host processors (like computer o f x86). I t means
being in o ne environment we are writing a code for a nother environment is ca lled cross
development and the compiler used for cross development is called cross compiler.
5.4 KEIL C CROSS COMPILER
Keil is a German based Software developme nt compan y. It provides sev eral
development tools like :
• IDE (Integrated Development environment)
• Project Manager
• Simulator
• Debugger
• C Cross Compiler, Cross A ssembler, Locator/Linker
The Keil ARM tool kit inclu des three main too ls, assembler, compiler and linker. An
assembler is used to assemble the ARM assembly program. A compiler is used to compile the C
source code into an object file. A linker is used to create an absolute object m odule su itable for
our in -circuit emulator.
5.5 Creating Our Own Application in µVis ion2
To create a new project in µVision2, we must :
1. Select Project – New Project.
P a g e | 66
2. Select a directory and enter the na me of the project file .
3. Select Project – Select Device a nd select an 8051, 251, or C16x/ST10 devi ce from the
Device Database .
4. Create source files to add to the project.
5. Select Project – Targets, Groups, Files. Add/Files, select Source Grou p1, and add the
source fil es to the pro ject.
6. Select Project – Options and set the tool options. Note when we selec t the target
device from the Device Databa se all special options are set automatically.
7. Select Project – Rebuild all target files or Build tar get.
5.6 Debugging an App lication in µ Vision2
To debug an application c reated using µVision2, we must:
1. Select De bug – Start/Stop Debug Session.
2. Use the St ep toolbar buttons to single -step through our program. We may enter G, main
in the Output Window to execute to the main C func tion.
3. Open th e Serial Window using the Serial # 1 button on the toolbar.
5.7 Starting µV ision2 and Creating a Project
µVision2 is a standard Windows application and started by clicking on the program icon.
To create a new project file select from the µVis ion2 menu Project – New Project…. This opens
a standard Windows dialog that asks ua for the new project file name. We can simply u se the
icon Create New Folder in this dialog to get a new empty folder. Then selec t this folder and enter
the file name for th e new project , this creates a new project file with the name that we entered ,
which cont ains a default target and file group name.
P a g e | 67
5.9 Building Projects and Creating a HEX Files
Typical, the tool settings under Options – Targe t are all you need to start a new
application. You may translat e all source files and line the application with a click on the Build
Target toolbar icon. Wh en we build an application with syntax errors, µVision2 will display
errors and warning messages in the Output Window – Build page. A double clic k on a message
line opens the s ource fil e on the correct location in a µVision2 editor window. Once we have
successfully generated our application , we can start debugging.
After we have tested our application, i t is required to create an Intel HEX fil e to
download the softw are into an E PROM prog rammer or simulator. µVisi on2 creates HEX files
with each build process when Create HEX files under Options for Target – Output is enabled.
5.11 Start Debugging
We start the debug mode of µVision2 with the Debug – Start/Stop Debug Session
Command. Depending on the Options for Targ et – Debug Configuration, µVision2 will lo ad the
application program and run the startup code µVision2 saves the editor screen layout and
restores the screen layout of the last debug session. If the program execution stops, µVision2
opens an editor window with the source text or shows CPU instruct ions in the disassembly
window. The next executable statement is marked with a yellow arrow. During debugging, most
editor features are still available.
5.13 Embedded C
Use of embedded proce ssors in passenger ca rs, m obile phones, medical equipment,
aerospace systems and defense systems is widespread, and even everyday domestic appliances
such as dish washers, televisions, washing machines and video recorders now i nclude at least one
such devi ce.
P a g e | 68
Chapter 6 . Demon strator of the pro ject
6.1 Functionality
The initializat ion o f the system starts from verifyi ng if the main board is connected
through a 12V supply , alos D1 ESP8266 needs to be connected to Microcontroller AT89S52
through TX ->DI port and GND , the WiFi boa rd must be checked if it is c onnected to internet
through a mobile hotspo t made from a Samsung Galaxy A3.
The blinking LED marked with an ‘X’ under it shows us that the connection is
established a nd at every 5 seconds the LED wil l blink and new, fresh data will be collected fr om
the website https://openweathermap.org .
Figure 6.1 – Functionality of the proj ect
P a g e | 69
6.2 Data processing
First of all we need to upload the code on the WiFi board using Ardui no IDE.
Figure 6.2 a – Code upload to ESP8266
Figure 6.2 b – Code upload to ESP8266
P a g e | 70
Data will be collected over API it is often used when data is sent from a server to a web
page in the below format.
Figure 6. 3 – Code in API format
If the ab ove URL is acces sed the data output of the API response will be:
{"coord": { "lon": 139,"lat": 35},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}
],
"base": "stations",
"main": {
"temp": 289.92,
"pressure": 1009,
"humidity": 92,
"temp_min": 288.71,
"temp_max": 29 0.93
},
"wind": {
"speed": 0.47,
"deg": 107.538
},
"clouds": {
P a g e | 71
"all": 2
},
"dt": 15 60350192,
"sys": {
"type": 3,
"id": 2019346,
"message": 0.0065,
"country": "JP",
"sunrise": 1560281377,
"sunset": 1 56033347 8
},
"timezone": 32400,
"id": 1851632,
"name": "Shuzenji",
"cod": 200
}
In our case we will check the ID which is the same format as we pr esented in Chapter 3.
The last digit (bonus ) it will show us how bad it is the we ather. For example if it is “0”
means that the w eather is nice . The higher the last digit increase, the wo rse will be the weather
cond itions .
Figure 6. 4 – Last digit change format
Once the code is uploaded we can go to the next stage which mea ns uploading the HEX
code to the microcontroller AT89S52 .
First we need to i denti fy the Microcontroller that we are using and second ly we will op en
a pop -up window and upload the respect ively HEX file for our project on AT89S52 .
P a g e | 72
Figure 6. 5 – Uploading HEX file
P a g e | 73
Conclusio ns
In conclusion, optimizing consumption can accomplish several things. The simplest way
is to use L EDs inst ead of classic al light bulbs , because LED s can last much more such as 25 ,000
hours instead of classical light bulbs which last around 8 ,000 hours . Firstly we can reduce the
power co nsumption by programming them when to tu rn on and off . Second ly it depends on the
weather conditions , if there are harsh c onditions LED s are a must, because their consumption is
around 7W instead of 60 W, data held by the n ormal light bulb .
Through these aspects, the costs of energy as well as of maintenance dec rease
significantly.
P a g e | 74
Bibliography
[1] https://www.aaeon.com/en/ac/intelligent -street-lighting
[2] https://en.wikipedia.o rg/wiki/Intelligent_street_lighting
[3] https://www.tvilight.com/wp -content/uploads/2017/10/Case -study -Moerdijk -V1.1 –
English.pdf
[4] http://www.appcessories.co.uk/how -smart -lighting-is-revolutionising -how-we-relate –
live-and-work/
[5] https://www.quora.com
[6] http://www.wi4b.it/outdoor_smart_lighting.php
[7] https://www.ele ctronicshub.org/basics -of-embedded -c-
program/#Introduction_to_Embedded_C_Programming_Language
[8] https://www.elprocus.com/ basics-and-structure -of-embedded -c-program -with-
examples -for-beginners/
[9] https://thinkelectr onics.org/types -of-capacitors/
[10] https://www.electronics -tutoria ls.ws/transformer/transformer -basics.html
[11] https://www.incibe -cert.es/en/blog/introduction -embedded -systems
[12] https://www.javatpoint.com/characteristics -of-embedded -system
[13] https://www.elprocus .com/working -procedu re-on-how-do-transformers -work/
[14] https: //electronicsforu.com/resources/learn -electronics/7805 -ic-voltage -regulator
[15] http://www.learningaboutelectronics.com/Articles/What -is-a-LM7805 -voltage –
regulator
[16] http:// hades.mech.northwest ern.edu/images/6/6c/LM7805.pdf
[17] https://www.physics -and-radio -electronics.com/electronic -devices -and-
circuits/rectifi er/rectifier -whatisrectifier.html
P a g e | 75
[18] https://slideplayer.com/slide/5313996/
[19] https://en.wikipedia.org/wiki/Rectifier
[20] https://components101.com/microcontrollers/at89s5 2-microcontroller -pinout –
features -datasheet
[21] http://elpr ojects.blogspot.com/2010/06/microcontroller -at89s52 -description.html
[22] http://ww1.microchip.com/downloads/en/DeviceD oc/doc1919.pdf
[23] https://whatis.techtarget.com/definition/IR -LED -infrared -light-emitting -diode
[24] https://electronic sforu.c om/resources/learn -electronics/ir -led-infrared -sensor -basics
[25] https://components101.com/ir -led-pinout -datasheet
[26] https://www.elprocus.com/photodiode -working -principle -applications/
[27] https://www.sciencedirec t.com/topics/enginee ring/photodiode
[28] https://en.wikipedia.org/wiki/Photodiode
[29] https://w ww.ledsmagazine.com/ leds-ssl-design/materials/article/1670129 2/what -is-
an-led
[30] https ://www.sparkfun.com/datasheets/Components/BC546.pdf
[31] https://w ww.theengineeringprojects.com/2017/06/introduction -to-bc547 .html
[32]https://sciencing.com/1n4007 -diode -specs -7448252.html
[33]https://www.theengineeringprojects.com/2017/07/introduction -to-1n400 7.html
[34] https://www.tech opedia.com/definitio n/683/resistor
[35] https://www .electronics -notes.com/articles/electronic_components/r esistors/resistor –
types.php
[36] https://en.wi kipedia.org/wiki/Resistor
[37] https://en.wi kipedia.org/wiki/Capacitor
[38] https://www.rap idtables.com/electric/capacitor.html
P a g e | 76
[39] https://howtomechatronics.com/how -it-works/electronics/what -is-capacitor -and-
how-it-works/
[40] http://www2.keil.com/mdk5/uvision/
[41] https://www.quora.com/How -would -one-explain -the-concept -of-a-compiler –
compiler
[42] https://isocpp.org/blog/2016/ 02/a-bit-of-background -for-concepts -and-cpp17 -bjarne –
stroustrup
[43] https://www.elprocus.com/basics -and-structure -of-embedded -c-program -with-
examples -for-beginners/
[44] https://ww w.electronicshub.org/basics -of-embedded -c-program/
[45] https://openweathermap. org/weather -conditions
[46] https://openweatherm ap.org/api
[47] https://openweathermap.org
[48] https://apigility.org/documentation/api -primer/what -is-an-api
[49] https://www.quora.co m/What -is-an-API-request
[50] https:/ /www.w3schools.com/js/js_json_intro .asp
[51] https://www.instruct ables.com/id/ESP -03-Upgrade -Flash -Memory -to-128-M-Bit/
[52] https://hobbycomponents.com/esp 8266/788 -esp8266 -d1-arduino -compatible –
development -board
[53] https://en.wikipedia.org/wiki/ESP8266
P a g e | 77
Annexes
Annex A. Arduino code for D1 ESP8266
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTT PClient.h>
#include <ArduinoJson.h>
// wifi network data
const char* wifiName = "mihnea -wifi";
const char* wifiPass = "12345678";
//Web Se rver address to read/write from
const char* host =
"http://api.openweathermap.org/data/2.5/wea ther?q=Bucharest,ro& APPID=46b62da7ede47da2c
d3e92cc7c138e55";
void setup() {
Serial.begin(9600);
WiFi.begin(wifiName, wifiPass);
while (WiFi.status() != WL_CONNECTED) {
delay(500 ); /* keep trying to connect to wifi */
P a g e | 78
}
}
void loop() { // loop se executa la infinit
HTTPClient http; //Declar e object of class HTTPClient
http.begin(host); //Specify request destination
int httpCode = http.GET(); //Send the request
String payload = http.getString(); //Get the response payload fro m server
int condition_id;
if(http Code == 200) // cod 200 = am primit json, e ok
{
// Allocate JsonBuffer
// Use arduinojson .org/assistant to compute the cap acity.
const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ ARRAY_SIZE(2) + 60;
DynamicJsonBuffer jsonBuffer(capacity );
// Parse JSON object
JsonObject& root = jsonBuffer.parseObject(payload);
condition_id = root["weather"][0]["id"].as<int>();
Serial.println( condition_id % 100 );
P a g e | 79
/*
* weath er codes end with th eir severity index. so you use last digit ( number mod 100);
* so th at index will be used asa bonus value for led distance
*/
}
else Serial.print("4"); /* if server communication was unsucessful, set the lights on */
http.end(); //Close con nection
delay(5000); //GET Data at every 5 seconds
}
P a g e | 80
Annex B . 8051 Arduino programmer
/**
PROGRAM MING AN ATMEL AT89S51/52 US ING ARDUINO
RELEASED AS IS WITHOUT WARRANTY
I AM NOT LIABLE FOR ANY DAMAGE DONE TO YOUR HARDWA RE
THIS PROJECT IS F OR EDUCATIONAL PURPOSES ONLY
Credits to N ICK PABLO for the Arduino Sketch
TIKTAK (C) 2014
**/
#define dummyData 0xAA
#define RDY 75
#define NRDY 76
const int _MISO = 4;
const int _MOSI = 5;
const int _CLK = 3;
const int RST = 2;
/* Variable definition block */
P a g e | 81
byte data;
byte AL,AH; // 16 -bit address
byte lockByte; // embed lock bits here
byte SigH,SigL; // Signature Bytes
void setup()
{
pinMode(_MISO, INPUT);
pinMode(_MOSI, OUTPUT);
pinMode(_CLK, OUTPUT);
pinMode(RST, OUTPUT);
Serial.begin(115200); / / depends on the setting of the host PC
}
void loop()
{
while (!Serial.available()); // wait for character
P a g e | 82
if (Serial.availabl e() > 0)
switch (Serial.read())
{
case 'p': Serial.write(progEnable());
break;
case 'r': readProgmem();
Serial.write(data);
break;
case 'a': while(!Serial.avail able());
AL = Serial.read();
break;
case 'A': whil e(!Serial.available( ));
AH = Serial.read() ;
break;
case 'd': while(!Serial.available());
data = Serial.read();
break;
case 'S': AH = 0;
AL = 0;
SigH = read Sign();
Serial.w rite(SigH);
P a g e | 83
break;
case 's': AH = 2;
AL = 0;
SigL = readSign();
Serial.write(SigL);
AH = 1;
AL = 0 ;
SigL = readSign();
Serial.write(SigL);
break; // read SigL
case 'o': digitalW rite(RST,1);break;
case 'c': digitalWrite(RST,0);break;
case 'e': eraseChip() ;
Serial.write(RDY);
break;
case 'j': break;
case 'w': writeProgmem();
break;
}
P a g e | 84
}
unsigned char SendSPI(unsigned char data)
{
uint8_t retval = 0;
uint8_t intData = dat a;
int t;
for (int ctr = 0; ctr < 7; ctr++)
{
if (intData & 0x80) digitalWrite(_MOSI,1);
else digitalWrite(_MOSI,0);
digitalWrite(_CLK,1);
delayMicroseconds(1);
t = digitalRead(_MISO);
digitalWrite(_CLK ,0);
P a g e | 85
if (t) retval |= 1; else re tval &= 0xFE;
retval<<=1;
intData<<= 1;
delayMicroseconds(1);
}
if (intData & 0x80) digitalWrite(_MOSI,1);
else digitalWrite(_MOSI,0);
digitalW rite(_CLK,1);
delayMicroseconds(1);
t = digitalRead (_MISO);
digitalWrite(_CLK,0);
if (t) retval |= 1;
else retval &= 0xFE;
retur n retval;
}
P a g e | 86
byte progEnable()
{
SendSPI(0xAC);
SendSPI(0x53);
SendSPI(dummyData );
return Se ndSPI(dummyData);
}
void eraseChip()
{
SendSPI(0xAC);
SendSPI(0x9F);
SendSPI(dummyData);
SendSPI(dummyData);
delay(520);
}
P a g e | 87
void readProgmem()
{
SendSPI(0x20);
SendSPI(AH);
SendSPI(AL);
data = SendSPI(dummyD ata);
}
void writeProgmem()
{
SendSP I(0x40);
SendSPI(AH);
SendSPI(AL);
SendSPI(data);
}
void writeLockBits()
{
SendSPI( 0xAC);
SendSPI(lockByte);
P a g e | 88
SendSPI(dummyData);
SendSPI(dummyData);
}
void readLockB its()
{
SendSPI (0x24);
SendSPI(dummyData);
SendS PI(dummyData);
lockByte = SendSPI(dummyData);
}
byte readSign()
{
SendSPI(0x28);
SendSP I(AH);
SendSPI(AL);
return SendSPI(dummyData);
}
P a g e | 89
Annex C . Microcontroller HEX file
#include <reg51.h> // constante de model de microcontroler
sbit S1=P0^7;
sbit S2=P0^6;
sbit S3=P0^5;
sbit S4=P0^4;
sbit S5=P0^3;
sbit S6=P0^2;
sbit S7=P0^1;
sbit S8=P0^0;
sbit out1=P3^5; // portul 3,pinul 5
sbit out2=P3^4;
sbit out3=P3^3;
sbit out4=P3^2;
sbit out5=P3^1;
sbit out6=P3^0;
sbit out7=P2^0;
sbit out8=P2^ 1;
P a g e | 90
sbit out9=P2^2;
sbit out10=P2^3;
sbit out11=P2^4;
sbit out12=P2^5;
sbit out13=P2^6;
sbit out14=P2 ^7;
sbit s witch1=P1^0;
unsigned char bonus=0;
unsigned char i;
void initialize() // Initializ e Timer 1 for serial communication
{
EA =1;
ES =1;
TMOD=0x2 0; //Timer1, mode 2, baud rate 9600 bps
TH1=0XFD; //Baud rate 9600 bps
P a g e | 91
SCON=0x50;
TR1=1; //Start timer 1
}
void receive() //Function to receive serial data
{
bonus=SBUF; //ia ce e in buff er si pune in bonus
}
void Delay(void) //astepata, ca nu f ace nimic 10000 cicluri
{
int j;
int i;
for(j=0;j<10000;j++)
{
}
P a g e | 92
}
void UART_Interrupt() interrupt 4 {
if (RI == 1) {
receive();
RI=0; // sterge flagul de i ntrerupere
}
if (TI == 1) {
TI = 0;
}
}
void m ain()
{
P0= 0xFF;
P2= 0xFF;
P3= 0xFF;
initializ e();
while(1)
P a g e | 93
{
if(S1==1)
{
P2 =0xFF; // le p ui pe toate pe 1 ca sa se stinga toate ledurile
P3 =0xFF;
if( bonus==0) {out1=0;out2= 0; out3=0;} //aprind e leduri
if( bonus==1) {out1=0;out2=0; out3=0; out4=0;}
if( bonus==2) {out1=0;out2=0; out3=0; out4=0; out5=0;}
if( bonus>=3) {out1=0 ;out2=0; out3=0; out4=0; out5=0;
out6=0;}
Delay();
}
if(S2==1)
{
P2 =0xFF;
P3 =0xFF;
if( bonus== 0) {out2=0;out3=0; out4=0;}
P a g e | 94
if( bonus==1) {out2=0;out3=0; out4=0; out5=0;}
if( bonus==2) {out2=0;out3=0; out4=0; out5=0; out6= 0;}
if( bonus>=3) {out2=0;out3=0; out4=0; out5=0; out6=0;
out7=0;}
Delay();
}
if(S3==1)
{
P2 =0xFF;
P3 =0xFF;
if( bonus==0) { out3=0;out4=0; out5=0;}
if( bonus==1) {out3=0;out4=0; out5=0; out6=0;}
if( bonus==2) {out3=0;o ut4=0; out5=0; out6=0; out7=0;}
if( bonus>=3) {out3=0;out4=0; out5=0; out6=0; out7=0;
out8=0;}
Delay();
}
P a g e | 95
if(S4==1)
{
P2 =0xFF;
P3 =0xFF;
if( bonus==0) {out4=0;out5=0; out6=0;}
if( bonus==1) {out4=0;out5=0; out6=0; out7=0; }
if( bonus==2) {out4=0;out5= 0; out6=0; out7=0; out8=0;}
if( bonus>=3) {out4=0;out5=0 ; out6=0; out7=0; out8= 0;
out9=0;}
Delay();
}
if(S5= =1)
{
P2 =0xFF;
P3 =0xFF;
if( bonus==0) {out5=0;out6=0; out7=0;}
if( bonus==1) {ou t5=0;out6=0; out7=0; out8=0;}
if( bonus==2) {out5=0;out6=0; out7=0; out8=0; out9=0;}
P a g e | 96
if( bonus>=3) {out5=0;o ut6=0; out7=0; out8=0; out9=0;
out10=0;}
Delay();
}
if(S6==1)
{
P2 =0xFF;
P3 =0xFF;
if( bonus==0) {out6=0;out7=0; out8=0;}
if( bonus==1) {out 6=0;out7=0; out8=0; out9=0;}
if( bonus==2) {out6=0;out7=0; out8=0; out9=0; out10=0 ;}
if( bonus>=3) {out6=0;out7=0; out8 =0; out9=0; out10=0;
out11=0;}
Delay();
}
if(S7==1)
{
P a g e | 97
P2 =0xFF;
P3 =0xFF;
if( bonus==0) {out7=0;out8=0; out9=0;}
if( bonus==1) {out7=0;out8=0; out9=0; out10=0;}
if( bonus==2) {out7=0 ;out8=0; out9=0; out10=0; out11=0;}
if( bonus>=3) {out7=0;out8=0; out9=0; out10=0; out11=0;
out12=0;}
Delay();
}
if(S8==1)
{
P2 =0xFF;
P3 =0xFF;
if( bonus==0) {out8=0;out9=0; out10=0;}
if( bonus==1) {out8=0;out9=0; out10=0; out11=0;}
if( bonus==2) {out8=0;out9=0; out10=0; out11=0; out12=0;}
if( bonus>=3) {out8=0;out9=0; out10=0; out11=0; out12=0;
out13=0; }
P a g e | 98
Delay ();
}
}
}
Copyright Notice
© Licențiada.org respectă drepturile de proprietate intelectuală și așteaptă ca toți utilizatorii să facă același lucru. Dacă consideri că un conținut de pe site încalcă drepturile tale de autor, te rugăm să trimiți o notificare DMCA.
Acest articol: Politehnica University of Bucharest [622659] (ID: 622659)
Dacă considerați că acest conținut vă încalcă drepturile de autor, vă rugăm să depuneți o cerere pe pagina noastră Copyright Takedown.
