CNT 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Control System Engineering

Laboratory

Controlling the Brightness of LEDs Using


Pulse Width Modulation with Arduino

Controlling the Brightness of LEDs Using Pulse Width


Modulation with Arduino
Introduction
we will show how to gradually change the luminance of an LED through
programming. Since the pulsing light looks like breathing, we give it a magical
name – breathing LED. We’ll accomplish this effect with pulse width modulation
(PWM).

PWM
Pulse Width Modulation, or PWM, is a technique for getting analog results with
digital means. Digital control is used to create a square wave, a signal switched
between on and off. This on-off pattern can simulate voltages in between full on
(5 Volts) and off (0 Volts) by changing the portion of the time the signal spends
on versus the time that the signal spends off. The duration of “on time” is called
the pulse width. To get varying analog values, you change, or modulate, that
pulse width.
To get varying analog values, you change, or modulate, that pulse width. If you
repeat this on-off pattern fast enough with an LED for example, the result is as if
the signal is a steady voltage between 0 and 5V controlling the brightness of the
LED. (See the PWM description on the official website of Arduino).
We can see from the top oscillogram that the amplitude of the DC voltage output
is 5V. However, the actual voltage output is only 3.75V through PWM because
the high level only takes up 75% of the total voltage within a period.
Here is an introduction to the three basic parameters of PWM

1. uty cycle describes the proportion of “on” time


to the regular interval or period of time.
2. Period describes the reciprocal of pulses in one
second.
3. The voltage amplitude here is 0V–5V.
light-emitting diode (LED) is a semiconductor device
that emits light when an electric current is passed
through it. Light is produced when the particles that carry
the current (known as electrons and holes) combine
together within the semiconductor material.

Since light is generated within the solid semiconductor


material, LEDs are described as solid-state devices. The
term solid-state lighting, which also encompasses organic
LEDs (OLEDs), distinguishes this lighting technology from
other sources that use heated filaments (incandescent
and tungsten halogen lamps) or gas discharge
(fluorescent lamps).

Different colors
Inside the semiconductor material of the LED, the
electrons and holes are contained within energy
bands. The separation of the bands (i.e. the bandgap)
determines the energy of the photons (light particles)
that are emitted by the LED.

LEDs are comprised of compound semiconductor materials, which are made up


of elements from group III and group V of the periodic table (these are known as
III-V materials). Examples of III-V materials commonly used to make LEDs are
gallium arsenide (GaAs) and gallium phosphide (GaP).
Until the mid-90s LEDs had a limited range of colors, and in particular
commercial blue and white LEDs did not exist. The development of LEDs based
on the gallium nitride (GaN) material system completed the palette of colors and
opened up many new applications.
Main LED materials
The main semiconductor materials used to manufacture LEDs are:
 Indium gallium nitride (InGaN): blue, green and ultraviolet high-
brightness LEDs
 Aluminum gallium indium phosphide (AlGaInP): yellow, orange and red
high-brightness LEDs
 Aluminum gallium arsenide (AlGaAs): red and infrared LEDs
 Gallium phosphide (GaP): yellow and green LEDs
Connection
Hardware Required
 Arduino board
 LED
 220 ohm resistor
 hook-up wires
 breadboard
Circuit
Connect the anode (the longer, positive leg) of your LED to digital output pin 9
on your board through a 220 ohm resistor. Connect the cathode (the shorter,
negative leg) directly to ground.

Notice:
You cannot directly connect an LED to a battery or voltage source. Firstly,
because the LED has a positive and a negative lead and will not light if they are
the wrong way around and secondly, an LED must be used with a resistor to
limit or ‘choke’ the amount of current flowing through the LED – otherwise the
LED could burn out!
Upload Sketch
Connect the OSOYOO Basic Board to your computer using the USB cable. The
green power LED (labelled PWR) should go on.Open the Arduino IDE and
select corresponding board type and port type for your OSOYOO Basic Board

Now load the ‘PWM_Control_LED’ example sketch or copy below code to your
new Arduino IDE window and upload it to your OSOYOO Basic Board. Wait a
few seconds you should see the RX and TX lads on the board flashing If the
upload is successful the message Done uploading will appear in the status bar.
void setup ()
{
pinMode(3,OUTPUT);// declare pin 3 to be an
output
}

void loop()
{
for (int a=0; a<=255;a++) //loop from 0 to
255,it controls the increase in PWM brightness
{
analogWrite(3,a); //set the
brightness of pin 3:
delay(8); //wait for 8 ms
}
for (int a=255; a>=0;a--) //loop from 255
down to 0,it control PWM brightness reduction
{
analogWrite(3,a); // set the
brightness of pin 3:
delay(8); //wait for 8 ms
}
delay(800); //wait for 800 ms
}

Questions
1) What is the range of PWM’s duty cycle in Arduino Uno?
In the simplest PWM mode, the timer repeatedly counts from 0 to 255. The
output turns on when the timer is at 0, and turns off when the timer matches the
output compare register. The higher the value in the output compare register, the
higher

2) What is the resolution of PWM’s duty cycle in Arduino Uno?


Arduino has implicitly set all of its PWM channels to 8-bit resolution but it's not
adequate especially when regulating the brightness of some light emitters

3) How to change duty cycle of PWM signal?


To change the duty-cycle to 0, you set the count-control register (CCR ) value
to the max value of the timer period (e.g. the rollover value)
For you, you seem to have a timer period of pwmPeriod = 3000; so to set a 90%
PWM, you would need to set CCR = 300 so the PWM power is on for 90% of
the 3000 tick period.

4) What are the applications and uses of PWM in Arduino based systems?
Pulse width modulation or PWM is a commonly used control technique that
generates analog signals from digital devices such as microcontrollers. The
signal thus produced will have a train of pulses, and these pulses will be in the
form of square waves. Thus, at any given time, the wave will either be high or
low
5) Which function is used for PWM in Arduino?
provides a simple interface to the hardware PWM, but doesn't provide any
control over frequency. (Note that despite the function name, the output is a
digital signal

6) Is the frequency of PWM signal changed when we change the duty cycle?
The average voltage of the PWM signal is determined by its duty-cycle, so
changing the frequency with the same duty-cycle should cause no appreciable
change in the solenoid operation

You might also like