wires. This helps to thermally isolate the sensing element.
Figure 12 is a closeup of the thermistor soldered to
copper wires, and the other resistors in the protoboard I
used to assemble the entire circuit. When I first tried the
thermistor — which had a nominal resistance of 1K ohm at
low current — I thought a 1K resistor would be an ideal
sense resistor. However, when I connected this circuit, the
thermistor went into a thermal runaway and its resistance
dropped to nearly 200 ohms. I finally settled on a 100
ohm sense resistor. Using the 9V supply to bias the
thermistor would have resulted in a nominal voltage of
about 4.5V on the sense resistor. I wanted this closer to
2.5V — the sweet spot for the Arduino’s ADC.
The final circuit used a 100 ohm sense resistor and a
50 ohm resistor to shift the nominal sense voltage closer
to 2.5V. This means the total resistance in the path is
about 250 ohms. The current draw through the thermistor
was 9V/250 ohms = 36 mA. With this current, the power
dissipation in the thermistor is I^ 2 x R = 0.035^ 2 x 100
ohms = 125 m W. This power is enough to heat the tiny
bead thermistor to be hot to the touch. This is exactly
what I wanted.
The slightest air motion is enough to cool the tiny
bead thermistor and lower its temperature. This increases
its resistance, and the total current in the circuit decreases.
The voltage across the sense resistor will also decrease.
Figure 13 is a scope trace of the voltage on the sense
resistor in still air and then when I touched the thermistor
to cool it down. In this example, we can see the maximum
voltage range of the sense resistor spanning about 1V. This
is well inside the range of the ADC.
The real fluctuations from tiny air movements are very
small. Figure 14 shows the measured voltage across the
sense resistor from still air motions cooling the thermistor,
which are less than 100 mV in extent. The challenge left is
to turn the small fluctuations into a large enough signal to
drive the LED so it mimics the flickering of a candle.
A Little Digital Signal Processing
I needed to turn these small voltage fluctuations into
higher level signals to drive the LED current. I
experimented with an AD623 instrumentation amplifier
front end. This worked really well. I could amplify these
low level signals into any range I wanted. However, the
dynamic range of the signal was a 1V variation. If I used a
gain of more than five, I ran the risk of saturating the
However, if I used another Arduino DAC pin to create
an offset voltage which I could adjust, I could always
change the offset voltage so the difference signal was in
range. I built all this up and it worked just fine, and then
realized there was a simpler way.
These 50 mV sensor fluctuations I wanted to be
sensitive to are just in the range that can be resolved with
a 10-bit ADC. The resolution of a 0V to 5V 10-bit ADC is
Even though the instrumentation amplifier AFE gave
me unlimited headroom, I decided to go for a straight up
digital signal processing solution. I wanted to use only the
fluctuations of the sense resistor voltage to drive the LED.
Yet again, if I just took a scaled version of the fluctuations,
I would quickly reach the voltage limit of the DAC and
saturate the LED.
So, I used a trick of re-establishing the baseline. I
initially measure the voltage on the sense resistor. This is
stored as a reference value and subtracted from every
consecutive value. This difference is scaled by a factor and
then centered about an offset value. This signal is then
used to drive the LED intensity.
However, I also monitor the voltage level to the LED.
If it is close to saturation and exceeds a predefined limit —
either too high or too low — I take another reading on the
baseline and re-center the LED drive voltage. This
continually shifts the LED drive voltage so it is always in
range, and allows any scale factor or sensitivity. Figure 15
is the code snippet which executes this simple algorithm.
Nominally, I wanted the roughly 100 mV of sensor
excursion to be mapped into a 0V to 5V output signal.
This is a scale factor of about 50. I experimented with
different scale factors and found a value of from 30 to
50 seemed to give the electronic candle its most realistic
performance. Figure 16 is an example of the typical
signal which drives the LED when the sensor is in still air.
This is the eight-bit signal that is written to the PWM pin.
I also wrote this value to the serial port and used
MakerPlot to plot this data.
With a scale factor of 30, the 250-bit range
44 March 2016
Figure 15. Code snippet to re-center the LED signal each time it
exceeds a pre-set threshold.
Figure 14. Measured voltage across the sense resistor in still
ambient air, showing variations on the order of 50 mV. This is
the sort of fluctuations that will emulate a candle flicker, and
will be used to drive the LEDs.