dramatically simplify what we must do to integrate this
sensor with the microcontroller. In this case, just plug
it into a few digital pins and install the library. All the
low level functions of reading the resistance,
converting it to a voltage, filtering it, conditioning it,
even compensating the electronics with the
measured onboard temperature, and ending up with
a calibrated barometric pressure is all done “under
the hood” for us by the electronics shown in Figure
2. That’s a lot of processing power in a tiny space —
all for less than $15.
Some sensors output a low level digital signal,
like a rain gauge. This sensor just sends a click
every time a bucket is filled and emptied. It’s up to
us to count the clicks with a digital I/O pin and
keep track of the total rain fall.
Then, there are all the sensors which just
output an analog signal. This is where the analog
front end conditioning we add to the system can
dramatically improve the quality of the measured
Limitations to Sensor Measurements
in an Arduino
An example of a sensor which outputs a voltage is the
TMP36 temperature sensor also from SparkFun. It comes
in a small three-terminal plastic package shown in Figure
3. One pin is connected to +5V; another pin is connected
to gnd; and the middle pin is the voltage output that is
directly proportional to temperature, with a sensitivity of
10 mV/°C and 0V at - 50°C, or 100°C/V.
The output voltage from this temperature sensor can
be read directly by one of the analog input pins on the
Arduino. Here’s where we encounter the fundamental
limitations with the Arduino analog input pins.
Each analog input pin of the Arduino is a 10-bit ADC
(analog-to-digital converter). This means there are only
2^ 10 = 1024 discrete voltage levels the ADC can report.
When we “read” an analog pin, the integer that comes
back is a discrete level — a number between 0 and 1023.
We sometimes refer to the units of these levels as analog-to-digital units (ADUs). When analog accuracy is
important, or in general as a good habit, I use the 3.3V
onboard reference as the reference to the ADC channels
(see the sidebar). I also add a large capacitor to the
reference channel just to reduce any AC noise on this rail.
With a voltage scale of 0V to 3.3V, this means the
voltage resolution is 3.3/1023 = 3. 2 mV resolution. In
general, we should measure the reference voltage level for
the ADC, Vref, with a three-digit DMM. Then, the voltage
on the pin in volts is V[volts] = ADUs/1023*Vref.
The TMP36 sensitivity is 100°C/V. With a discrete
level resolution of about 3. 2 mV, the Arduino has about a
0.3°C per ADU resolution. This may be fine for reporting
ambient temperature, but may not be sensitive enough
when we care about very small temperature changes.
I wrote a sketch to read one of the analog channels of
an Arduino Redboard from SparkFun. I averaged about
100 readings in about 100 msec, and scaled the voltage
into a temperature value. The analog channel reading in
February 2016 39
FIGURE 4. Measured temperature of the TMP36 when
I touched it and let go.
FIGURE 3. Close-up of the TMP36
FIGURE 2. The electronics that turn the resistance
measurement into an I2C signal that is then read by the
microcontroller (source: EPCOS datasheet).