Go Down

Topic: 8 bit to 10bit adc conversion.... (Read 1 time) previous topic - next topic

xylem007

I have an Arduino Diecimila and a bunch of old Phidgets 1114 Temperature Sensors.

I want to be able to get a somewhat steady / accurate temperature from these sensors inside my arduino sketches.

The formula from phidgets for the 1114 is tempC = (SensorValue / 4) - 50.

My understanding is that Phidgets have an 8 bit ADC and Arduino has a 10bit ADC.

Also read an old post here describing the use of a formula more like this tempC = (SensorValue * 0.0625) - 50. Due to the 10bit dac needing to divide by 4 again to get this result on a 10bit ADC.

Using the analoginoutserial example I've come up with this:

const int analogInPin = A5;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

Code: [Select]
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)
float temperature = 0.0;
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);           
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255); 
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);           

  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);     
  Serial.print("\t Temperature = ");
  temperature = ((float)sensorValue/4) - 50.0;
  Serial.println(temperature);   

  // wait 10 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(10);                     
}

This yields serial monitor output like so:

Code: [Select]
sensor = 303     Temperature = 25.75
sensor = 305     Temperature = 26.25
sensor = 306     Temperature = 26.50
sensor = 307     Temperature = 26.75
sensor = 303     Temperature = 25.75
sensor = 310     Temperature = 27.50
sensor = 308     Temperature = 27.00
sensor = 305     Temperature = 26.25
sensor = 306     Temperature = 26.50
sensor = 307     Temperature = 26.75
sensor = 303     Temperature = 25.75
sensor = 304     Temperature = 26.00
sensor = 302     Temperature = 25.50
sensor = 305     Temperature = 26.25
sensor = 304     Temperature = 26.00
sensor = 305     Temperature = 26.25
sensor = 307     Temperature = 26.75
sensor = 303     Temperature = 25.75
sensor = 305     Temperature = 26.25
sensor = 306     Temperature = 26.50

Which shows the temperature is about 2-3 degrees C higher than it presently is, I have a separate temp gauge here showing 24.5C

I've tried using the * 0.0625 and that just brings the value to -30, -31 range...

Nick Gammon

The analog input returns 0 for 0V and 1023 for 5V, so we can divide the read value by 1023 and multiply by 5 to give volts.

Thus:

Code: [Select]
303 / 1023 * 5 = 1.4809384164223 Volts

From the datasheet:

Quote
If the sensor is being interfaced to your own Analog to Digital Converter (not a Phidget device), our formulas can be modified by replacing (SensorValue) with (Vin * 200).


So SensorValue is:

Code: [Select]
1.4809384164223 * 200 = 296.18768328446

Now:

Quote
The Formula to translate SensorValue into Temperature is: Temperature (°C) = (SensorValue/4) - 50


Code: [Select]
   296.18768328446 / 4 - 50 = 24.046920821115

So, 24.05 degrees. Not too far out from your measured temperature, and not the figure you got.
http://www.gammon.com.au/electronics

Nick Gammon

And the reading you got of 305 gives the "right" answer:

Code: [Select]
(305 / 1023 * 5 * 200) / 4 - 50 = 24.54

So just substitute the analog reading for the 305 in that formula. Better use floats or you may lose precision.
http://www.gammon.com.au/electronics

Go Up