Embedded Systems Report Lab 4

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

Embedded Systems Report Lab 4

Made by: Essoufia EL JERARI Grp A1


Supervisored by: Adnane ADDAIM

1
Table of Contents
INTRODUCTION.........................................................................................................................................................3
PART THAT WE WILL NEED..................................................................................................................................3
BREADBOARD LAYOUT..........................................................................................................................................4
ARDUINO SKETCH....................................................................................................................................................4
CODE EXPLANATION..............................................................................................................................................4
LED BRIGHTNESS CONTROL USING PROTEUS 8...........................................................................................5
PULSE WIDTH MODULATION CONCEPT..........................................................................................................5
THE THEORY BEHIND THE POTENTIOMETER...............................................................................................6

2
Introduction
In this lab, we will make a LED dimmer by using a potentiometer to control the brightness
of the LED. The potentiometer is like a button that sends an analog signal to the Arduino
Board. We will use PWM to manipulate the signal from the Arduino Board to the LED.

Part that we will need

Arduino Uno Rev3 ×1

Dupont Wires ×1

10K Potentiometer ×1

220 ohm resistor ×1

Blue LED ×1

3
BreadBoard Layout

Arduino sketch

// code for controlling the brightness of LED by a Potentiometer


int AnalogInputPin = A0 ; // analog pin from the potentiometer
int LED = 3; // pin that is connected to the LED
int var;
float Y;

void setup() {
pinMode(LED, OUTPUT);
pinMode(AnalogInputPin,INPUT);
Serial.begin(9600);
}
void loop () {
// reading the value of the potentiometer
potValue = analogRead(AnalogInputPin);
// send a value to control brightness LED
// we need to convert the value of 0 - 1023 to 0 - 255
var=AnalogRead(AnalogInputPin);
Y=(255./1023.)*var;
Serial.println(Y);
analogWrite(LED, Y);
delay(10); // delay for 10 ms
}

Code Explanation

After you wired everything correctly we can begin with the coding part. First, we will declare
our variables.

4
The next step is to set the led as an output pin in the void setup() part of our sketch.
Now we are ready to code the loop. We assigned a variable for the readings of the
Potentiometer. To be able to read the value of the potentiometer we need to read the analog pin.

The analogRead() command converts the input voltage range, 0 to 1023, to 0 to 5 voltage. After
the reading is successful we are able to control the brightness of the LED depending on the value
that is read. An interesting part of this sketch is the way we convert the reading to a digital
number for controlling the LED.

First, we need to consider that PWM uses a range of values between 0 and 255 while
analogRead() returns a value between 0 and 1023.

To send the reading of the potentiometer to the LED, we are using the analogWrite() command.

LED brightness control using Proteus 8

This is the result as we


turn the wiper of the
potentiometer. The more
we click to + button, the
more the brightness
increase.

Pulse width modulation concept

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,

5
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.

In the graphic below, the green lines represent a regular time period. This duration or period is
the inverse of the PWM frequency. In other words, with Arduino’s PWM frequency at about
500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale
of 0 – 255, such that analogWrite(255) requests a 100% duty cycle (always on), and
analogWrite(127) is a 50% duty cycle (on half the time) for example:

The theory behind the potentiometer


A potentiometer is a passive electronic component. Potentiometers work by varying the
position of a sliding contact across a uniform resistance. In a potentiometer, the entire
input voltage is applied across the whole length of the resistor, and the output voltage
is the voltage drop between the fixed and sliding contact as shown
below.
potentiometer has the two terminals of the input source fixed to the end
of the resistor. To adjust the output voltage the sliding contact gets
moved along the resistor on the output side
The rotary type potentiometers are used mainly for obtaining adjustable
supply voltage to a part of electronic circuits and electrical circuits. The

6
volume controller of a radio transistor is a popular example of a rotary potentiometer
where the rotary knob of the potentiometer controls the supply to the amplifier.

You might also like