Politehnica University of Bucharest [622660]

1 | P a g e

“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 domain of Electronics and Telecommunications
Bachelors program Applied Electronics

Scientific Coordinator Graduate
Ș. l. dr. ing. Marius ENĂCHESCU Mihnea -Dan SĂVOIU

Year 2020

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 | P a g e

TABLE OF CONTENTS

Introduction ………………………………………………………………………………15
Chapter 1
Street Lighting System Overview ………………………………… …………… ……… …… 17

Chapter 2
Weather Based Intelligent Street Lightning System ……………………………… …23

Chapter 3
Hardware implementation ……………………………………………………… ….…26
3.1. Transformer …………………………………… ……………………………….. .26
3.2. Voltage Regulator 7805 …………… ……….. …………………… ………27
3.3. Rectifier …………………………… ……………………………. ……….2 8
3.4. Filter………………………………………………………………………28
3.5. Microcontroller AT89S52 ………………………..……………………..29
3.6. D1 ESP8266 WiFi B oard ……………………………………………….32
3.7. IR LED ………………………………………………………………….32
3.8. Photodiode ………………………………………………………………34
3.9. LED ……………………………………………………………………..35
3.10. BC547 Transistor ……… ………………………………………………41
3.11 1N4007 D iode ………………………………………………………….42
3.12. Resistors ………………….……………………………………………46
3.13. Capacitors ………………………………………………………………48

8 | P a g e

Chapter 4
Weather forecast data collection …………………………………………… ………. 50
4.1. API …………………………………………………………….. ………… .50
OpenWeatherMap ………………………………………… ..……. ……50
Weatherbit ………………………………………………………… …50
AccuWeather ………………………………………………………… 50
Weather2020 …………………………………………………… ………50
4.2. JSON………………………………………………………… ……… ….54

Chapter 5
Demonstrator of the project ………………………………………………………….58

Conclusions ……………………………………………………………………………… ..67

References …………………………………………………………………………………..68

Annexes ………………………………………………………………………………… …..70
Annex A…………………………………………………………………………… ….70
Annex B…………………………………………………………………………… ….73
AnnexC……………………………………………………………………………… .81

9 | P a g e

10 | P a g e

List of figures
Chapter 1
Figure 1.1. AAEON system ………… ………………………………………………………………….. .18
Figure 1.2. Tvilight system overview application…………………………………………………… 19
Figure 1.3. Tvilight remote control application CityManager… ………………………………… 19
Figure 1.4. inteliLIGHT system principle of working……………………………………………… 21

Chapter 2
Figure 2. 1. Weather Based Intelligent Street Lightning System ……………………….. 24

Chapter 3
Figure 3.1 – Weather Based Intelligent Street Lightning System ……..………………… 26
Figure 3.2. Transformer ……………………………………………………………… …28
Figure 3.3. Voltage Regulator 7805 ……… ..…………………………………………… 29
Figure 3.4. Resultant waveform output of a rectifier ……… .………………………….. 30
Figure 3.5. Block Diagram of AT89S52 ……………………………………………….. .31
Figure 3.6. Pin Diagram of AT89S52 ……………………………………………………. ..32
Figure 3.7. D1 ESP8266 WiFi BOARD …………………………………… …………… 33
Figure 3.8. IR LED ……………………. ……………………………………………….. 34
Figure 3.9. Photodiode …………………………………………………………… …………………. 35
Figure 3.10. Typical LED ………… ..………………………………………………….. .36
Figure 3.11. Different types of LED’ S…………………… ..…………………………… 37
Figure 3.12. White LED spectrum ……… …..………………………………… .………. 38
Figure 3.13. BC 547 Transistor Pinout …………………………………………………. 41
Figure 3.14. NPN Transistor Configuration ……………………………… …………….. 42
Figure 3.15. 1N4007 Diodes …………… ……………………………………………….. 40
Figure 3.16. PN Junction diode ……………… ………………………………………….. 43
Figure 3.17. Zero Bias connection …… …………………………………………………. 44

11 | P a g e

Figure 3.18. Forward Bias connection ..………………………………………………… 45
Figure 3.19. Reverse Bias connection ..………………………………………………… 46
Figure 3.20. Resistors …… ………………. …………………………………………….. 47
Figure 3.21. Variable Resistors – Potentiometers …… ..……………………………….. 48
Figure 3.22 Electrolytic Capacitors …..………………………………………………… 49

Chapter 4
Figure 4.1. Main Day Forecast ………………………………………… .……………….. 52
Figure 4.2. Daily Forecast …………………………………………… .…………………. 53
Figure 4.3. Wind fluctuations …… .…………………………… ….…………………….. 54
Figure 4.4. ID's for a sky with thunderstorms ………………… …………………… …… 55
Figure 4.5. ID's for a drizzly weather …… …………………… ………………………… 55
Figure 4.6. ID's for a rainy weather ……… ..…………………………………………… 56
Figure 4.7. ID’s for a snowy weather ………………. ………………………………….. 56
Figure 4.8. ID’s for a clear and cloudy weather …………… …………………………… 57

Chapter 5
Figure 5.1 Arduino application start screen …………………………………………………………….. 58
Figure 5.2 The "Open" section ……………………………………………………. ……….5 9
Figure 5.3 Selection of the respective Arduino board …… …………………………… …60
Figure 5.4 Driver update…………. ……………………………………………………… 61
Figure 5.5 Port selection…………. ……………………………………………………… 62
Figure 5.6 Code verifying and uploading ……………………………………………………………….. 62
Figure 5.7 Microcontroller setup ………………………… ……………………………………………… 63
Figure 5.8a SPI Programmer interface ……………………………………………………………………. 64
Figure 5.8b Code uploading …………………………………………………………. …………………. 64
Figure 5.9 WiFi hotspot made with a smartphone ……………………………………………………. 65
Figure 5.10 Board with row of leds ……………………………………………………………………. 66
Figure 5.11 Final assembly of the whole project …………………………………………………….. 67

12 | P a g e

13 | P a g e

List of tables

Chapter 1
Table 1.1 – Street lighting systems overview ………………………………………. 22

Chapter 4
Table 4.1 – Weather forecast websites ……………………………………………… 51

14 | P a g e

15 | P a g e

Introduction

