0% found this document useful (0 votes)
9 views10 pages

Labsheet 3 IOT

The document describes experiments to control LED brightness using potentiometers and pulse width modulation. Potentiometers are used as inputs to control PWM outputs and vary the brightness of LEDs. Experiments include controlling a single LED, two LEDs with two pots, and three LEDs with three pots.

Uploaded by

pranav2131
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Labsheet 3 IOT

The document describes experiments to control LED brightness using potentiometers and pulse width modulation. Potentiometers are used as inputs to control PWM outputs and vary the brightness of LEDs. Experiments include controlling a single LED, two LEDs with two pots, and three LEDs with three pots.

Uploaded by

pranav2131
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Amrita Vishwa Vidyapeetham, Amritapuri Campus

Department of Electronics and Communication Engineering


23ECE184-Introduction to Internet of Things
LABSHEET-3
Interfacing Potentiometer and Pulse width Modulation(PWM)

Objective: To control the brightness of LEDs using potentiometer with PWM control

List of Experiments:
1. To get analog reading from the serial monitor using potentiometer
2. To control the brightness of an LED using potentiometer
3. To control RGB LED using three potentiometers

Introduction:
1. Potentiometer:
Potentiometer is a commonly used electrical circuit that is used to manually change
oscilloscope zoom levels, brightness, volume, and other parameters. A potentiometer, often
referred to as a “pot”, is a type of variable resistor that can be used to control the flow of
electric current in a circuit. It consists of 3 terminals, two of which are connected to the ends
of the resistive element and the third is connected to a movable contact that can slide along
the resistive element. By adjusting the position of the movable contact, the resistance between
the two end terminals can be varied, allowing for the control of the current flow in the circuit.

Fig .a. Potentiometer

2. Pulse Width Modulation:


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

2.a. Duty Cycle


When the signal is high, we call this "on time". To describe the amount of "on time", we use
the concept of duty cycle. The duty cycle is measured in percentage. The percentage duty
cycle specifically describes the percentage of time a digital signal is on over an interval or
period of time. This period is the inverse of the frequency of the waveform. If a digital signal
spends half of the time on and the other half off, we would say the digital signal has a duty
cycle of 50% and resembles an ideal square wave. If the percentage is higher than 50%, the
digital signal spends more time in the high state than the low state and vice versa if the duty
cycle is less than 50%. 100% duty cycle would be the same as setting the voltage to 5 Volts
(high). 0% duty cycle would be the same as grounding the signal. Here is a graph that
illustrates 3 different duty cycle.

Fig. b. Graph that illustrates 3 different duty cycle

3. Analog to Digital Converter (ADC)


An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage
on a pin to a digital number. By converting from the analog world to the digital world, we can
begin to use electronics to interface with the analog world around us. The Arduino boards
have an inbuilt analog-to-digital converter. The ADC on the Arduino is a 10-bit ADC meaning
it has the ability to detect 1,024 (2^10) discrete analog levels.
Fig. c. Analog pins on Arduino Board

Experiment 1: To get analog reading from the serial monitor using


potentiometer.
Hardware Required: Arduino board, potentiometer, connecting wires, Bread board.

Circuit Diagram

Circuit Explanation:
The middle pin of the potentiometer is connected to the analog input pin A0 on the Arduino.
The other pins are connected to 5V and GND respectively. The output voltage is directly
proportional to the rotated angle of the movable contact. When the movable contact is turned
all the way in one direction (nearest by GND), voltage at the analog pin is reading 0V, which
corresponds to 0 input level. When the movable contact is turned all the way in other direction
(nearest by 5V), voltage at the analog pin is reading 5V, which corresponds to 1023 input level.
The analog input levels then map to a range from 0 to 255.
Programming Code:

// C++ code
int pot = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop()
{
pot = analogRead(A0); // Read input value on analog pin
pot = map(pot, 0, 1023, 0, 255); // The result is mapped to range 0-255
Serial.println(pot); // print result on the serial monitor
delay(15); // Wait for 15 millisecond(s)
}}
Results:
As the movable contact of the potentiometer is turned, the output value is printed on the serial
monitor.

EXPERIMENT 2: To control the brightness of an LED using potentiometer

Hardware Required: Arduino board, LED, resistor (220 ohm), potentiometer,


connecting wires, Bread board.

Circuit Diagram

