Go Down

### Topic: 8 bit to 10bit adc conversion.... (Read 2236 times)previous topic - next topic

#### xylem007

##### Mar 16, 2012, 01:08 am
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 analogOutPin = 9; // Analog output pin that the LED is attached to

Code: [Select]
`int sensorValue = 0;        // value read from the potint 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.75sensor = 305     Temperature = 26.25sensor = 306     Temperature = 26.50sensor = 307     Temperature = 26.75sensor = 303     Temperature = 25.75sensor = 310     Temperature = 27.50sensor = 308     Temperature = 27.00sensor = 305     Temperature = 26.25sensor = 306     Temperature = 26.50sensor = 307     Temperature = 26.75sensor = 303     Temperature = 25.75sensor = 304     Temperature = 26.00sensor = 302     Temperature = 25.50sensor = 305     Temperature = 26.25sensor = 304     Temperature = 26.00sensor = 305     Temperature = 26.25sensor = 307     Temperature = 26.75sensor = 303     Temperature = 25.75sensor = 305     Temperature = 26.25sensor = 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

#1
##### Mar 16, 2012, 01:43 am
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.
Please post technical questions on the forum, not by personal message. Thanks!

http://www.gammon.com.au/electronics

#### Nick Gammon

#2
##### Mar 16, 2012, 01:46 am

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.
Please post technical questions on the forum, not by personal message. Thanks!

http://www.gammon.com.au/electronics

Go Up

Please enter a valid email to subscribe