Adafruit ESP32 & TMP36
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit ESP32 & TMP36

by atabrizi on Sun Feb 23, 2020 1:55 pm

I have been trying to use ESP32 with TMP36 but unfortunately, things do not work out! Other users suggest using a 4.7K resistor or a capacitor in the circuit but none of these work. One user who posted a document in the Instructable uses a resistor but modified the temperature equation as (T= ((pin_reading/1023) - 0.5)*100. If the resistor is connected to the ground, this works but why? ESP32 is supposed to be a 12-bit system so instead of 1024 don't we need 4095? I am totally confused and I can't find any direct info on how TMP36 can be used to measure temperature using ESP32. Can anyone help out, please? Thanks. Abdie

Posts: 1
Joined: Sun Feb 23, 2020 1:40 pm

Re: Adafruit ESP32 & TMP36

by adafruit_support_carter on Mon Feb 24, 2020 12:28 pm

There's some basic usage info here:

Also, keep in mind that the Arduino analogRead() defaults to 10bit regardless of actual ADC resolution:
https://www.arduino.cc/reference/en/lan ... nalogread/

Posts: 20281
Joined: Tue Nov 29, 2016 2:45 pm

Re: Adafruit ESP32 & TMP36

by kevinjwalters on Fri Feb 12, 2021 9:06 pm

My recollection is it fires up in 12 bit mode on ESP32 and this aligns with https://randomnerdtutorials.com/esp32-a ... duino-ide/

I wrote some simple code for reading analogue values from ESP32 to allow me to plot them. It's got a bit more involved because I made it work on Uno too but have a look at https://github.com/kevinjwalters/circui ... test-1.ino if you still need an example of reading analogue values. I was plotting them because the Espressif ADCs don't seem to be very good, have a look at Feather ADC comparison including 2.6V limited ESP32-S2.

This is one of the calibration libraries to clean up the analogue readings from the ESP32: https://github.com/e-tinkers/esp32-adc-calibrate - that's probably a better starting point than just using analogRead().

Posts: 959
Joined: Sun Oct 01, 2017 3:15 pm

Please be positive and constructive with your questions and comments.