The development of the technological and IT domain has experienced an exponential
growth in the last decades. The fast evolution i n time of things has made the man of today more
and more hasty trying to get to the places where necessary, as needed, as quickly as possible.
With the development of the transport field, the means of transport have become much more
reliable, fast, but als o much more secure. Given that we live in a speed century , safety is
paramount when traveling on either road: highway, European road, bicycle lane etc.
This thesis starts from an existing project, a smart street lighting system, and to improve
this technology.
Since the aforementioned system is not guided by the information of a weather forecast,
information is updated every 5 seconds so that the light is correctly adapted to the current road
conditions.
In this project , the WiFi mod ule D1-ESP8266 is used to connect to an Internet network
(made by a mobile phone through hotspot technology). Also with the Internet connection, the
AT89S52 microcontroller will collect the data required for the location imposed by the user from
https://openweathermap.org website platform, in API format and will transmit the respective data
to a number of LEDs, which will light up in a certain number is either 3, 5, or 6 depending on the
severity of the weather outside.

In the following chapters, the following will be presented:
• Short introduction of large -scale lighting systems, already on the market.
• Comparison between the existing system and the improved one
• Hardware implementation of the system
• Software implementation of the system
• The scientific demonstrator for project
• Conclusions

16 | P a g e

17 | P a g e

Chapter 1. Street Lighting System Overview

The street lamps waste energy due to their long periods of functionality, e.g., automatically
turn ON when it is dark and OFF when becomes bright . Energy waste represents a major concern
that humanity is confronting nowadays. This type of energy can be easily saved by installing a
sensor light and a motion sensor. In this chapter I w ill present a number of existing street light ing
systems that are used nowadays on all over the globe in countries like Taiwan, The Netherlands,
Romania.
• AAEON Street Light Control [1]:
The first presented system is the AAEON Street Light Control. They dev eloped a street
lighting system using existing power lines and wireless data transmission architectures such as
NB-IoT, LoRa, and Zigbee to provide an integrated, diversified framework . Smart systems like
AAEON represents an initiative to establish a solid basis upon which to build scalable and
sustainable programs that can serve as the foundatio n of future smart city systems.
One of the main purpose s is combining Artificial Intelligence (AI) edge and cloud computing
to improve the transmission analysis of data from the entire system.
Figure 1.1 describes the block level diagram of the whole system. Each pole is equipped with
a plug -and-play controller. Controllers and gateways form a mesh network with self -recovery
features. This system is based either on a server or the cloud which supports NB -IoT, LoRa and
Zigbee.
Last but not least they provide a Central Management System(CMS) that helps operators
manage street lighting networks. CMS is able to handle the network formed by street lighting
systems even if are located in different cities.
In my opinion the best feature of this system is the CMS because through this software you
can manage all street lighting network and action from a large distance in order to fix the
problems, a disadvantage would be here the cost and the infrastructure needed to implement it.

18 | P a g e

Figure 1.1 – AAEON System
• Tvilight CitySense [2]:
Already implemented in Port of Moerdijk, in The Netherlands , the XX system is
characterized to be a “ project for rough outdoor environments ”, it is a combination of
sharp sensors within it can detects pedestrians, cyclists, and vehicles, and then fetch the
lamp to a higher brightness le vel.
Already market leaders in smart street lighting systems, Tvilight provide a n easy
maintenance, low costs and best quality system which connects over 360 million
streetl ights worldwide with 24×7 power and maintenance.
Their CMS product “Tvilight City Manager ” software, is designed to manage and
control street lighting in real -time. Also , it provides the right amount of light based on
your lighting infrastructure. It create s information profiles that suit s for dim profiles,
calendar based, light on dema nd and even event based. T he brightness adapts for the
requirements of each particular location.
data is collected through cloud from all gateways and send the information to the
CMS. In addition, the outdoor motion sensors help to connect the streetlight to a feeder
pillar.

19 | P a g e

Their implementation is as follows: when no one around the lights dull down t o
20% of their ability, and return to 100% brightness as soon as human presence is noticed ,
one the other hand at the railroad crossing, the lights are kept at 70% of brightness.

Figure 1. 2 – Tvilight system overview application

20 | P a g e

Figure 1. 3 – Tvilight remote control application CityManager
• inteliLIGHT [3]:
People of the historical city Brasov, Romania have chosen inteliLIGHT street
lighting system which offers a remote guidance solution that ensures that the right
amount of light is provided where and when required. Energy cost in reduced up to 35%
and the o verall operational costs come down by up to 42%.
They guarantee continuous, seamless and autonomous street lighting operation.
Furthermore, if the communication fails for any reason, their controllers still have the
capability to operate the lamps autonom ously. Also malfunctions of this system are
related in real time and automatic processes inform the maintenance teams concerning the
ongoing problems.
In figure 1.4 is described the LoRaWAN system architecture. The LoRaWAN
compatible controllers enable ind ividual remote management of streetlight lamps. It is
more than a basic ON/OFF switching and dimming functions because the controllers can
have autonomous operations based on predefined schedules if light and motion sensors
are provided.
InteliLIGHT also p rovides an autonomous lighting panel which carries out
analysis of different parameters such as voltage, current and frequency. It also reports

21 | P a g e

malfunctions in real time managed by the LoRaWAN Network Server for an optimal and
failsafe operation.
InteliLIG HT CMS allows the remote control of the street lighting system, 24×7
monitoring and maintenance. Compatible LoRaWAN sensors are also integrated in this
application which makes data easier to be analized.

Figure 1. 4 – inteliLIGHT system principle of working

• Advantages [4]:
o Automatic Switching of Street lights
o Maintenance Cost Reduction
o Reduction of light pollution
o Wireless Communication
o Energy Saving
o Reduction of manpower
o 24/7 Instant reports
o 24/7 Control and programming
o Lamp diagnostics and real -time fault detection as well as provision of alarms

22 | P a g e

• Disadvantages:
o Higher initial investment
o Dependency upon the climatic conditions
o Risk of harm
o Hindering energy production from solar panels by accumulating snow, dust,
moisture

System AAEON Tvilight inteliLIGHT
Cost Medium Low Medium
Maintenance High High High
Energy saving Medium High Low
Table 1.1 – Street lighting systems overview

To qualitative assess the performance of each implemented system, in this thesis, we
select several metrics like cost, maintenance, and energy savings/efficiency.
In Table 1.1 we can observe the comparison between street lighting systems presented in
this chapter. As we can see the best system that suits this requirement would be Tvilight,
because, on the one hand its costs are not so expensive than the others and o n the other hand this
system provides the most suitable amount of saved energy.

