I'll continue in this thread with my follow up question:
I'm trying to get an lm35 (temperature sensor) to work with the analog pin on the nodemcu 1.0. I realise now that the voltage out (V_out) from the lm35 is not that arriving at the ADC pin on the esp, but rather V_adc = V_out * 100/320 (given the voltage divider).
So, if we have a V_out = 0.2V, the V_adc = 0.0625. We've basically scaled the V_out.
The LM35 datasheet says that the temperature changes by 1 deg C for each 10 mV. So, given that I've scaled the voltage, I'd have to scale the 10 mV/C to 10 * 100/320 mV/C, right? And the temperature reading should be V_adc * 1000 / (10 * 100 / 320)
I'm getting temperatures about 5 degrees higher than I would expect.. Here is my code for getting the temperature:
float getTemperature()
{
int val = analogRead(TEMP);
Serial.print("Analog: ");
Serial.println(val);
float mv = (val / 1024.0);
Serial.print("V at analog: ");
float vAtAnalog = val / 1024.0 * 3.3;
mv = vAtAnalog * 1000;
float cel = mv / (10.0 * (10.0/32.0));
return cel;
}
Now, when I measured the with a potentiometer, I found the voltage at which the ADC pin gives a reading of 1024 is at about 3.5V. I'm not sure if this is related?
Can anyone see a problem / possible see whether I have a mistake in my code above. Any help is appreciated.