Analog Sensor Output analogRead()

I’m utilizing an analog temperature sensor (TMP36) and obtaining different results between an Arduino and a Dash with analogRead(). Should the readings be the same or is the analog to digital converter different in the Dash? Thanks !

@tonym63

The Dash analogRead() is biased to 3.3V - the core voltage of our micro. The Arduino you were using might have been biased to 5V, which could provide a different value. The default analog resolution on the Dash is 10 bits, so 0-3.3V will give a range of values 0-1023. You can call analogReadResolution(new_resolution), which allows you to change the resolution to 8, 10, 12 or 16 bits.

I found a TMP36 in one of my boxes of components (yea Sparkfun!) and wrote this sketch:

void setup() {
  // put your setup code here, to run once:;
  SerialUSB.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  uint32_t temp = analogRead(A01);
  int32_t mv = temp*3300/1024;  //convert to mV
  int32_t c10 = mv - 750 + 250; //750mv == 25C for TMP36
  SerialUSB.print("TMP36: ");
  SerialUSB.print(temp);
  SerialUSB.print("/1024 ");
  SerialUSB.print(mv);
  SerialUSB.print("mV ");
  SerialUSB.print(c10/10);
  SerialUSB.print(".");
  SerialUSB.print(abs(c10%10));
  SerialUSB.println("C");
  delay(3000);
}

I got the following output, putting my finger on the TMP36 and then removing it:

TMP36: 221/1024 712mV 21.2C
TMP36: 221/1024 712mV 21.2C
TMP36: 232/1024 747mV 24.7C
TMP36: 225/1024 725mV 22.5C
TMP36: 247/1024 795mV 29.5C
TMP36: 242/1024 779mV 27.9C
TMP36: 250/1024 805mV 30.5C
TMP36: 239/1024 770mV 27.0C
TMP36: 240/1024 773mV 27.3C
TMP36: 239/1024 770mV 27.0C
TMP36: 238/1024 766mV 26.6C
TMP36: 236/1024 760mV 26.0C
TMP36: 236/1024 760mV 26.0C
TMP36: 234/1024 754mV 25.4C
TMP36: 232/1024 747mV 24.7C
TMP36: 232/1024 747mV 24.7C
TMP36: 229/1024 737mV 23.7C
TMP36: 240/1024 773mV 27.3C
TMP36: 229/1024 737mV 23.7C
TMP36: 229/1024 737mV 23.7C
TMP36: 228/1024 734mV 23.4C

2 Likes

Thanks Eric! Greatly appreciate the quick and detailed response. Made the suggested changes and it works perfectly.

@tonym63

Glad it’s working for you! Notice I made a change to the code (click the pencil icon to see the diff) to correctly handle negative temperatures.

Great! Thanks again Erik