Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By RogerGuess
#14287 I am attempting to connect pin 2 to a temp sensor and read voltage. I have a tmp36. I have confirmed that it is working using an Auduino UNO:

https://learn.adafruit.com/tmp36-temper ... emp-sensor

I have confirmed that I am correctly identifying pin 2 as I was able to use it in output mode to blink an LED. However, no sketch I have tried can get anything from analogRead other than '0'. I have even tried connecting pin 2 back to 3.3v.

Any suggestions?

Sketch:
Code: Select allint sensorPin = 2;
int i = 0;

void setup() {
  pinMode(sensorPin, INPUT);
  Serial.begin(115200);
}

void loop() {
  int reading = analogRead(sensorPin);
  Serial.print(reading);
  Serial.println(" reading");
 
  float voltage = reading * 3.3;
  voltage /= 1024.0;
 
  Serial.print(voltage);
  Serial.println(" volts");
  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((voltage - 500mV) times 100)
  Serial.print(temperatureC); Serial.println(" degrees C");
  // now convert to Fahrenheit
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  Serial.print(temperatureF); Serial.println(" degrees F");
  Serial.println(i);
  Serial.println("");
  Serial.println("");
  i+=1;
  delay(1000); 
}
User avatar
By alonewolfx2
#14304 tmp36 is analog sensor. esp8266 have just one adc pin with 1v scale. soo you cant use tmp36 directly attached pin 2.

RogerGuess wrote:I am attempting to connect pin 2 to a temp sensor and read voltage. I have a tmp36. I have confirmed that it is working using an Auduino UNO:

https://learn.adafruit.com/tmp36-temper ... emp-sensor

I have confirmed that I am correctly identifying pin 2 as I was able to use it in output mode to blink an LED. However, no sketch I have tried can get anything from analogRead other than '0'. I have even tried connecting pin 2 back to 3.3v.

Any suggestions?

Sketch:
Code: Select allint sensorPin = 2;
int i = 0;

void setup() {
  pinMode(sensorPin, INPUT);
  Serial.begin(115200);
}

void loop() {
  int reading = analogRead(sensorPin);
  Serial.print(reading);
  Serial.println(" reading");
 
  float voltage = reading * 3.3;
  voltage /= 1024.0;
 
  Serial.print(voltage);
  Serial.println(" volts");
  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((voltage - 500mV) times 100)
  Serial.print(temperatureC); Serial.println(" degrees C");
  // now convert to Fahrenheit
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  Serial.print(temperatureF); Serial.println(" degrees F");
  Serial.println(i);
  Serial.println("");
  Serial.println("");
  i+=1;
  delay(1000); 
}
User avatar
By RogerGuess
#14323 I understand now that I have a ESP-01. I am not sure I completely how the one pin differs from an Arduino, or the significance of it being 1v scale.

Can I do this with the ESP-01 and a different type of temp sensor? Suggestions welcome.

Thanks
User avatar
By lethe
#14330 The ESP has only one ADC channel (usually labeled TOUT or ADC), which is not available on the ESP-01 (since it only has 2 I/Os), so you can't use analog sensors.
Your options are either to get an ESP module which has the ADC routed to a pin (e.g. ESP-7/12/201 or Olimex MOD-WIFI-ESP8266-DEV) or use a digital sensor such as the DS18B20 (one-wire) or LM75 (i2c). There are also many combo sensors available for temperature & humidity measurement (DHT11/21, AM2321, SHT21) or temperature & barometer (BMP180).
If you stick with the TMP36, be aware that it's output voltage will exceed 1V for temperatures above 50°C.