Thermometer = Nodemcu ESP8266 + DS18B20

Hi Readers,

Today I would like to show you how we can use our nodemcu as a simple thermometer.

What you need:

  1. Nodemcu (esp8266)
  2. DS18B20
  3. Arduino studio
  4. Serialport monitor (for example the one from Arduino studio)

You can also use:

  1. Breadboard
  2. Couple connectors
  3. 4.7k ohms resistor

How it should be connected?

Untitled Sketch_bb

As you can see on attached picture you need to first connect 3.3V and GND on your breadboard to edge breadboard. Then you simply should connect DS18B20 sensor legs to 3.3V and GND plus its DQ to Nodemcu D4 and also connect it by 4.7k ohm resistor to the 3.3V.

This is how it looked for me


I am sure you have manage to connect everything so let’s do some coding.

I have created example code (based on ajaran source code) which you can build and upload by Arduino studio (I used it) and test and use device you have just created! If you haven’t noticed that you have just build basic and simple thermometer :). In example source code gathered temperate I am printing to the serial port. So you can use really any serial monitor to read current temperature.


#define myPeriodic 15 // Seconds
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float prevTemp = 0;
const char* MY_SSID = “ssid”;
const char* MY_PWD = “password”;
int sent = 0;
void setup() {

void loop() {
float temp;
temp = DS18B20.getTempCByIndex(0);
Serial.print(String(sent)+” Temperature: “);
int count = myPeriodic;

I have hope you enjoyed this post. I did!


Github repository:

Be positive and stay calm!



Leave a Reply

Your email address will not be published. Required fields are marked *