ESP8266 - Temperature Sensor - OLED
This tutorial instructs you how to use ESP8266 to read the temperature from a DS18B20 sensor and then display it on an OLED.
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
Buy Note: Many DS18B20 sensors available in the market are unreliable. We strongly recommend buying the sensor from the DIYables brand using the link provided above. We tested it, and it worked reliably.
Overview of OLED and DS18B20 Temperature Sensor
If you are unfamiliar with OLED and DS18B20 Temperature Sensor (pinout, functionality, programming, etc.), the following tutorials can help:
This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
We recommend buying a DS18B20 sensor along with its accompanying wiring adapter for a seamless setup. This adapter includes an integrated resistor, removing the need for an additional resistor in the wiring.
ESP8266 Code - Temperature from DS18B20 Temperature Sensor and display it on OLED
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for “SSD1306” and locate the SSD1306 library by Adafruit.
- Then, press the Install button to complete the installation.
- You will be prompted to install additional library dependencies.
- To install all of them, click the Install All button.
- Search for “Dallas” and locate the DallasTemperature library by Miles Burton.
- Press the Install button to install the DallasTemperature library.
- You will be asked to install the dependency. Click Install All button to install OneWire library.
- Copy the code and open it in the Arduino IDE.
- Click the Upload button to transfer the code to your ESP8266.
- Place the sensor in hot and cold water, or hold it in your hand.
- Check out the result on the OLED.
※ NOTE THAT:
The code in question will center the text both horizontally and vertically on an OLED display.