23 | P a g e

Chapter 2. Weather Based Intelligent Street Lightning
System
None of the systems mentioned in the previous chapter take into consideration the outside
weather conditions. Hence, i n this chapter we will present an enhancement of a general system
presented in the previous chapter that will take into consideration the driver’s comfort and safety.
The proposed system addresses comfort and safety by integr ating weather conditions , like
rainy , sunny, snowy and foggy based light adaptation into decision making of the system light
type/intensity.
All phenomena that a driver will encounter such as rain, snow, fog and so o n. In order to
maintain a calm trip without unpleasant events the streetlights will adapt based on the outside
weather conditions even if are harsh or kind.
To demonstrate the usefulness of taking weather into consideration we plan to compare 2
systems, o ne with weather aware and one with out weather aware decisions.
Weather data contains information about humidity, atmospherically pressure, daily and
weekly forecasts which can be collected from https://openweathe rmap.org/ .
Our goal for this implementation is to propose a number of data collection ways, and these
are in number of 3 :
• Local – the data will be collected from a humidity sensor.
• Weather forecast website.
• Hybrid.
Based on the information collected by one or more ways mentioned above , the system
will make a decision and adapt the street light to road conditions. For example if it is a sunny
day the light intensity can vary 3 by 3 LED’s will turn ON, when passing a vehicle and OFF
when it is not in the action of the respective sensors. If it is a rainy day 5 LED’s will be
turned ON and so on.
In the diagrams below I will present the actual implementation of the project, but also the
improvements brought to it .

24 | P a g e

Block diagram of the weather based street light intelligent system:

Figure 2. 1 – Weather Based Intelligent Street Lightning System
In the figure 2.1 presented above we can observe the block diagram of the proposed
system containing the following components:
• Transformer
• Rectifier
• Voltage regulator
• A row of LED’s emphasizing the street light
• Microcontroller
• IR Receiver
• LED

25 | P a g e

• IR Transmitter
• WiFi mod ule D1-ESP8266
• Humidity sensor
In the following section I want to describe some basic features of the components
mentioned above:
1. A transformer [5][6] is an electrical device which transfers electrical energy from
one electric circuit to another, from a wall plug to the microcontroller, without
changing the frequency . After this, the curren t passes through a rectifier [7], named
by its main function (rectification) and its purpose is to convert the current which
flows in only one direction, from AC (alternating current) to DC (direct current). Last
but not least, current passes through a voltage regulator [8] until it reaches the
microcontroller, its main operation is to automatically maintain a constant voltage
level.
2. The microcontroller is the brain of the entire system, it commands all the actions
that need to be made in the current implementation, its responsibilities are either
turning on and off the LEDs and collecting data through the forecast website.
3. IR Receiver and IR Transmitter are used to control a device wirelessly.
4. The WiFi Module [9] is a self contained SOC (system on a chip) with integrated
TCP(Transfer Control Protocol) /IP(Internet Protocol) protocol stack that can give any
microcontroller access to your WiFi network.
5. Humid ity sensor or rain sensor represents a switching device activated by rainfall.

26 | P a g e

Chapter 3. Hardware implementation
In the following chapter I will talk about the hardware implementation of this project , the
components purpose that was basically explained a chapter before will be much more detailed in
this one.
Figure 3.1 – Weather Based Intelligent Street Lightning System

3.1 TRANSFORMER [5][6]
As already mentioned before , a transformer is an electrical device which transfers electrical
energy from one electric circuit to another, without changing the frequency. The energy transfer
usually takes place with a change of voltage and current with a little loss of power. Step -up
transformers increase voltage, step -down transformers reduce voltage. Most power supplies use a
step-down transformer to reduce the dangerously high voltage to a safer low voltage.

27 | P a g e

Figure 3.2 Transformer

The input coil is called the primary and the output coil is called the secondary . There is
no electrical connection between the two coils; instead they are linked by an alternating magnetic
field created in the soft -iron core of the transformer. The two li nes 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 is stepped down and current is stepped up.
The ratio of the number of tu rns on each coil, called the turn’s ratio , determines the ratio
of the voltages. A step -down transformer has a large number of turns on its primary (input) coil
which is connected to the high voltage mains supply, and a small number of turns on its
seconda ry (output) coil to give a low output voltage.
If the secondary coil is attached to a load that allows current to flow, electrical power is
transmitted from the primary circuit to the secondary circuit.

3.2 VOLTAGE REGULATOR 7805 [8]
Each type employs internal current limiting, thermal shutdown and safe operating area
protection, making it essentially indestructible. If adequate heat sinking is provided, they can
deliver over 1A output Current. Although designed primarily as fixed voltage regula tors, these
devices can be used with external components to obtain adjustable voltages and currents.

28 | P a g e

Figure 3.3 Voltage Regulator 7805

3.3 REC TIFIER [7]
A rectifier is an electrical device that converts alternating current (AC) to direct current
(DC), current that flows in only one direction, a process known as rectification . Rectifiers have
many uses including as components of power supplies and as detectors of radio signals.
The rectifier may be a half wave or a full wave rectifier. In this project, a bridge rectifier
is used because of its merits like good stability and full wave rectification. In positive half cycle
only two diodes (1 set of parallel diodes) wi ll conduct, in negative half cycle remaining two
diodes will conduct and they will conduct only in forward bias only.

3.4 FILTER
Capacitive filter is used in this project in order to remove the ripples from the output of
rectifier and for smoothing the D.C. Output received from this filter which is constant until the
main voltage and load is maintained constant.
The simple capacito r filter is the most basic type of power supply filter. The use of this
filter is very limited. It is sometimes used on extremely high -voltage, low -current power supplies
for cathode -ray and similar electron tubes that require very little load current from the supply.

29 | P a g e

This filter is also used in circuits where the power -supply ripple frequency is not critical and can
be relatively high. Figure 4.3 show s how the capacitor changes and discharges.

Figure 3.4 Resultant waveform output of a rectifier

3.5 MICROCONTROLLER AT89S52 [10][11]
The AT89S52 is a low -power, high -performance CMOS 8 -bit microcontroller with 8K
bytes of in -system programmable Flash memory. The device is manufactured using non volatile
memory technology and is compatible with the industry standard 80C51 instruction set and pin
out. The on -chip flash allows the program memory to be reprogrammed in -system or by a
conventional non volatile memor y programmer.
The Atmel AT89S52 is a powerful microcontroller which provides a highly -flexible and
cost-effective solution to many embedded control applications. This microcontroller is designed
with static logic for operation down to zero frequency and su pports two software selectable
power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters,
serial port, and interrupt system to continue functioning. The Power -down mode saves the RAM

