ESP32 C3 Super Mini - Temperature Sensor - LCD

This tutorial shows you how to use the ESP32 C3 Super Mini to read the temperature from a DS18B20 temperature sensor and show it on an LCD I2C 16x2. It is a simple first project that combines a sensor and a display, with no computer needed to read the result.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - Temperature Sensor - LCD

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×LCD I2C Display 3.3V
1×Alternatively, LCD I2C 20x4
1×DS18B20 Temperature Sensor (WITH Adapter)
1×DS18B20 Temperature Sensor (WITHOUT Adapter)
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

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.

Buy Note: Most LCD I2C displays available on the market are 5V displays. They may work with this board, but it is unsafe and can damage the board. We strongly recommend using the 3.3V LCD I2C display recommended above.

Overview of Temperature Sensor and LCD

The DS18B20 is a digital temperature sensor that sends its reading over one data wire, and the LCD I2C is a display that shows text using only two data wires.

Key Features:

  • DS18B20: Sends the temperature as a digital value, so no analog reading is needed
  • LCD I2C: Shows 2 rows of text with 16 characters in each row
  • Few wires: The project uses only 3 signal wires in total

Technical Specifications:

  • DS18B20 power: 3.0V to 5.5V
  • DS18B20 range: -55°C to +125°C
  • DS18B20 accuracy: ±0.5°C between -10°C and +85°C
  • LCD I2C power: 5V
  • LCD I2C address: Usually 0x27 or 0x3F, depending on the manufacturer

We have a full tutorial for each part, with the pinout, how it works, wiring and code:

Pinout

The sensor has 3 pins and the LCD has 4 pins.

DS18B20 temperature sensor:

  • VCC: Connect to 3.3V power
  • GND: Connect to ground (0V)
  • DATA (DQ): 1-Wire data signal

LCD I2C:

  • VCC: Connect to 5V power
  • GND: Connect to ground (0V)
  • SDA: I2C data signal
  • SCL: I2C clock signal

Wiring Diagram

Connect both parts to the ESP32 C3 Super Mini as shown below.

  • Note: Unplug the USB cable before you change any wire.
  • Note: The sensor uses 3.3V, the LCD uses 5V, and both share the same GND.
  • Note: A DS18B20 with an adapter already has the pull-up resistor. A DS18B20 without an adapter needs a 4.7kΩ resistor between DATA and VCC.
The wiring diagram between ESP32 C3 Super Mini Temperature Sensor LCD

This image is created using Fritzing. Click to enlarge image

DS18B20 Pin ESP32 C3 Super Mini Pin
VCC 3.3V
GND GND
DATA GPIO7
LCD I2C Pin ESP32 C3 Super Mini Pin
VCC 5V
GND GND
SDA GPIO8
SCL GPIO9

ESP32 C3 Super Mini Code

The code below reads the temperature from the DS18B20 sensor and shows it on the LCD.

What This Code Does:

  • Uses I2C: The LCD uses the default I2C pins of the board: GPIO8 (SDA) and GPIO9 (SCL)
  • Starts the parts: Starts the DS18B20 sensor on GPIO7 and turns on the LCD backlight
  • Reads: Asks the sensor for the temperature in Celsius
  • Converts: Turns the Celsius value into Fahrenheit
  • Shows the result: Prints Celsius on the first row and Fahrenheit on the second row, every 500 milliseconds
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-temperature-sensor-lcd */ #include <OneWire.h> #include <DallasTemperature.h> #include <DIYables_LCD_I2C.h> #define SENSOR_PIN 7 // The ESP32 C3 SuperMini pin connected to DS18B20 sensor's DQ pin OneWire oneWire(SENSOR_PIN); DallasTemperature DS18B20(&oneWire); DIYables_LCD_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows float tempC; // temperature in Celsius float tempF; // temperature in Fahrenheit void setup() { DS18B20.begin(); // initialize the sensor lcd.init(); // initialize the lcd lcd.backlight(); // open the backlight } void loop() { DS18B20.requestTemperatures(); // send the command to get temperatures tempC = DS18B20.getTempCByIndex(0); // read temperature in Celsius tempF = tempC * 9 / 5 + 32; // convert Celsius to Fahrenheit lcd.clear(); lcd.setCursor(0, 0); // display position lcd.print(tempC); // display the temperature in Celsius lcd.print((char)223); // display ° character lcd.print("C"); lcd.setCursor(0, 1); // display position lcd.print(tempF); // display the temperature in Fahrenheit lcd.print((char)223); // display ° character lcd.print("F"); delay(500); }

※ NOTE THAT:

The LCD I2C address can be different from each manufacturer. In the code, we used address of 0x27 that is specified by DIYables manufacturer

Detailed Instructions

Follow these bullets to run the project.

  • New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
  • Wire the parts: Connect the parts as shown in the wiring diagram.
  • Connect your board: Plug the ESP32 C3 Super Mini into your computer with a USB Type-C cable.
  • Open the IDE: Launch the Arduino IDE on your computer.
  • Select your board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Select your port: Choose the matching COM port.
  • Open the Library Manager: Click the Libraries icon on the left bar of the Arduino IDE.
  • Search for the sensor library: Type “DallasTemperature” in the search box, then look for the DallasTemperature library by Miles Burton.
  • Install the sensor library: Click the Install button.
  • Search for DallasTemperature created by Miles Burton , Tim Newsome , Guil Barros , Rob Tillaart and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Library Manager
Type:
All
Topic:
All
DallasTemperature by Miles Burton , Tim Newsome , Guil Barros , Rob Tillaart
Supports DS18B20, DS18S20, DS1822, DS1820 More info
3.9.0
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32C3 Dev Module on COM15
1
  • Install the dependency: When asked, click the Install All button to also install the OneWire library.
ESP32 C3 Super Mini onewire library
  • Search for the LCD library: Type “DIYables LCD I2C” in the search box, then look for the DIYables_LCD_I2C library by DIYables.
  • Install the LCD library: Click the Install button.
ESP32 C3 Super Mini DIYables LCD I2C library
  • Copy the code: Copy the code above and paste it into the Arduino IDE.
  • Upload the code: Click the Upload button to compile and upload the code to your ESP32 C3 Super Mini.
  • Test it: Make the sensor hotter or colder by holding the DS18B20 in your hand, or by putting a waterproof probe in hot and cold water.
  • See the result: Watch the temperature change on the LCD.
  • Pro Tip: If the LCD shows -127°C, check the DS18B20 wires. This value means the board cannot read the sensor.

If LCD displays nothing, see Troubleshooting on LCD I2C

Line-by-line Code Explanation

The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!

Application and Project Ideas

You can use this ESP32 C3 Super Mini temperature sensor LCD project as the base for many useful builds.

  • Room thermometer: Show the room temperature on your desk
  • Aquarium monitor: Show the water temperature of a fish tank with a waterproof probe
  • Fridge checker: Show how cold your fridge is without opening the door
  • Greenhouse display: Show the temperature near your plants
  • Coffee cup meter: Show when your drink is cool enough to enjoy

Challenge Yourself

Ready to do more with your ESP32 C3 Super Mini and LCD? Try these challenges.

  • Easy: Show only Celsius on the first row and your own text on the second row
  • Easy: Change the update time from 500 milliseconds to 2 seconds
  • Medium: Show the text "Too hot!" on the second row when the temperature is above 30°C
  • Medium: Add a button that switches the LCD between Celsius and Fahrenheit
  • Advanced: Show the lowest and highest temperature on the second row
  • Advanced: Connect two DS18B20 sensors on the same wire and show both on the LCD

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!