How to Interface SHT21 Sensor with Arduino and Display Data on LCD
In this tutorial, we will learn how to interface the SHT21 temperature and humidity sensor with Arduino. The SHT21 is a highly accurate digital sensor that communicates using the I2C protocol, making it very easy to connect with microcontrollers like Arduino.
We will start by understanding the pinout and connection of the SHT21 sensor. After that, we’ll write an Arduino code to read the temperature and humidity data and display it on the Serial Monitor.
Prerequisites:
This project will use LCD1602 to display the Temperature and Humidity values obtained from the SHT21 Sensor. You can check out the tutorial for more information about how to interface the LCD1602 with Arduino using I2C.

Introduction to SHT21 Sensor
The SHT21 is a digital temperature and humidity sensor developed by Sensirion. It is compact, highly accurate, and easy to use with Arduino or other microcontrollers. The sensor uses the I2C communication protocol, which means it requires only two data lines — SDA (data) and SCL (clock) — to transfer information.
Inside the sensor, a precise humidity and temperature sensing element is combined with an integrated analog-to-digital converter and a digital signal processing unit. This allows the SHT21 to deliver calibrated and linearized digital output, so there’s no need for complex signal conditioning or external calibration.
Features and Specifications of SHT21
Here are some key features and specifications that make the SHT21 a popular choice for Arduino-based temperature and humidity monitoring projects:
- Operating Voltage: 2.1V to 3.6V (works fine with Arduino 3.3V or 5V via logic level conversion)
- Interface: I2C communication protocol
- Temperature Range: –40°C to +125°C
- Humidity Range: 0% to 100% RH
- Typical Accuracy:
- ±2% RH (Humidity)
- ±0.3°C (Temperature)
- Low Power Consumption: Ideal for battery-operated or low-power IoT devices
- Fast Response Time: Quick and reliable readings for real-time monitoring
- Factory-Calibrated: No need for additional calibration steps
- Compact Size: Fits easily in small enclosures and embedded systems
These specifications make the SHT21 an excellent choice for weather monitoring, data logging, and indoor environmental control projects.
Applications of SHT21 in Arduino Projects
The SHT21 sensor is widely used in many Arduino IoT and automation projects due to its accuracy, small size, and simple I2C interface. Some common applications include:
- Weather Stations: To measure real-time temperature and humidity levels.
- Home Automation Systems: For controlling air conditioners, humidifiers, and ventilation systems.
- Greenhouse Monitoring: To maintain optimal growing conditions for plants.
- Data Logging Projects: To record environmental data over time.
- Portable Devices: Used in small battery-powered gadgets for climate tracking.
SHT21 Pinout and Connection with Arduino
Let’s start by taking a look at the pinout of the SHT21 sensor to understand its available connections and functions. Once we are familiar with the pins, we’ll move on to the wiring part, where we’ll see how to properly connect the SHT21 to an Arduino board for data communication.
SHT21 Pinout
The SHT21 sensor comes with a simple 4-pin interface, which makes it very easy to connect with an Arduino. Since it communicates over the I2C protocol, only two pins are used for data transfer — SDA and SCL. The remaining two pins are for power supply.
Here’s the pin description of the SHT21 sensor:
| Pin Name | Function | Description |
|---|---|---|
| VCC | Power Supply | Connects to 3.3V or 5V from Arduino (depending on module) |
| GND | Ground | Connects to Arduino ground |
| SDA | Serial Data Line | Used for I2C data communication |
| SCL | Serial Clock Line | Used for I2C clock signal |
Circuit Diagram for SHT21 with Arduino
The circuit diagram for connecting the SHT21 sensor to Arduino is very straightforward. The image below shows how to connect the SHT21 sensor with Arduino UNO.
Below is a typical connection setup using the Arduino UNO:
| SHT21 Pin | Arduino UNO Pin |
|---|---|
| VCC | 3.3V or 5V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
If you are using another board such as Arduino Mega or Arduino Nano, the I2C pins might be different. For example:
- On Arduino Mega, SDA = Pin 20, SCL = Pin 21
- On Arduino Leonardo, SDA = Pin 2, SCL = Pin 3
This connection allows the Arduino to communicate with the SHT21 sensor using its built-in Wire (I2C) library. Once the wiring is complete, you can power up the Arduino and start reading data from the sensor using the Wire library.
Arduino Code to Read Temperature and Humidity from SHT21
In this section, we’ll write and test the Arduino code to read temperature and humidity from the SHT21 sensor using the I2C communication protocol. Once connected properly, the SHT21 provides precise and stable readings, which can be easily displayed on the Serial Monitor.
Required Libraries
To communicate with the SHT21 sensor, we’ll use the SHT2x library by Rob Tillaart. This library handles all the low-level I2C communication and provides simple functions to get accurate readings directly from the sensor.
Follow these steps to install the library:
- Open your Arduino IDE.
- Go to Sketch → Include Library → Manage Libraries…
- In the search bar, type “SHT2x”.
- Install the library named “SHT2x by Rob Tillaart.”
Once installed, you can use the library to easily read both temperature and humidity values from the SHT21 sensor.
Arduino Sketch for SHT21
Here’s the tested and working Arduino code to read data from the SHT21 sensor periodically and display it on the Serial Monitor:
#include <Wire.h>
#include <SHT2x.h>
SHT2x SHT21;
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("SHT21 Temperature and Humidity Sensor");
}
void loop() {
SHT21.read();
float humidity = SHT21.getHumidity();
float temperature = SHT21.getTemperature();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %RH");
Serial.println("-------------------------");
delay(1000);
}Code Explanation:
- The
Wire.hlibrary enables I2C communication between Arduino and the sensor. - The
SHT2xobjectSHT21is created to access the sensor’s functions. - In every loop cycle,
SHT21.read()updates the sensor values. - The functions
getTemperature()andgetHumidity()are then used to read the latest temperature and humidity data. - The readings are printed on the Serial Monitor every 1 second.
This version of the code provides reliable and fast readings with minimal delay.
Output on Serial Monitor
Once the code is uploaded successfully, open the Serial Monitor from the Arduino IDE (Tools → Serial Monitor) and set the baud rate to 9600.
The values will update every second. You can test the sensor’s responsiveness by blowing gently over it or placing your finger on it. You’ll notice the humidity value rise quickly while the temperature also changes slightly.
This confirms that your SHT21 sensor is properly interfaced with Arduino and accurately reading environmental data.
Display SHT21 Data on 16×2 I2C LCD
Now that we have successfully displayed temperature and humidity readings from the SHT21 sensor on the Serial Monitor, let’s take the project one step further.
In this section, we’ll learn how to show the same readings on a 16×2 I2C LCD display. This makes the project more practical, allowing you to view real-time sensor data without needing to connect your Arduino to a computer.
I2C LCD1602 Connection with Arduino
The I2C LCD1602 display uses the same SDA and SCL pins as the SHT21 sensor, which means both can share the same I2C bus. This setup is simple and efficient since I2C supports multiple devices on a single bus.
The Image below shows how SHT21 sensor module and LCD1602 are connected to the Arduino UNO using the same I2C pins.
Here’s how to connect the I2C LCD1602 to your Arduino UNO:
| LCD Pin | Arduino UNO Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
Tip: Both the SHT21 and the LCD use I2C, so you can connect their SDA lines together and SCL lines together. Just ensure each device has a unique I2C address.
Configuring the LCD1602 Library
Before running the code, make sure you have installed the LiquidCrystal_I2C library. You can do this by:
- Opening the Arduino IDE
- Going to Sketch → Include Library → Manage Libraries…
- Searching for “LiquidCrystal I2C”
- Installing the library by Frank de Brabander
Modify the Code to Print on LCD
We’ll now modify our previous SHT21 code to display the sensor readings on both the Serial Monitor and the I2C LCD. The LCD will show the temperature on the first line and the humidity on the second line, updating every second.
Here’s the complete and tested Arduino code that displays SHT21 sensor data on the Serial Monitor and I2C LCD1602 display:
#include <Wire.h>
#include <SHT2x.h>
#include <LiquidCrystal_I2C.h>
SHT2x SHT21;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 to 0x3F if your LCD uses a different address
void setup() {
Serial.begin(9600);
Wire.begin();
lcd.init();
lcd.backlight();
Serial.println("SHT21 with I2C LCD Display");
}
void loop() {
SHT21.read();
float humidity = SHT21.getHumidity();
float temperature = SHT21.getTemperature();
// Print data on Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %RH");
Serial.println("-------------------------");
// Display data on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature, 1);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humi: ");
lcd.print(humidity, 1);
lcd.print(" %");
delay(1000);
}Code Explanation:
- The LiquidCrystal_I2C library controls the LCD over I2C.
- The LCD is initialized using
lcd.init()and its backlight turned on withlcd.backlight(). - Inside the loop,
SHT21.read()updates the sensor data before printing. - The temperature and humidity values are displayed on both the Serial Monitor and the LCD screen every second.
- The I2C address of the LCD is set to 0x27, but some modules use 0x3F, so update it if your display doesn’t show text.
Output on the LCD1602
Once the code is uploaded successfully, the LCD should print the Temperature and Humidity values as shown in the image below.

