Analog-to-Digital Converter (ADC)
can read. This is usually some
combination of resistors, voltage
bias, op-amps, and instrumentation
Once the digital signal is in the
Arduino through its ADC, we can
apply the power of math with digital
signal processing to turn these bits into the
appropriate Pulse Width Modulated (PWM)
voltage signal that will drive adjustable current
through the LED. There is a limit to the output
current of an Arduino pin. If we need more
current, we can use a current booster. This can
be as simple as a transistor follower circuit.
To illustrate how to implement each section,
I’ll walk you through three examples which go
from simple to more complex:
Example #1: Internally generated sine wave
signal and Arduino limited LED brightness.
Example #2: Pushing the ultimate current limits to an LED.
Example #3: Modulating the LED brightness with an air
Example #1: Modulating an LED’s Brightness:
The Quick and Simple
In this first example, we’re going to modulate an LED’s
brightness with a simple math function generated inside
an Arduino. I chose to use a sine wave as the example. If
you can describe the function as an intensity vs. time, you
can use it to modulate the LED or any other light source.
Every sine wave has just three terms that characterize
it: the amplitude, frequency, and phase. The phase just
says where in the cycle we start the sine wave. To make it
easy, we’ll use a phase of 0. Then, it’s just the amplitude
(A) and frequency (f) we need to define.
Sine waves are bipolar, rising equally above zero and
below zero in magnitude. Figure 2 shows the calculated
sine wave signal with an amplitude of one and a
frequency of 1 Hz. The pattern repeats every 1 sec, so its
frequency is one cycle per second — or 1 Hz — in this
example. We have to modify this sine wave slightly to use
it to modulate an LED. While the sine wave magnitude
drops below zero, an LED’s light intensity cannot. Its
lowest value is 0. We’re going to shift the sine wave up so
it extends between 0 to the peak value, A. The sine wave
function for an intensity [I(t)] is:
The factor of 1/2 at the beginning scales the sine
wave so that its maximum value is A/2 x 2 = A.
This is literally the equation we will use in the Arduino
sketch to modulate the LED. This will be the analog
voltage output to the Arduino Digital-to-Analog Converter
(DAC) pin which will drive the LED.
Analog Output Signals and the Arduino
The Arduino and many other microcontrollers don’t
really have an analog output signal. Instead, they have a
PWM signal. In the Arduino, it is a 500 Hz digital signal
with a duty cycle that is modulated. The average of the
modulated signal is the analog voltage.
When the analog Write value is set to a high level, the
duty cycle is nearly 100%. When set to a small value, the
duty cycle is close to zero. Figure 3 shows the measured
PWM output voltages on pin 3 for an output level that is a
4.5V/90% duty cycle, and a 0.5V/10% duty cycle signal.
Not all the Arduino pins can be used for PWM
output. On my RedBoard from SparkFun, the PWM pins
are identified with a “~” (tilde) symbol written right on the
By Eric Bogatin
March 2016 39
Figure 1. Flow diagram of the system implemented in this project, which can be used for
many similar applications.
Example of the
magnitude of a
sine wave with
an amplitude of
frequency of 1
Hz, showing the
Post comments on this article and find any associated files and/or downloads at
A I(t) = (sin(2πft) + 1) 2
Figure 3. Measured output voltage of two PWM signals. Top: set
for 4.5V output. Bottom: for 0.5V signal. The frequencies are the
same 500 Hz, or a period of 2 msec. The duty cycle of each
signal is adjusted to control the average value.