30 | P a g e

contents but freezes the oscillator, disabli ng all other chip functions until the next interrupt or
hardware reset.

Block Diagram of AT89S52 [11]:

Figure 3.5 Block Diagram of AT89S52

31 | P a g e

Pin Configurations of AT89S52

Figure 3.6 Pin Diagram of AT89S52

32 | P a g e

3.6 D1 ESP8266 WiFi B OARD [9]
The WeMos D1 is a ESP8266 WiFi based board that uses the Arduino layout with a
operating voltage of 3.3V. ESP8266 with 32 MiB of built -in flash, allowing for single -chip
devices capable of connecting to Wi -Fi.

Figure 3.7 – D1 ESP8266 WiFi BOARD

The development board also includes a CH340 USB to serial interface giving it the
ability to be connected and programmed directly from your computer and requiring only a
common micro USB cable – no additional interface h ardware or configuring is required. Once
connected to the computer, and drivers have been installed, the ESP8266 -D1 will appear as a
standard serial COM port.
3.7 IR LED [12]
An IR (Infrared) LED, also known as IR transmitter, is a special purpose LED that
transmits infrared rays in the range of 760 nm wavelength. Such LEDs are usually made of

33 | P a g e

gallium arsenide or aluminum gallium arsenide. They, along with IR receivers, are commonly
used as se nsors.
The appearance is same as a common LED. Since the human eye cannot see the infrared
radiations, it is not possible for a person to identify whether the IR LED is working or not, unlike
a common LED. The IR LED can be seen in figure 3.8.

Figure 3.8 IR LED
Features [13][14]:
• Extra high radiant power
• Low forward voltage
• Suitable for high pulse current operation intensity
• High reliability

Chip Materials
• Dice Material : GaA1As/GaAs
• Lens Color : Water Clear

34 | P a g e

3.8 PHOTODIODE [15][16]
A photodiode (figure 3.9) is a device that helps in conversion of light into electric
current. Made of semi -conductor material and containing a P -N junction, it is designed to
function in reverse bias. Current is produced in the photodiode when photons are absorbed and a
small amount of current is also produced when there is no light present. With increase of the
surface area, photodiodes have slower response times. Photodiode technology has been
success fully and widely used due to its simple and low -cost rugged structure .

Figure 3.9 Photodiode

The working principle of a photodiode is [15], when a photon of ample energy strikes the
diode, it makes a couple of an electron -hole. This mechanism is also called as the inner
photoelectric effect. If the absorption arises in the depletion region junction, then the carriers are
removed from the jun ction by the inbuilt electric field of the depletion region. Therefore, holes in
the region move toward the anode, and electrons move toward the cathode, and a photocurrent
will be generated.
The entire current through 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 device.

Photovoltaic mode
When used in zero bias or photovoltaic mode, the flow of photocurrent out of the device
is restricted and a voltage builds u p [16]. The diode becomes forward biased and "dark current"
begins to flow across the junction in the direction opposite to the 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 photodiode.

35 | P a g e

Photoconductive mode
In this mode the diode is often reverse biased, dramatically reducing the response time at
the expense of increased noise. This increases the width of the depletion layer, which decreases
the junction's capacitance resulting in faster response times. The reverse bias induces only a
small amount of current (known as saturation or back current) along its direction while the
photocurrent remains virtually the same.

3.9 LED [17]

LEDs are semiconductor devices [17]. Like transistors, and other diodes, LEDs are made
out of silicon.
When current passes through the LED, it emits photons as a byproduct. Normal light
bulbs produce light by heating a metal filament until it is white hot. LEDs p roduce photons
directly and not via heat, they are far more efficient than incandescent bulbs.

Figure 3.10 Typical LED

Not long ago , LEDs were only bright enough to be used as indicators on dashboards or
electronic equipment. But recent advances have made LEDs bright enough to rival traditional
lighting technologies. Modern LEDs can replace incandescent bulbs in almost any application.
In figure 3.10 is presented a typical LED.

Types of LED s
LEDs are produced in an array of shapes and sizes . The color of the plastic lens is often the
same as the actual color of light emitted, but not always. For instance, purple plastic is often used for
infrared LEDs, and most blue devices have clear housings. There are also LEDs in extremely tiny

36 | P a g e

packages, such as those found on blinkers and on cell phone keypads. The main types of LEDs are
miniature, high power devices and cust om designs such as alphanumeric or multi -color.

Figure 3.11 Different types of LED’S

White LED’S [18]
Light Emitting Diodes have recently become available that are white and bright, so bright
that they seriously compete with incandescent lamps in lighting applications.
Red LEDs are now being used in automotive and truck tail lights and in red traffic sign al
lights. You will be able to detect them because they look like an array of point sources and they
go on and off instantly as compared to conventional incandescent lamps.

37 | P a g e

Figure 3.12 White LED spectrum

LEDs are monochromatic devices. The color is determined by the band gap of the
semiconductor used to make them. Red, green, yellow and blue LEDs are fairly common. White
light contains all colors and cannot be directly created by a single LED. The most common form
of "white" LED really isn't white. It is a Gallium Nitride blue LED coated with a phosphor that,
when excited by the blue LED light, emits a broad range spectrum that in addition to the blue
emission, makes a fairly white light , as you can see in figure 3.12.
There is a claim that these white LED's have a limited life. After 1000 hours or so of
operation, they tend to yellow and dim to some extent. Running the LEDs at more than their
rated curren t will certainly accelerate this process.

38 | P a g e

Advantages of using LEDs

• Efficiency:
LEDs produce more light per watt than incandescent bulbs; this is useful in battery powered
or energy -saving devices.
• Size:
LEDs can be very small (smaller than 2 mm2) and are easily populated onto printed circuit
boards.
• On/Off time:
LEDs light up very quickly. A typical red indicator LED will achieve full brightness in
microseconds. LEDs used in communications devices can have even faster response times.
• Cycling:
LEDs are ideal for use in applications that are subject to frequent on -off cycling, unlike
fluorescent lamps that burn out more quickly when cycled frequently, or HID lamps that require
a long time before restarting.
• Cool light:
In contrast to most light sources, LEDs radiate very little heat in the form of IR that can
cause damage to sensitive objects or fabrics. Wasted energy is dispersed as heat through the base
of the LED.
• Lifetime:
LEDs can have a relatively long useful lif e. One report estimates 35,000 to 50,000 hours of
useful life, though time to complete failure 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 lumen, on an initial capital cost basis, than
most conventional lighting technologies.

