Sparkfun ESP8266 and TMP36 sensor, high read values?

Hi all,

I have a Sparkfun ESP8266 Thing Dev board and a TMP36 sensor from the Arduino Starter Kit. I have made the project Love-O-Meter project 3 from the Projects Book with the Genuino Uno board, and now i want to do the same with the Sparkfun board. I have connected the TMP36 sensor and hooked up 2 LEDs. But i’m getting some weird readings on the Sparkfun board. On the Uno board i am reading the correct values, but the ESP8266 board is reading some really high values.

I have hooked the sensor to the 5V pin and GND, and the middle pin to the ADC/A0 analog pin.

My code is and this works on the Uno.

const int sensorPin = A0;
const int LEDRedPin = 12;
const int LEDGreenPin = 14;
const int baseTemp = 25;

void setup() {
  pinMode(LEDRedPin, OUTPUT);
  pinMode(LEDGreenPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Val: ");
  Serial.print(sensorVal);
  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.print(", voltage: ");
  Serial.print(voltage);
  float temperature = (voltage - .5) * 100;
  Serial.print(", temperature: ");
  Serial.println(temperature);
  if (temperature > baseTemp) {
    digitalWrite(LEDRedPin, HIGH);
    digitalWrite(LEDGreenPin, LOW);
  } else {
    digitalWrite(LEDRedPin, LOW);
    digitalWrite(LEDGreenPin, HIGH);
  }
  delay(1000);
}

Is there something speciel about the ESP8266 board and the analog input?

Kind regards

Steffen

The Uno uses 5V I/O, while the Sparkfun ESP8266 Thing Dev uses 3.3V I/O. You’ll need to connect the TMP36 to 3.3V and adjust your code.

Okay, i have changed the volt to 3.3 and adjusted the code for that. Instead of: float voltage = (sensorVal/1024.0) * 5.0; it is now: float voltage = (sensorVal / 1024.0) * 3.3;. But i’m still getting some really high values.

After a little reading i can see that the analog input have a range of 0v to 1v. Does this means that i need a voltage divider between the Vout pin and the analog input? Or is there something else i need to do?

I’m new to electronics :slight_smile:

You’re right, I hadn’t noticed that. A voltage divider would work. So would switching to a sensor with a digital interface.

Okay, i tried to put a voltage divider between then Vout and the analog pin. So there was about 0.93V with the resistors i got from the kit, but the reading was still about 10C off. I will se if i can find one with a digital interface instead.

And thanks for your help :slight_smile:

Sparkfun carries several https://www.sparkfun.com/search/results … ure+sensor.

If the A0 pin of the 8266 Thing has been subjected to 3.3 volt or 5 volt then it could also have been damaged. First make sure it gives out proper readings from voltages known to be between 0 and 1c for sure.