Introduction: WiFi Temperature Logger (with ESP8266)

About: I'm a student from Italy. I'm studying Information and Communication Engineering at the University of Trento (Universita' degli Studi di Trento). For my project I use Microchip's and Atmel micro controller.

Hello, glad to see you here. I hope that in this instructable you will find some useful information. Feel free to send me suggestions, questions, ... Here are some basic data and a quick overview of the project. For mobile users: Video.
Let me know what you think of the project in the comment section, thanks.

I've recently bought a NodeMcu (esp8266 based) board just to give it a try so this is not a really advanced project. But it works and it is what I need, so it's ok.

Main function for this data logger is to collect temperature and save it to a server. This lets users check data and graph online even when they aren't in the same location of the logger (for example for a weather station). Another useful feature is the OTA update included in the code that let user update and customize the software easily. I'll analyze two sensors and their related acquisition method to make a balance of all pros and cons.

Spoiler: after a bit of testing i found that a digital sensor like DS18B20 is the best solution because it offers stability and higher accuracy. It's already waterproof and with the cable.

Step 1: Materials

This is a minimal project with only few external component, for this the BOM list will be really short. However, let's see what material is requested:

  • NodeMcu V3 (or any compatible ESP8266 μprocessor);
  • RGB led (common anode);
  • Resistors for led (1x10Ω, 1x22Ω, 1x100Ω, 1x10kΩ)
  • DS18B20 (Maxim Integrated thermometer);
  • LM35 (Texas Instrument thermometer);
  • External battery (optional);
  • Cable;
  • Connector (to make it more "advanced");
  • Box (optional, again to make it more "advanced");
  • Led holder (optional);

Note: As I said you need to chose one of the two methods. If you choose LM35 thermometer, you'll need a few others component:

  • Attiny45/85;
  • AVR programmer (or Arduino as ISP);
  • Resistor (1x1kΩ,1x2kΩ, 1x10kΩ, 1x18kΩ)
  • 2.54mm strip connector (optional)
  • Diode (2x1N914)
  • Perfboard or PCB;

Step 2: Choosing the Sensor

Choosing the sensor can be a difficult step: today there are tons of transducers (TI offers 144 different element) both analog and digital with different temperature range, accuracy and case.

Analog Sensors (46 parts available from TI):

  • The data logger can easily be changed from temperature to another quantity (voltage, current, ...);
  • May be a little cheaper;
  • Easy to use since it doesn't require any special library;


  • Require ADC (that can influence the measurement's accuracy) and other external components. Since esp8266 has only one ADC (and not really accurate) I would suggest to use an external one.
  • Needs dedicated cable with noise rejection since any inducted voltage can change the result.

After a bit of thinking I decided to use LM35, a linear sensor with +10mV/°C scale factor with 0.5°C accuracy and a very low current (about 60uA) with a operating voltage from 4V to 30V. For more detail I suggest to see the datasheet: LM35.

Digital Sensors (highly recommended)

  • Almost any external components needed;
  • Integrated ADC


  • Request library or software con decode the digital signal (I2C, SPI, Serial, One Wire, ...);
  • More expensive;

I've chosen DS18B20 because I found a set of 5 waterproof sensors on Amazon and because it's widely documented on internet. Main feature is 9-12bit measurement, 1-Wire bus, 3.0 to 5.5 supply voltage, 0.5°C accuracy. Again, for more detail here is the datasheet: DS18B20.

Step 3: LM35

Let's analyse how I've implemented the external ADC and other feature for the LM35 thermometer. I found a cable with three wires, one with shielding and two without. I decided to add a decoupling capacitor to stabilize the supply voltage near the sensor.

To convert analog temperature to digital, I've used Attiny85 microprocessor in a dip8 package (again for more information see the datasheet: attiny85). Most important thing for us is the 10 bit ADC (not really the best one but enough precise for me). To communicate with Esp8266 I decided to use Serial communication keeping in mind that esp8266 works with 3.3V and attiny85 at 5V (as it needs to power the sensor). To achieve that, i used a simple voltage divider (see schematic). To read negative temperature we need to add some external components (2x1N914 and 1x18k resistor), since I don't want to use negative power supply.

Here is the code: TinyADC repository.

Note: to compile this code you'll need to install attiny to ide (insert this in option:, if you don't know how to do it, just search on Google.Or upload .hex file directly.

Step 4: DS18B20

I bought those sensors from Amazon (5 costs about 10€). It arrived with a stainless steel cover and a cable 1m length. This sensor can return 9 to 12 bit data of temperature. Lots of sensor can be plugged in the same pin since all of them have an unique ID.

To plug the DS18B20 to esp8266 you can just follow the schematic (second photo).

Since I've decided that my logger would have had three probes, I've had to distinguish which is which. So I thought to give them a color associated via software to their address. I've used some thermo-shrinkable tube(third photo).

Step 5: ESP8266 Code

Since I'm new to this world, I decided to use a lot of libraries. As said in the introduction main features are:

  • OTA update: you don't need to plug esp8266 to your computer every time you need to upload the code (you have to do it only the first time);
  • Wireless manager, if wireless network change, you don't need to reupload the sketch. You can simply configure again the network parameters connecting to esp8266 access point;
  • Thingspeak data trasmission;
  • Both LM35 and DS18B20 supported;
  • Simple User Interface (RGB led indicates some useful information);

Please apologize me because my software isn't the best and it's not really well-ordered. Before uploading to the device, you need to change some parameters to fit the code to your setup. Here you can download the software.

Common LM35 and DS18B20 configuration

You need to change pin definition, token, channel number, user and password for OTA update. Line from 15 to 23.

#define red YOURPINHERE #define green YOURPINHERE 
#define blue YOURPINHERE 
const char* host = "select host address"; //not really needed you can leave esp8266-webupdate
const char* update_path = "/firmware"; //to change the address for updating ex: 
const char* update_username = "YOURUSERHERE"; 
const char* update_password = "YOURPASSWORDHERE; 
unsigned long myChannelNumber = CHANNELNUMBERHERE; 
const char * myWriteAPIKey = "WRITEAPIHERE";

Step 6: ESP8266 Code: LM35 User

You need to connect the attiny board to esp8266, to power the ADC unit use the VU pin and G pin. You need to choose which pin you want to use for serial communication (to keep hardware serial free for debug purpose). Tx pin must be selected but isn't really used. (Line 27).

SoftwareSerial mySerial (RXPIN, TXPIN);

On the top you need to add:

#define LM35USER

Step 7: ESP8266 Code: DS18B20 User

As first operation you need to identify the device Address for each sensor. Compile and program this code to the esp and look in serial for the results. Code can be found here (search for this title in the page: «Read individual DS18B20 Internal Addresses»). Connect only one sensor to obtain the address, results should be something like this (random number here! Just as example):

0x11, 0x22, 0x33, 0xD9, 0xB1, 0x17, 0x45, 0x12

Then you need to change my code in the section "Configuration for DS18B20" (line 31 to 36)":

#define delayDallas READINTERVAL //(In Milliseconds, minimum is 15s or 15000mS)
DeviceAddress blueSensor = { 0x11, 0x22, 0x33, 0xD9, 0xB1, 0x17, 0x45, 0x12}; //CHANGE WITH YOUR ADDRESS
DeviceAddress redSensor = { 0x11, 0x22, 0x33, 0xD9, 0xB1, 0x17, 0x45, 0x12}; //CHANGE WITH YOUR ADDRESS
DeviceAddress greenSensor = {0x11, 0x22, 0x33, 0xD9, 0xB1, 0x17, 0x45, 0x12 }; //CHANGE WITH YOUR ADDRESS

On the top you need to add:
#define DSUSER

Step 8: ESP8266 Little Trick

After a bit of testing I found that if you plug esp8266 without programming, it will not run the code until you press reset one time. To solve this issue, after a bit of research, I discovered that you have to add a pull-up resistor from 3.3V to D3. This will tell the processor to load the code from flash memory.

With this method, D3 can directly be used to data input for DS18B20 sensors.

Step 9: First Time Operation

If you've uploaded the code correctly but never use Wifi manager library it's time to configure your wifi connection. Wait until you see the RGB led flashing faster than before, then search with your mobile or PC the wifi network called "AutoConnectAp" and connect.

After connection, open a web browser and enter, you'll find the GUI interface of wifi manager (see photos) and press "Configure Wifi". Wait for esp8266 to search wifi networks, and select the desired one. Insert password and press "save".

Esp8266 will restart (don't care RGB led this time because it'll output some random information) and connect to the network.

Step 10: Conclusion

In the end, here is a graph taken from the data logger in action while logging my freezer temperature. In orange is the DS18B20 and in blue the LM35 and it's circuit. You can see the biggest difference in accuracy from digital to analog sensor (with my poor "ADC circuit") that give some non-physical data.

Summing up, if you want to build this logger I suggest using the DS18B20 digital temperature sensor since it's easier to read and almost "plug and play", it's more stable and accurate, it runs at 3.3V and require only one pin for lots of sensors.

Thanks for the attention, I hope that this project is good for you and you've found some useful information. And for who wants to realize it, I wish that i gave all the information needed. If not fell free to ask everything, I'll be happy to answer to all the questions. Since I'm not an English speaker, if something is wrong or not understandable please let me know.

If you liked this project, please vote it for the contests and/or leave a comment ☺. It will encourage me to keep updating and publishing new contents. Thank you.

Step 11:

Epilog Challenge 9

Participated in the
Epilog Challenge 9