Hardware Reference
In-Depth Information
ConvertinganAnalogSignaltoaDigitalOne
Suppose that you want to measure the brightness of your room. Presumably,
a good light sensor could produce a varying output voltage that changes with
the brightness of the room. When it is pitch black, the device would output 0V,
and when it's completely saturated by light, it would output 5V, with values in
between corresponding to the varying amount of light. That's all well and good,
but how do you go about reading those values with an Arduino to figure out
how bright the room is? You can use the Arduino's analog-to-digital converter
(ADC) pins to convert analog voltage values into number representations that
you can work with.
The accuracy of an ADC is determined by the resolution. In the case of the
Arduino Uno, there is a 10-bit ADC for doing your analog conversions. “10-bit”
means that the ADC can subdivide (or quantize) an analog signal into 2 10 dif-
ferent values. If you do the math, you'll find that 2 10 = 1024; hence, the Arduino
can assign a value from 0 to 1023 for any analog value that you give it. Although
it is possible to change the reference voltage, you'll be using the default 5V
reference for the analog work that you do in this topic. The reference voltage
determines the max voltage that you are expecting, and, therefore, the value
that will be mapped to 1023. So, with a 5V reference voltage, putting 0V on an
ADC pin returns a value of 0, 2.5V returns a value of 512 (half of 1023), and 5V
returns a value of 1023. To better understand what's happening here, consider
what a 3-bit ADC would do, as shown in Figure 3-2.
Figure 3-2: 3-bit analog quantization
Search WWH ::




Custom Search