These values will update every second.
Link to Detailed LCD Tutorial
If you want to learn more about how the I2C LCD1602 display works — including how to find its I2C address, create custom characters, or troubleshoot display issues — check out my full guide here:
This detailed post explains everything you need to know about using I2C LCDs with Arduino and will help you customize your display further for other projects.
Troubleshooting SHT21 with Arduino
Even though the SHT21 sensor is quite reliable, you may encounter a few issues during setup or testing. Here are some common problems and quick fixes to help you troubleshoot effectively:
1. No Data or “nan” Readings on Serial Monitor
If the Serial Monitor shows “nan” or blank readings for temperature and humidity:
- Double-check SDA and SCL connections — they must match the Arduino’s I2C pins.
- Ensure the sensor is powered correctly (typically 3.3V or 5V, depending on module version).
- Make sure you have called
SHT21.read()before accessing temperature or humidity values. - Run an I2C Scanner sketch to confirm that the Arduino is detecting the SHT21 module.
2. LCD Display Not Showing Any Text
If your LCD1602 I2C screen lights up but shows no characters:
- Try changing the I2C address in your code from
0x27to0x3F, or vice versa. - Verify that the LiquidCrystal_I2C library is correctly installed.
- Adjust the contrast potentiometer on the LCD module until text becomes visible.
- Check that both the LCD and SHT21 share the same I2C lines (SDA, SCL) properly.
3. Fluctuating or Inaccurate Readings
If temperature or humidity values jump too frequently:
- Allow the sensor a few seconds to stabilize after powering up.
- Avoid touching or breathing near the sensor during testing, as it affects humidity levels.
- Add a small delay (e.g., 1–2 seconds) between consecutive readings.
- You can also average multiple samples in code to get smoother results.
4. I2C Communication Errors
If you get errors related to I2C communication:
- Use shorter wires (less than 20 cm) to reduce noise on the I2C bus.
- Add 4.7kΩ pull-up resistors on SDA and SCL lines if your module doesn’t already include them.
- Ensure there are no address conflicts between multiple I2C devices connected to the same bus.
5. LCD or Sensor Not Powering On
If neither device seems to be working:
- Check your Arduino’s 5V and GND pins with a multimeter.
- Make sure no wires are loose or connected to the wrong pins.
- Try powering the setup via USB directly instead of external adapters to rule out voltage issues.
Conclusion
In this tutorial, we learned how to interface the SHT21 temperature and humidity sensor with Arduino and display real-time data on both the Serial Monitor and a 16×2 I2C LCD display. We started by understanding the pinout and connections of the SHT21, followed by writing the Arduino code to read temperature and humidity using the SHT2x library. We then enhanced the project by integrating the I2C LCD1602, allowing the readings to be displayed without relying on a computer connection.
This project is not only simple but also highly practical for IoT and environmental monitoring applications. By combining the accuracy of the SHT21 sensor with the readability of an LCD display, you can easily build smart weather stations, greenhouse monitors, or indoor air quality systems. It’s a great step toward learning sensor interfacing, I2C communication, and data visualization with Arduino — all essential skills for anyone exploring embedded systems or home automation projects.
Browse More Arduino Tutorials
Arduino UART Tutorial: Step-by-Step Guide to Serial Communication
Arduino ADC and analogRead() Explained – Read Analog Voltage Easily
Complete Arduino I2C Tutorial with Examples: Wire Library & Projects
Mastering Arduino’s delayMicroseconds() Function: A Practical Guide
Arduino PWM and analogWrite() Explained: A Complete Beginner’s Guide
Arduino External Interrupts Guide: How to Use INT0 & INT1 Pins for Responsive Projects
How to Interface I2C LCD1602 Display with Arduino (With Custom Characters)
Arduino SHT21 Project Download
Info
You can help with the development by DONATING Below.
To download the project, click the DOWNLOAD button.
Arduino SHT21 FAQs
You can use the Arduino I2C Scanner sketch to detect all connected I2C devices and confirm their addresses before uploading the main code.
This usually happens due to loose connections or power issues. Make sure the sensor is powered at 3.3V or 5V (depending on module type) and that SDA/SCL pins are correctly connected.
Yes, the SHT21 works with all Arduino boards that support I2C communication. Just check the correct SDA and SCL pins for your board.
You can average multiple sensor readings or add a small delay between measurements to stabilize data output.
Absolutely! You can use OLED, TFT, or even serial displays with minor code modifications, as long as they support I2C or SPI communication.







