Wednesday, February 23, 2011

Erratic sensor readings

I soldered the temp sensor and the photocell to a small perf board to enclose in a waterproof box BUT now the temperature sensor is giving erratic readings.

As always someone has seen this before and on the adafruit forum there is a write up about interferences

Solution to try:
The problem is that the Atmega on the Arduino has one ADC that is multiplexed for all the analog pins.
When you do an analogRead(), a multiplexer connects the pin you are reading to the ADC. This works fine for low impedance voltage sources.

It takes time for a high impedance sensor like your temperature sensor to change the voltage at the ADC after this switch of pins. Temperature sensors must use low power and thus be high impedance to avoid IR heating.

Try the following:

Code:
analogRead(5);
delay(10);
nTemp = analogRead(5) * 5000L / 1024L / 10;
The first analogRead(5) will switch the pin to the ADC. The delay will allow the voltage at the ADC to stabilize and the second analogRead(5) should get a stable value.

As a note:
The ATmega ADC is suitable for devices with at most 10K ohm impedance (see the 168/328 data sheet). The Arduino analog library does not handle the ADC mux well so 10K ohms impedance won't work unless you use tricks like multiple reads and delays.

No comments:

Post a Comment