You are on page 1of 20

Basic Embedded Systems Course

Training & Development Department


training@uruktech.com
 Potentiometer (Variable Resistor)
 Analogue Input in Arduino
 Introduction to PWM
 Producing PWM in Arduino
 Mapping Variables
 Controlling the brightness level of an LED using a potentiometer.
 Controlling the time blinking rate of two LEDs by using potentiometer

Training & Development Department


training@uruktech.com
A potentiometer is a three-terminal resistor with a sliding or rotating
contact that forms an adjustable voltage divider.

Training & Development Department


training@uruktech.com
Training & Development Department
training@uruktech.com
Training & Development Department
training@uruktech.com
The Arduino Uno board contains a 6 channel, 10-bit analog to digital
converter. This means that it will map input voltages between 0 and 5 volts
into integer values between 0 and 1023. This yields a resolution between
readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.
Syntax:
Val = analogRead(pin)

Parameters:
pin: the number of the analog input pin to read from (0 to 5)
Val: variable to save the return of the function (int)
Training & Development Department
training@uruktech.com
Pulse Width Modulation is basically, a square wave with a varying high and
low time. A basic PWM signal is shown in the following figure.

Training & Development Department


training@uruktech.com
There are various terms associated with PWM:
On-Time: Duration of time signal is high.
Off-Time: Duration of time signal is low.
Period: It is represented as the sum of on-time and off-time of PWM signal.
Duty Cycle: It is represented as the percentage of time signal that remains ON
during the period of the PWM signal.

Training & Development Department


training@uruktech.com
Training & Development Department
training@uruktech.com
Training & Development Department
training@uruktech.com
Writes an analog value to a pin can be used to generate PWM signal.
The frequency of the PWM signal on most pins is approximately 490 Hz. On
the Uno and similar boards, pins 5 and 6 have a frequency of approximately
980 Hz.
Syntax:
analogWrite(pin, value)

Parameters:
pin: the pin to write to
value: the duty cycle: between 0 (always off) and 255 (always on).
Training & Development Department
training@uruktech.com
Re-maps a number from one range to another.
Syntax:

X = map (value, fromLow, fromHigh, toLow, toHigh)

Parameters:
X = new remappped value
Value: the number or variable to map.
fromLow: the lower bound of the value's current range
fromHigh: the upper bound of the value's current range
toLow: the lower bound of the value's target range
toHigh: the upper bound of the value's target range

Training & Development Department


training@uruktech.com
Assumptions:

• LED connected to PIN 3


• Potentiometer connected to A3
• The brightness of the LED changed according to the input voltage
variation fed from the potentiometer.

Training & Development Department


training@uruktech.com
Circuit Diagram:

Training & Development Department


training@uruktech.com
Program Code:

Training & Development Department


training@uruktech.com
Assumptions:

• Potentiometer connected to A0
• LED1 connected to PIN 5
• LED2 connected to PIN 6
• When the potentiometer is changed, blinking rate of the two LED is
changed (1 to 3 seconds)

Training & Development Department


training@uruktech.com
Circuit diagram:

Training & Development Department


training@uruktech.com
Program code:

Training & Development Department


training@uruktech.com
Program code:

Training & Development Department


training@uruktech.com
Thank you …
Q&A

You might also like