39 | P a g e

• Temperature dependence:
LED performance largely depends on the ambient temperature of the operating environment.
Over -driving the LED in high ambient temperatures may result in overheating of the LED
package, eventually leading to device failure.
• Voltage sensitivity:
LEDs must be supplied with the voltage above the threshold and a current below the rating.
This can involve series resistors or cu rrent -regulated power supplies.
• Blue Hazard:
There is increasing concern that blue LEDs and cool -white LEDs are now capable of
exceeding safe limits of the so -called blue -light hazard as defined in eye safety.

40 | P a g e

3.10 BC547 Transistor [19]
Presented in the figure 3.13, BC547 is an NPN Bipolar Junction Transistor [19]. Similar
to the other transistors BC547 is also used for the amplification of current. The smaller amount
of current at the base is used to control the larger amount of currents at collector and emitter as
well. Its basic applications are switching and amplification BC847/BC547 series 45 V, 100 mA
NPN general -purpose transistors.

Figure 3.13 BC 547 Transistor Pinout

41 | P a g e

An NPN Transistor Configuration

Figure 3.14 NPN Transistor Configuration
Figure 3.14 shows the working principle of a NPN transistor, the way how the current
flows and the basic configuration.

3.11 1N4007 D IODE [20][21]
A diode is a semiconductor device that essentially acts as a one -way switch for current
[20]. It allows current to flow easily in one direction, but severely restricts current from flowing
in the opposite direction, also diodes are used to convert AC into DC these are used as half wave
rectifier or full wave rectifier. Three points must he kept in mind while using any type of diode.
1.Maximum forward current capacity
2.Maximum reverse voltage capacity
3.Maximum forward voltage capacity

42 | P a g e

Figure 3.15 1N4007 diodes

IN4007 has maximum reverse bias voltage capacity of 50V and maximum forward current
capacity of 1 Amp.

Figure 3.16 PN Junction diode
PN JUNCTION OPERATION [21]
There are two operating regions: P -type and N -type. And based on the applied voltage, there
are three possible “biasing” conditions for the P -N Junction Diode, which are as follows:
1) Zero Bias – No external voltage is applied to the PN junction diode.
When a diode is connected in a Zero Bias condition, no external potential energy is applied
to the PN junction. However , if the diodes terminals are shorted together, a few holes (majority
carriers) in the P -type material with enough energy to overcome the potential barrier will move
across the junction against this barrier pote ntial. 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. This 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 shown below.

43 | P a g e

Figure 3.17 Zero Bias connection
2) Forward Bias – The voltage potential is connected positively to the P -type
terminal and negatively to the N -type terminal of the Diode.
When a diode is connected in a Forward Bias condition, a negative voltage is applied to
the N -type material and a positive voltage is applied to the P -type material. If t his external
voltage becomes greater than the value of the potential barrier, approx. 0.7 volts for silicon and
0.3 volts for germanium, the potential barriers opposition will be overcome and current will start
to flow.
This is because the negative voltage pushes or repels electrons towards the junction
giving them the energy to cross over and combine with the holes being pushed in the opposite
direction towards the junction by the positive voltage. This results in a characteristics curve of
zero current fl owing up to this voltage point, called the “knee” on the static curves and then a
high current flow through the diode with little increase in the external voltage as shown below , in
the figure 3.17.

44 | P a g e

Figure 3.18 Forward Bias connection
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 app lied to the P -type material.
The positive voltage applied to the N -type material attracts electrons towards the positive
electrode and away from the junction, while the holes in the P -type end are also attracted away
from the junction towards the negative electrode.
The net result is that the depletion layer grows wider due to a lack of electrons and holes
and presents a high impedance path, almost an insulator. The result is that a high potential barrier
is created thus preventing current from flowing thro ugh the semiconductor material.

45 | P a g e

Figure 3.19 Reverse Bias connection
3.12 RESISTORS [22][23]
A resistor [22] is a two -terminal electronic component designed to oppose an electric
current by producing a voltage drop between its terminals in proportion to the current, that is, in
accordance with Ohm's law:

V = IR

Resistors [23] are used as part of electrical networks and electronic circuits. They are
extremely commonplace in most electronic equ ipment. Practical resistors can be made of various
compounds and films, as well as resistance wire (wire made of a high -resistivity alloy, such as
nickel/chrome).
The primary characteristics of resistors are their resistance and the power they can
dissipa te. Other characteristics include temperature coefficient, noise, and inductance. Less well –
known is critical resistance, the value below which power dissipation limits the maximum
permitted current flow, and above which the limit is applied voltage. Criti cal resistance depends
upon the materials constituting the resistor as well as its physical dimensions; it's determined by
design.

46 | P a g e

Resistors can be integrated into hybrid and printed circuits, as well as integrated
circuits. Size, and position of leads (o r terminals) are relevant to equipment designers; resistors
must be physically large enough not to overheat when dissipating their power.

Figure 3.20 Resistors

VARIABLE RESISTORS [24]
Potentiometer
A potentiometer is a manually adjustable resistor . The way this device works is relatively simple.
One terminal of the potentiometer is connected to a power source. Another is hooked up to ground (a
point with no voltage or resistance and which se rves as a neutral reference point), while the third
terminal runs across a strip of resistive material. This resistive strip generally has a low resistance at
one end; its resistance gradually increases to a maximum resistance at the other end. The third t erminal
serves as the connection between the power source and ground, and is usually interfaced to the user by
means of a knob or lever. The user can adjust the position of the third terminal along the resistive strip
in order to manually increase or decre ase resistance. By controlling resistance, a potentiometer 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.
The power of this simple device is not to be underestimated. In most analog devices, a
potentiometer is what establishes the levels of output. In a loud speaker, for example, a potentiometer
directly adjusts volume; in a television monitor, it controls brightness.

47 | P a g e

Figure 3.21 Variable Resistors – Potentiometers

