The AHT10 is a high-precision digital temperature and humidity sensor that provides accurate environmental readings using I2C communication. It is widely used in applications such as weather monitoring, industrial automation, and home automation. In this tutorial, we will interface the AHT10 sensor with an Arduino and display the measured temperature and humidity on an SSD1306 OLED screen.

 

Components Required

 

About the Components

AHT10 Temperature and Humidity Sensor

The AHT10 is a high-performance sensor offering:

  • Temperature range: -40°C to 85°C with ±0.3°C accuracy.
  • Humidity range: 0% to 100% RH with ±2% accuracy.
  • Communication protocol: I2C.
  • Supply voltage: 2.2V - 5.5V.
  • Application areas: Climate control, IoT-based monitoring, and industrial automation.

SSD1306 OLED Display

The SSD1306 OLED display module is a 128x64 pixel monochrome screen that:

  • Operates using I2C or SPI (this project uses I2C).
  • Provides high contrast and low power consumption.
  • Uses 3.3V or 5V for operation.
  • Application areas: Smart devices, wearable electronics, and information displays.

 

Arduino AHT10 Sensor Module Circuit Diagram

Arduino AHT10 Sensor Module Circuit Diagram

 

Arduino AHT10 Sensor Module Circuit Diagram

 

Connections 

Arduino Nano to OLED Display (0.96" I2C):

  • GND → GND
  • VDD → 5V
  • SCK → A5 (SCL)
  • SDA → A4 (SDA)

Arduino Nano to AHT10 Temperature & Humidity Sensor:

  • GND → GND
  • VCC → 5V
  • SCL → A5
  • SDA → A4
Arduino AHT10 Temperature and Humidity Sensor Module Circuit Diagram

In an I2C communication setup, each device connected to the I2C bus (SDA and SCL lines) has a unique 7-bit address that allows the Arduino Nano to differentiate between them.

I2C Addresses of Connected Devices:

  1. OLED Display (0.96" I2C SSD1306)
    • Default I2C Address: 0x3C (Common for most SSD1306 OLED displays)
  2. AHT10 Temperature & Humidity Sensor
    • Default I2C Address: 0x38

Explanation:

  • Both the OLED display and the AHT10 sensor share the same I2C bus, meaning they both connect to the same SDA (A4) and SCL (A5) pins on the Arduino Nano.
  • The Arduino communicates with each device by specifying its I2C address during data transmission.

 

Code Explanation

#include <Wire.h>
#include <Adafruit_AHTX0.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

  • Wire.h → Enables I2C communication.
  • Adafruit_AHTX0.h → Driver for the AHT10 temperature and humidity sensor.
  • Adafruit_SSD1306.h → Library to control the SSD1306 OLED display.
  • Adafruit_GFX.h → Graphics library for rendering text, shapes, etc.

Note: Install the required libraries from the Library Manager.

#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR   0x3C

  • Defines the OLED display resolution (128x64 pixels).
  • Defines the I2C address of the OLED (0x3C).

Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
Adafruit_AHTX0 aht;

  • Creates an object display for the OLED screen.
  • Creates an object aht for the AHT10 sensor.

void setup() {
  Serial.begin(115200);
  Serial.println();

  • Initializes serial communication at 115200 baud rate for debugging.

  if (!aht.begin()) {
    Serial.println(F("AHT10/AHT20 not found, check wiring!"));
    while (1) delay(10);
  }
  Serial.println(F("AHT10/AHT20 initialized"));

  • Calls aht.begin() to initialize the AHT10 sensor.
  • If sensor is not detected, it prints an error message and halts execution.
  • display.clearDisplay(); ensures the screen is cleared before writing.

  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);

  • Reads the temperature and humidity values from the AHT10 sensor.

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(25, 0);
  display.println(F("Temp -"));
  display.setCursor(35, 25);
  display.print(temp.temperature);
  display.println(F(" C"));
  display.display();

  • Clears the OLED display.
  • Sets text size to 2.
  • Sets text color to WHITE.
  • Positions text at (25, 0) and prints "Temp -" as a title.
  • Displays the temperature value in Celsius (°C).

  Serial.print(F("Temperature: "));
  Serial.print(temp.temperature);
  Serial.println(F(" C"));

  • Prints temperature to the Serial Monitor.

  delay(4000);

  • Pauses for 4 seconds before switching to humidity display.

  display.clearDisplay();
  display.setCursor(25, 0);
  display.println(F("Humd -"));
  display.setCursor(35, 25);
  display.print(humidity.relative_humidity);
  display.print(F(" %"));
  display.display();

  • Clears the OLED display.
  • Displays "Humd -" as a title.
  • Prints the humidity value in percentage (%).

  Serial.print(F("Humidity: "));
  Serial.print(humidity.relative_humidity);
  Serial.print(F(" %"));

  • Prints humidity to the Serial Monitor.

  delay(4000);

  • Pauses for another 4 seconds, then repeats the loop.

 

Results

The system successfully measures and displays temperature and humidity readings from the AHT10 sensor on an OLED screen. The Arduino Nano retrieves data from the AHT10 sensor over the I2C bus and alternates between temperature and humidity readings every 4 seconds.

AHT10 High Precision Digital Temperature and Humidity Sensor Module

This system provides a simple yet effective way to monitor environmental conditions using the AHT10 sensor and Arduino Nano.

 

Arduino AHT10 Sensor Module Code

#include <Wire.h>
#include <Adafruit_AHTX0.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR   0x3C

Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
Adafruit_AHTX0 aht;

void setup() {
  Serial.begin(115200);
  Serial.println();

  if (!aht.begin()) {
    Serial.println(F("AHT10/AHT20 not found, check wiring!"));
    while (1) delay(10);
  }
  Serial.println(F("AHT10/AHT20 initialized"));

  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (1);
  }
  display.clearDisplay();
}

void loop() {
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(25, 0);
  display.println(F("Temp -"));
  display.setCursor(35, 25);
  display.print(temp.temperature);
  display.println(F(" C"));
  display.display();

  Serial.print(F("Temperature: "));
  Serial.print(temp.temperature);
  Serial.println(F(" C"));

  delay(4000);

  display.clearDisplay();
  display.setCursor(25, 0);
  display.println(F("Humd -"));
  display.setCursor(35, 25);
  display.print(humidity.relative_humidity);
  display.print(F(" %"));
  display.display();

  Serial.print(F("Humidity: "));
  Serial.print(humidity.relative_humidity);
  Serial.print(F(" %"));

  delay(4000);
}

 

Video

Leave a comment

Please note, comments must be approved before they are published

Your cart

×