Hardware Reference
In-Depth Information
Figure 14-2: An LM35
However, the Arduino's analog-to-digital converters are normally calibrated
from 0 to 5 volts, but the LM35 will never output 5 volts. To compare analog
values, the Arduino will compare the input to something called a reference —a
voltage. Generated inside the microcontroller, this reference is normally set to
the same voltage as the Arduino's power. The reference voltage can be changed
so instead of sampling values between 0 and 5 volts, the Arduino can be told
to sample between 0 and 1.1 volts. You do this by calling analogReference
(INTERNAL). This will give more precision for this application, but it comes at
a price. If using the INTERNAL constant, this sketch will not run correctly on an
Arduino Mega; it will require changing. When this example is complete, it will
be up to you, the designer, to choose if you want to sample on 5 V and keep
compatibility or to use a different sample range and only use specii c boards.
By using a reference of 1.1 V, the 10-bit ADC will have a sampling precision
of 1.1 divided by 1,024, or 1.07 mV. The LM35 outputs 10 mV per degree, so 10
divided by 1.07 is approximately 9.31. So, a change of 9.31 in the analog reading
equals 1 degree. To get a reading in Celsius, simply get the return value and
divide by 9.31.
The sketch can now retrieve temperatures between 0 and 100 degrees Celsius,
but this range is too large. If your internal thermometer is showing 100 degrees,
your house might be on i re, and you shouldn't be looking at your thermometer.
If the outside reading is 100 degrees, something is wrong. In both cases, there is
no use in displaying the temperature, so everything above 50 will be ignored.
Finally, the last part will be to convert a temperature into the servo motor
movement. For this example, the servo motor will be mounted so that the 0-180
degrees line is parallel to the l oor. Ninety degrees will be straight up. The tem-
perature hand will move only between 45 degrees and 135 degrees.
This brings a question: How should the temperature be converted to an angle?
This sounds like a lot of complicated calculation; 0 degrees Celsius is 45 degrees
Search WWH ::




Custom Search