A potentiometer can also be used to control the potential difference, or voltage, across a circuit.
The setup involved in utilizing a potentiometer for this purpose is a little bit more complicated. It
involves two circuits: the first circuit consists 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 potentiometer in this arrangement drops the voltage by an amount equal to the
ratio between the resistance allowed by the position of the third terminal and the highest possible
resistivity of the strip. In other words, if the knob controlling the resistance is positio ned at the exact
halfway point on the resistive strip, then the output voltage will drop by exactly fifty percent, no
matter how high the potentiometer's input voltage. Unlike with current regulation, voltage regulation is
not limited by the maximum resist ivity of the strip

3.13 CAPACITORS [25][26]

A capacitor or condenser [25] is a passive electronic component consisting of a pair of
conductors separated by a dielectric. When a voltage potential difference exists between the
conductors, an electric field is present in the dielectric. This field stores energy and produces a
mechanical force between the plates. The effect is greatest between wide, flat, parallel, narrowly
separated conductors.
An ideal capacitor [26] is characterized by a sin gle constant value, capacitance, which
is measured in farads. This is the ratio of the electric charge on each conductor to the potential

48 | P a g e

difference between them. In practice, the dielectric between the plates passes a small amount of
leakage current. The conductors and leads introduce 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, power dissipation and operating frequency in a digital logic circuit, energy
capacity in a high -power system, and many other important aspects.

Figure 3.22 Electrolytic Capacitors

49 | P a g e

Chapter 4. Weather forecast data collection

