ESP8266 - Temperature Sensor - LCD
This tutorial instructs you how to use ESP8266 to acquire the temperature from a DS18B20 sensor and display it on an LCD I2C.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of Temperature Sensor and LCD
If you are not familiar with temperature sensor and LCD (pinout, how it works, how to program ...), the following tutorials can provide you with more information:
Wiring Diagram
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
※ NOTE THAT:
The address of the LCD may differ depending on the manufacturer. In our code, we have used 0x27 as specified by DIYables.
Detailed Instructions
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.
- Plug the USB cable into the ESP8266 and the PC.
- Launch the Arduino IDE, choose the correct board and port.
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for “Dallas” and locate the DallasTemperature library created by Miles Burton.
- Press the Install button to add the library.
- You will be asked to install the dependency. Click Install All button to install OneWire library.
- Search for “LiquidCrystal I2C” and then locate the LiquidCrystal_I2C library by Frank de Brabander.
- Press the Install button to install the LiquidCrystal_I2C library.
- Copy the code and open it with the Arduino IDE.
- Then, press the Upload button on the Arduino IDE to compile and upload the code to the ESP8266.
- Put the sensor to both hot and cold water, or hold it in your hand.
- Check the LCD display.
If the LCD display is not showing anything, check out Troubleshooting on LCD I2C for help.
Code Explanation
Check out the line-by-line explanation contained in the comments of the source code!