HomeArduino TutorialsInterface SHT21 Temperature and Humidity Sensor with Arduino | Display on Serial Monitor and I2C LCD

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.

How to Interface SHT21 Sensor with Arduino and Display Data on LCD

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.

SHT21 sensor module breakout board.

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.

Image showing Pinout of SHT21 Temperature and Humidity sensor module.

Here’s the pin description of the SHT21 sensor:

Pin NameFunctionDescription
VCCPower SupplyConnects to 3.3V or 5V from Arduino (depending on module)
GNDGroundConnects to Arduino ground
SDASerial Data LineUsed for I2C data communication
SCLSerial Clock LineUsed 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.

Image showing wiring connection between SHT21 sensor and Arduino Uno. They are connected using 2 pins via I2C.

Below is a typical connection setup using the Arduino UNO:

SHT21 PinArduino UNO Pin
VCC3.3V or 5V
GNDGND
SDAA4
SCLA5

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:

  1. Open your Arduino IDE.
  2. Go to Sketch → Include Library → Manage Libraries…
  3. In the search bar, type “SHT2x”.
  4. Install the library named “SHT2x by Rob Tillaart.”
SHT21 sensor connected to Arduino displaying temperature and humidity readings on a 16x2 I2C LCD screen.1

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.h library enables I2C communication between Arduino and the sensor.
  • The SHT2x object SHT21 is created to access the sensor’s functions.
  • In every loop cycle, SHT21.read() updates the sensor values.
  • The functions getTemperature() and getHumidity() 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.

Image showing the output of SHT21 sensor with Arduino. The temperature and humidity values are printed on the Serial console of the Arduino IDE.

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.

SHT21 Sensor module and LCD1602 are connected to Arduino using the same I2C pins.

Here’s how to connect the I2C LCD1602 to your Arduino UNO:

LCD PinArduino UNO Pin
VCC5V
GNDGND
SDAA4
SCLA5

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:

  1. Opening the Arduino IDE
  2. Going to Sketch → Include Library → Manage Libraries…
  3. Searching for “LiquidCrystal I2C”
  4. Installing the library by Frank de Brabander
Add the I2C LCD1602 liquidcrystal_I2C library to Arduino IDE.

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 with lcd.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.

Image showing the Temperature and Humidity values obtained from SHT21 and printed on the LCD1602.
Both are connected to Arduino UNO.

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:

I2C LCD1602 Arduino Tutorial

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 0x27 to 0x3F, 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

1 2 3

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

Subscribe
Notify of

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments