ESP8266 IoT Temperature Sensing
I needed to get accurate temperature readings of a cold room for data logging, so I put together this schematic and code. I ultimately logged that data over wifi to a web server, which was made fairly easy by the ESP8266’s integrated wifi, but that’s a post I’ll share later.
This is the basic circuit schematic and code to get the sensing job done. It can be adapted to manipulate relays, or just monitor a growing environment. All the parts are inexpensive and fairly easy to use. The code is straight forward, and instead of printing results, they can be used to toggle other GPIO pins.(turn things on or off, etc) If you haven’t set up your Arduino environment to handle connecting to and uploading to the ESP8266 board check out this link on Github – https://github.com/esp8266/Arduino.
The Parts
Makerfocus 2pcs ESP8266 Module ESP-12E NodeMcu LUA WiFi Internet New Version Development Board (cp2102) – Makerfocus 2pcs ESP8266 Module ESP-12E NodeMcu LUA WiFi Internet New Version Development Board
Ocr TM 5 Pcs NTC 10K 3950 Ohm Waterproof Digital Thermal Temperature Sensor Probe 1M – Ocr TM 5 Pcs NTC 10K 3950 Ohm Waterproof Digital Thermal Temperature Sensor Probe 1M
A 10k Ohm resistor – 10K Ohm, 1/4 Watt, 5%, Carbon Film Resistors (pack of 100)
The Code:
byte NTCPin = A0;
#define SERIESRESISTOR 10000
#define NOMINAL_RESISTANCE 10000
#define NOMINAL_TEMPERATURE 25
#define BCOEFFICIENT 3950
void setup(){
Serial.begin(9600);
}
void loop(){
float ADCvalue;
float Resistance;
ADCvalue = analogRead(NTCPin);
Serial.print("Analoge ");
Serial.print(ADCvalue);
Serial.print(" = ");
Resistance = (1023 / ADCvalue) - 1;
Resistance = SERIESRESISTOR / Resistance;
Serial.print(Resistance);
Serial.println(" Ohm");
float steinhart;
float farthat;
steinhart = Resistance / NOMINAL_RESISTANCE; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (NOMINAL_TEMPERATURE + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C
farthat = (steinhart*1.8) + 32;
Serial.print("Temperature ");
Serial.print(steinhart);
Serial.println(" oC");
Serial.print("Temperature ");
Serial.print(farthat);
Serial.println(" F");
delay(1000);
}