4.1 API (Application Programming Interface ) [27] :
An application programming interface (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 , those delivered over Hyper Text Transfer
Protocol (HTTP). Weather APIs allow you to connect to large databases of weather forecast .

• OpenWeatherMap [28][29]
This website provides current data about wea ther, forecasts, weather alerts, historical air
pollution. It can present a three -hour forecast which is available for up to 5 days and daily
forecasts which are available for up to 16 days.

• Weatherbit [30]
Weatherbit provides only basic access to weather API with only latitude and longitude
coordinates helping us to get the weather forecast.

• AccuWeather [31]
It is the biggest website and also has the largest database on the market, it delivers
current, his torical and forecasted weather for all locations over the world. It can even provide
flight delays, mosquito activity, stargazing, and dozens of other daily index values for a
specific location . It is the best app for weather conditions, images, cyclones & more.

• Weather2020 [32]
It is one of the best weather forecast website, it can provide forecasts up to 12 weeks by
Zip Code or City. Its best application is long range forecast, used people who are very far
from the desired location.

50 | P a g e

API Forecast Data Current/Real -Time
Weather Pricing
OpenWeatherMap Very good Very good Free
Weatherbit Good Good From $10.00 to
$25.00 per month
AccuWeather Very good Very good From $25.00 to
$500.00 per month
Weather2020 Sufficient Bad From $10.00 to
$40.00 per month
Table 4.1 – Weather forecast websites
Even though all the applications mentioned above provide accurate weather data, the best
choice for my project is OpenWeatherMap website , because the supply and demand parameters
are very good, as shown in table 4.1. The data for the weather forecast will be collected through
WiFi Module – ESP8266 and from https://openweathermap.org/ , also the lights will be adapted
based on data collected from the website, which has a periodic refresh rate.
The refresh of data is shown by the blinking LED on the main board .
The fresh data for adapting the lights are collected by means of some general parameters,
based on location, temperature, weather and so on and so forth. The most i mportant parameters
for this projected are presented below: [5]

• weather [27]
o weather.id – Weather condition id
o weather.main – Group of weather parameters (Rain, Snow, Extreme etc.)
o weather.description – Weather condition within the group
• main
o main.temp – Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial:
Fahrenheit.
o main.humidity – Humidity, %
o wind.speed – Wind speed. Unit Default: meter/sec, Metric: meter/sec,
Imperial: miles/hour.

51 | P a g e

• clouds
o clouds.all – Cloudiness , %
• rain
o rain.1h – Rain volume for the last 1 hour, mm
• snow
o snow.1h – Snow volume for the last 1 hour, mm
• id – City ID
• name – City name

We can call by city name or city name and country code. API responds with a list of
results that match a searching word. We will receive a central district of the city with its own
parameters (geographic coordinates/id/name) in API response.
The chosen city for the implementation made in this project is Bucharest, RO. We can
choose the way we visualize the data, such as:

• Main data forecast seen in figure 4.1

Figure 4.1 Main Day Forecast

52 | P a g e

• Daily

Figure 4.2 Daily Forecast
Figure 4.2 shows the temperature fluctuations and the atmospherically pressure during a
certain period of time.
OpenWeatherMa p also provides access to a daily basis chart from which we can observe
the wind fluctuations from the days before , as shown in figure 4.3.

53 | P a g e

Figure 4.3 – Wind fluctuations

4.2 JSON (JavaScript Object Notation ) [33]:
JSON is a lightweight format for storing and transporting data and stands
for JavaScript Object Notation , it is often used when data is sent from a server to a web page and
also “ self-describing" and easy to understand .
The number of LEDs lit will be based on the IDs , based on every profile a certain number
of LEDs will be turned ON in order to provide the correct amount of light and to have trip
without unpleasant events.

54 | P a g e

• Thunderstorm

Figure 4.4 – ID's for a sky with thunderstorms

• Drizzle

Figure 4.5 – ID's for a drizz ly weather

55 | P a g e

• Rain

Figure 4.6 – ID’s for a rainy weather
• Snow

Figure 4.7 – ID’s for a snowy weather

56 | P a g e

• Clear and cloudy

Figure 4.8 – ID's for a clear or a cloudy weather
OpenWeatherMap website will provide the list of ID’s corresponding to a certain event
and the AT89S52 microcontroller will make decision whether it will turn ON 3, 4 or 5 LEDs.
The group ID’s for the events mentioned above are represented in figure 4.4, if we have a
thunderstorm on the sky, figure 4.5 if it is a drizzly weather, figure 4.6 if we will confront with a
rainy day, figure 4.7, which fits best for winter, because it sh ows the group ID for a snowy
weather. Last but not least the IDs for a clear or cloudy weather are represented in figure 4.8.

57 | P a g e

Chapter 5. Demonstrator of the project

In the last chapter of this thesis I will present the functionality of the project that I already
implemented. In the first part is described the WiFi module configuration, in the second and third
part is described how the code is uploaded to the microcontroller and how the project is working.

• WiFi module configuration

In the pictures below I will explain step by step how exactly this configuration will take
part.

Figure 5.1 – Arduino application start screen

In figure 5.1 is shown the first window when we open the Arduino app. We will select
the “File” tab and after will select the “Open” section.

58 | P a g e

Figure 5.2 – The "Open" section

In the figure 5.2, we can see a pop -up screen where we need to select the respective file
for our purpose, in this case it will be “ esp8266.ino ”.

59 | P a g e

Figure 5.3 – Selection of the respective Arduino board

In 5.3 section we will select the “WeMos D1 R1” board and also make sure that we
install the correct software version for our WiFi module.

60 | P a g e

Figure 5.4 – Driver update

In the above figure ( Figure 5 .4) we must select the right driver version for our board, in
this case it will be 2.4.1 and we will click “Update”. Once this action is finished we will select
the right COM port where our D1 R1 is connected, as shown in figure 5.5. Last but not least the
code is verified and uploaded to our WiFi module ( Figure 5.6).

61 | P a g e

Figure 5.5 – Port selection

Figure 5.6 – Code verifying and uploading

62 | P a g e

As I mentioned at the beginning of this chapter, in the section below it is described how
exactly the C code is uploaded on the microcontroller . We will use an additional board and an
ARDUINO UNO boa rd in order to fulfill this task.
• Microcontroller programming

Figure 5.7 – Microcontroller setup

In figure 5.7 is shown a setup necessary to be done in order to upload the “.hex” code
on the microcontroller, through a serial connection. After the setup is made we need to open
the “8051 SPI Programmer” as shown in figure 5.8a and 5.8b. In this section the code found in
“.hex” format is uploaded on the microcontroller. We will click the “ Open ” section and select
the right code for our purp ose.

63 | P a g e

Figure 5.8a – SPI Programmer interface

Figure 5.8b – Code uploading

64 | P a g e

• Final assembly

In the last section of this chapter I presented, how the D1R1 WiFi module is connected to the
internet via a Samsung smartphone and how the final result of this project looks like.
As you can see in figure 5.9 the WiFi board is connected through internet immediately as
it detects the name and the password of the network which is configured in the “ esp8266.ino ”
file, presented above. Later on, in figure 5.10 we can see the board with the row of leds, serving
as a row of light pillars, the one marked with an “X” next to it is only blinking from 5 to 5
seconds showing that fresh data are collecting in this tiny interval. Last but not least the 5.11
figure presen ts the whole system connected with the D1R1 WiFi module and the Raindrops
sensor.

Figure 5.9 – WiFi hotspot made with a smartphone

65 | P a g e

Figure 5.10 – Board with row of leds

66 | P a g e

Figure 5.11 – Final assembly of the whole project

67 | P a g e

Conclusions

In conclusion, optimizing consumption can accomplish several things. The simplest way
is to use LEDs instead of classical light bulbs, because LEDs can last much more such as 25,000
hours instead of classical light bulbs which last around 8,000 hours. Firs tly we can reduce the
power consumption by programming them when to turn on and off. Secondly it depends on the
weather conditions, if there are harsh conditions LEDs are a must, because their consumption is
around 7W instead of 60W, data held by the norma l light bulb .
Through these aspects, the costs of energy as well as of maintenance decrease
significantly.

68 | P a g e

References

[1] https://www.aaeon.com/en/ac/intelligent -street -lighting
[2] https://www.tvilight. com/wp -content/uploads/2017/10/Case -study -Moerdijk -V1.1 –
English.pdf
[3] https://intelilight.eu/intelligent -street -lighting -contr ol/#system_benefits
[4] http://www.wi4b.it/outdoor_smart_lighting.php
[5] https://www.electronics -tutorials.ws/transformer/transformer -basics.html
[6] https://www.elprocus.com/working -procedure -on-how-do-transformers -work/
[7] https://www.physics -and-radio -electronics.com/electronic -devices -and-
circuits/rectifier/rectifier -whatisrectifier.html
[8] https://electronicsforu.com/resources/learn -electronics/7805 -ic-voltage -regulator
[9] https://en.wikiped ia.org/wiki/ESP8266
[10] http://elprojects.blogspot.com/2010/06/microcontroller -at89s52 -description.html
[11] http://ww1.microchip.com/downloads/en/DeviceDoc/doc1919.pdf
[12] https://whatis.techtarget.com/definition/IR -LED -infrared -light-emitting -diode
[13] https://electronicsforu.com/resources/learn -electronics/ir -led-infrared -sensor -basics
[14] https://components101.com/ir -led-pinout -datasheet
[15] https://www.elprocus.com/photodiode -working -principle -applications/
[16] https://www.sciencedirect.com/topics/engineering/photodiode
[17] https://www.ledsmagazine.com/leds -ssl-design/materials/article/16701292/what -is-
an-led
[18] https://www.lrc.rpi.edu/programs/nlpip/lightinganswers/led/whiteLi ght.asp
[19] https://www.theengineeringprojects.com/2017/06/introduction -to-bc547.html
[20]https://sciencing.com/1n4007 -diode -specs -7448252.html

69 | P a g e

[21]https://www.theengineeringprojects.com/ 2017/07/introduction -to-1n4007.html
[22] https://www.techopedia.com/definition/683/resistor
[23] https://en.wikipedia.org/wiki/Resisto r
[24] https://www.electronics -notes.com/articles/electronic_components/resistors/resistor –
types.php
[25] https://en.wikipedia.org/wiki/Capacitor
[26] https://howtomechatronics.com/how -it-works/electronics/what -is-capacitor -and-
how-it-work s/
[27] https://www.quora.com/What -is-an-API-request
[28] https://openweathermap.org/weather -conditions
[29] https://openweathermap.org
[30] https://www.weatherbit.io/features
[31] https://corporate.accuweather.com/about
[32] https://rapidapi.com/blog/access -global -weather -data-with-these -weather -apis/
[33] https://www.w3schools.com/js/js_json_intro.asp

70 | P a g e

Annexes

Annex A. Arduino code for D1 ESP8266
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>

// wifi network data
const char* wifiName = "mihnea -wifi";
const char* wifiPass = "12345678";

//Web Server address to read/write from
const char* host =
"http://api.openweathermap.org/data/2.5/weather?q=Bucharest,ro&APPID=46b62da7ede47d a2c
d3e92cc7c138e55";

void setup() {

Serial.begin(9600);
WiFi.begin(wifiName, wifiPass);

while (WiFi.status() != WL_CONNECTED) {
delay(500); /* keep trying to connect to wifi */

71 | P a g e

}

}

void loop() { // loop se executa la infinit
HTTPCli ent http; //Declare 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 from server
int condition_id;

if(httpCode == 200) // cod 200 = am primit json, e ok
{
// Allocate JsonBuffer
// Use arduinojson.org/assistant to compute the capacity.
const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;
Dynam icJsonBuffer jsonBuffer(capacity);

// Parse JSON object
JsonObject& root = jsonBuffer.parseObject(payload);
condition_id = root["weather"][0]["id"].as<int>();
Serial.println( condition_id % 100 );

72 | P a g e

/*
* weather codes end with their sever ity index. so you use last digit ( number mod 100);
* so that 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 connection

delay(5000); //GET Data at every 5 seconds
}

73 | P a g e

Annex B . 8051 Arduino programmer
#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 */

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

74 | P a g e

pinMode(RST, OUTPUT);
Serial.begin(115200); // depends on the setting of the host PC

}

void loop()
{
while (!Serial.available()); // wait for character
if (Serial.available() > 0)
switch (Serial.read())
{
case 'p': Serial.write(progEnable());
break;
case 'r': readProgmem();
Serial.write(data);
break;
case 'a': while(!Serial.available());
AL = Serial.read();
break;
case 'A': while(!Serial.available());
AH = Serial.read();
break;

75 | P a g e

case 'd': while(!Serial.available());
data = Serial.read();
break;
case 'S': AH = 0;
AL = 0;
SigH = readSign();
Serial.write(SigH);
break;
case 's': AH = 2;
AL = 0;
SigL = readSign();
Seria l.write(SigL);
AH = 1;
AL = 0;
SigL = readSign();
Serial.write(SigL);
break; // read SigL
case 'o': digitalWrite(RST,1);break;
case 'c': digitalWrite(RST,0);break;
case 'e': eraseChip();
Serial.write(RDY);
break;

76 | P a g e

case 'j': break;
case 'w': writeProgmem();
break;
}

}

unsigned char SendSPI(unsigned char data)
{
uint8_t retval = 0;
uint8_t intData = data;
int t;

for (int ctr = 0; ctr < 7; ctr++)
{
if (intData & 0x80) digitalWrite(_MOSI,1);
else digi talWrite(_MOSI,0);

digitalWrite(_CLK,1);

77 | P a g e

delayMicroseconds(1);

t = digitalRead(_MISO);
digitalWrite(_CLK,0);

if (t) retval |= 1; else retval &= 0xFE;
retval<<=1;
intData<<= 1;
delayMicroseconds(1);
}

if (intData & 0x80) digitalWrite(_MOSI,1);
else digitalWrite(_MOSI,0);

digitalWrite(_CLK,1);
delayMicroseconds(1);

t = digitalRead(_MISO);
digitalWrite(_CLK,0);

if (t) retval |= 1;

78 | P a g e

else retval &= 0xFE;

return retval;
}

byte progEnable()
{
SendSPI(0xAC);
SendSPI(0x53);
SendSPI(dummyData);

return SendSPI(dummyData);
}

void eraseChip()
{
SendSPI(0xAC);
SendSPI(0x9F);
SendSPI(dummyData);
SendSPI(dummyData);

79 | P a g e

delay(520);
}

void readProgmem()
{

SendSPI(0x20);
SendSPI(AH);
SendSPI(AL);
data = SendSPI(dummyData);
}

void writeProgmem()
{
SendSPI(0x40);
SendSP I(AH);
SendSPI(AL);
SendSPI(data);
}

void writeLockBits()
{

80 | P a g e

SendSPI(0xAC);
SendSPI(lockByte);
SendSPI(dummyData);
SendSPI(dummyData);
}

void readLockBits()
{
SendSPI(0x24);
SendSPI(dummyData);
SendSPI(dummyData);
lockByte = SendSPI(dummyData);
}

byte readSign()
{
SendSPI(0x28);
SendSPI(AH);
SendSPI(AL);
return SendSPI(dummyData);
}

81 | P a g e

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;
sbit out9=P2^2;
sbit out10=P2^3;

82 | P a g e

sbit out11=P2^4;
sbit out12=P2^5;
sbit out13=P2^6;
sbit out14=P2^7;

sbit switch1=P1^0;
unsigned char bonus=0;
unsigned char i;

void initialize() // Initialize Timer 1 for serial communication

{
EA =1;
ES =1;

TMOD=0x20; //Timer1, mode 2, baud rate 9600 bps

TH1=0XFD; //Baud rate 9600 bps

SCON=0x50;

TR1=1; //Start timer 1

83 | P a g e

}

void receive() //Function to receive serial data

{

bonus=SBUF; //ia ce e in buffer si pune in bonus

}

void Delay(void) //astepata, ca nu face nimic 10000 cicluri
{
int j;
int i;
for(j=0;j<10000;j++)
{
}
}

void UART_Interrupt() interrupt 4 {
if (RI == 1) {

84 | P a g e

receive();
RI=0; // sterge flagul de intrerupere
}
if (TI == 1) {
TI = 0;
}
}

void main()
{

P0= 0xFF;
P2= 0xFF;
P3= 0xFF;
initialize();
while(1)
{
if(S1==1)
{
P2 =0xFF; // le pui pe toate pe 1 ca sa se stinga toate ledurile
P3 =0xFF;

85 | P a g e

if( bonus==0) {out1=0;out2=0; out3=0;} //aprinde 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;}
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();

86 | P a g e

}

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;out4=0; out5=0; out6=0; out7=0;}
if( bonus>=3) {out3=0;out4=0; out5=0; out6=0; out7=0;
out8=0;}

Delay();
}

if(S4==1)
{
P2 =0xFF;
P3 =0xFF;

if( bonus==0) {out4=0;out5=0; out6=0;}

87 | P a g e

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) {out5=0;out6=0; out7=0; out8=0;}
if( bonus==2) {out5=0;out6=0; out7=0; out8=0; out9=0;}
if( bonus>=3) {out5=0;out6=0; out7=0; out8=0; out9=0;
out10=0;}

Delay();
}

if(S6==1)

88 | P a g e

{
P2 =0xFF;
P3 =0xFF;

if( bonus==0) {out6=0;out7=0; out8=0;}
if( bonus==1) {out6=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)
{
P2 =0xFF;
P3 =0xFF;

if( bonus==0) {out7=0;out8=0; out9=0;}
if( bonus==1) {out7=0;out8=0; out 9=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;}

89 | P a g e

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

Delay();
}
}

}

Similar Posts