Circuit Explanation:
The middle pin of the potentiometer is connected to the analog input pin (A0) on the Arduino.
The other pins are connected to 5V and GND respectively. The output voltage is directly
proportional to the rotated angle of the movable contact. When the movable contact is turned
all the way in one direction (nearest by GND), voltage at the analog pin is reading 0V, which
corresponds to 0 input level. When the movable contact is turned all the way in other direction
(nearest by 5V), voltage at the analog pin is reading 5V, which corresponds to 1023 input level.
An LED is taken and its Cathode is grounded while anode is connected to digital pin 9 through
a 220 ohm resistor. The analog input levels then map to a range from 0 to 255. After mapping,
this value is utilized to adjust the brightness of an LED connected to digital pin 9 using pulse
width modulation (PWM).
Programming Code:

// C++ code
int pot = 0;
int out = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
}
void loop()
{
pot = analogRead(A0);
pot = map(pot, 0, 1023, 0, 255);
analogWrite(9, pot);
delay(15); // Wait for 15 millisecond(s)
}

Results:
As the movable contact of the potentiometer is turned, the brightness of the LED changes
respectively.

EXPERIMENT 3: To control the brightness of a 2 LED using 2 potentiometer.

Hardware Required: Arduino board, two LEDs, two resistors (220 ohm),
potentiometer, connecting wires, Bread board.
Circuit Diagram

Circuit Explanation:
The middle pin of the two potentiometers are connected to the analog input pins (A0,A1) on
the Arduino. The other pins are connected to 5V and GND respectively. The output voltage is
directly proportional to the rotated angle of the movable contact. When the movable contact is
turned all the way in one direction (nearest by GND), voltage at the analog pin is reading 0V,
which corresponds to 0 input level. When the movable contact is turned all the way in other
direction (nearest by 5V), voltage at the analog pin is reading 5V, which corresponds to 1023
input level. Two LEDs are taken and their Cathode is grounded while anode is connected to
digital pin 9 and 10 through 220 ohm resistors. The analog input levels then map to a range
from 0 to 255. After mapping, this value is utilized to adjust the brightness of each LED
connected to digital pin 9 and 10 using pulse width modulation (PWM).

Programming Code:
// C++ code
int pot1 = 0;
int pot2 = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop()
{
pot1 = analogRead(A0);
pot2 = analogRead(A1);
pot1 = map(pot1, 0, 1023, 0, 255);
pot2 = map(pot2, 0, 1023, 0, 255);
analogWrite(9, pot1);
analogWrite(10, pot2);
delay(15); // Wait for 15 millisecond(s)
}
Results:
As the movable contact of the each potentiometer is turned, the brightness of the each
Led changes respectively.

EXPERIMENT 4: To control Three LED using three potentiometers.


Hardware Required: Arduino board, three LEDs, three resistors(220 ohm),
three potentiometers, connecting wires, Bread board.

Circuit Diagram:
Circuit Explanation:
The middle pin of the Three potentiometers are connected to the analog input pins (A0,A1,A2)
on the Arduino. The other pins are connected to 5V and GND respectively. The output voltage
is directly proportional to the rotated angle of the movable contact. When the movable contact
is turned all the way in one direction (nearest by GND), voltage at the analog pin is reading 0V,
which corresponds to 0 input level. When the movable contact is turned all the way in other
direction (nearest by 5V), voltage at the analog pin is reading 5V, which corresponds to 1023
input level. Three Leds are taken and their Cathode is grounded while anode is connected to
digital pin 9 , 10 and 11 through 220 ohm resistors. The analog input levels then map to a range
from 0 to 255. After mapping, this value is utilized to adjust the brightness of each LED
connected to digital pin 9 , 10 and 11 using pulse width modulation (PWM).

Programming Code:

// C++ code
int pot1 = 0;
int pot2 = 0;
int pot3 = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
pot1 = analogRead(A0);
pot2 = analogRead(A1);
pot3 = analogRead(A2);
pot1 = map(pot1, 0, 1023, 0, 255);
pot2 = map(pot2, 0, 1023, 0, 255);
pot3 = map(pot3, 0, 1023, 0, 255);
analogWrite(9, pot1);
analogWrite(10, pot2);
analogWrite(11, pot3);
delay(15); // Wait for 15 millisecond(s)
}

Results:
As the movable contact of the each potentiometer is turned, the brightness of the each
Led changes respectively.

You might also like