XIAO Room TEMP and HUMIDITY Meter

by Arnov Sharma in Circuits > Microcontrollers

1431 Views, 14 Favorites, 0 Comments

XIAO Room TEMP and HUMIDITY Meter

13 (46).gif
14 (50).gif
0001.jpg

Greetings and welcome back.

So here's something cool: a room temperature and humidity meter that measures current room temperature and humidity and displays the readings on an SSD1306 OLED Screen.

AHT10 is being used here to get the Temperature and humidity data, and the whole setup is driven by an XIAO M0 MCU.

This whole meter is powered through the onboard 18650 lithium Cell through a power management IC Setup that boosts the 3.7V of the lithium Cell to 5V for the MCU, display, and sensor to work.

This Instructables is about how this setup was made and how you can make it in few easy steps, so let's get started.

Supplies

These are the materials used in this built-

  • Custom PCB (Provided by Seeed Studio)
  • XIAO M0 MCU
  • SSD1306 OLED Screen
  • AHT10 TEMP and HUMIDITY SENSOR
  • Li-Ion Cell 3.7V 2200mAh
  • IP5306 IC
  • 1uf CAP
  • 10K Resistor
  • 1uH Inductor
  • Female Header Pins
  • THT USB Mini Port
  • SMD 18650 Cell Holder
  • SMD LED

AHT10 Sensor

aht10_MpcqJDDr6U.jpg

The AHT10 Temp and Humidity Sensor Module is a compact and highly accurate sensor designed to measure temperature and humidity in various applications. The module integrates a high-performance AHT10 sensor chip, which utilizes a capacitive sensing element to detect changes in temperature and humidity.

It provides reliable and precise measurements with a temperature accuracy of ±0.3°C and a humidity accuracy of ±2% RH.

The AHT10 module operates between 1.6V and 6V, which is ideal if we use an external 5V source to power this sensor along with the SSD1306 display and Arduino board.

It communicates with the host device through a standard I2C interface, allowing for easy integration and data retrieval. With its low power consumption and fast response time, the AHT10 Temp and Humidity Sensor Module is an excellent choice for applications such as environmental monitoring, weather stations, HVAC systems, and industrial automation.

PCB Design

SCH_page-0001.jpg
0002.JPG

The power management IC setup and the XIAO MCU, which is connected to the SSD1306 Display and AHT10 Sensor, are the major two elements of the PCB Design for this project.

The IP5303 IC, which has the same footprint as the IP5306 but a different current output, is mentioned in the schematic but was not utilised in this project. Whereas IP5303 can deliver 5V 1A, IP5306 can deliver 5V 2A.

The IP5306 IC is a power management IC that can deliver a consistent 5V output from a 3.7V Li-ion cell. It also has HIGH and LOW CUT functionality, an internal boost module option, and four battery fuel indication LEDs. Power banks, solar chargers, and other products are relatively common places to find this IC.

The second section is made up of an XIAO M0 DEV Board that makes use of a Microchip SAMD21G18A microcontroller. It has a distinct form factor and is smaller in size than an Arduino board. A powerful 32-bit ARM Cortex-M0+ processor with 256KB of flash memory and 32KB of SRAM, the SAMD21G18A operates at 48 MHz.

Using I2C, XIAO is connected to the AHT10 Sensor and SSD1306 Display. The SDA and SCL Pins of the display and sensor are connected in parallel with D4 and D5 of XIAO.

Power for the XIAO, Display, and TEMP sensor is supplied by the IP5306 Setup.

After the schematic is finished, we move on to the PCB editing process, which begins with inserting all of the SMD components (mostly those used in the IP5306 Setup) on the bottom side of the PCB and the XIAO, Display with AHT10 sensor, on the top side.

After that, PCB data is created and sent to Seeed Studio for samples.

Seeed Studio Fusion Service

01 (44).gif
02 (48).gif
IMG_20230727_220255.jpg

After finalizing the PCB and generating its Gerber data, I sent it to SEEED Studio for samples.

The PCB was ordered in Blue solder mask with white silkscreen.

PCBs were received in a week, and their quality was super good considering the rate, which was also pretty low.

Seeed Fusion PCB Service offers one-stop prototyping for PCB manufacture and PCB assembly, and as a result, they produce superior quality PCBs and fast turnkey PCBAs within 7 working days.

This ROOM TEMP and HUMIDITY BOARD's PCB quality is SUPER COOL!

Seeed Studio Fusion PCB Assembly Service takes care of the entire fabrication process, from Seeed Studio Fusion Agile manufacturing and Hardware Customization to parts sourcing, assembly, and testing services, so you can be sure that they are getting a quality product.

After gauging market interest and verifying a working prototype, Seeed Propagate Service can help you bring the product to market with professional guidance and a strong network of connections.

Next is the PCB assembly process.

PCB Assembly Process

03 (47).gif
04 (47).gif
05 (48).gif
06 (50).gif
07 (50).gif
08 (50).gif
  • We start the PCB assembly Process by first adding solder paste to the component pads on the bottom side.
  • Next, we add all the SMD components on the bottom side to their locations using an ESD tweezer.
  • In order to heat the PCB to the solder paste melting temperature, we carefully lift the Board and place it on an SMT hotplate. Solder paste melts, and components are attached to their pads as soon as the Board reaches that temperature.
  • Next, we gather all the THT Components like the display, female header pins, SHT10 Sensor, USB Port, and switch and place them in their locations on the top side of the PCB.
  • We then solder THT component Pads with a soldering iron.

The board assembly is complete.

Power Source

09 (50).gif
10 (45).gif

The entire system is powered by a 3.7V, 2200mAh 18650 lithium-ion battery, and the XIAO, OLED, and AHT10 are powered by a reliable 5V output from the IP5306 power management IC.

We insert an 18650 cell into its holder by confirming the polarity, and we then use a multimeter to measure the output voltage, which should be 5 volts; this confirms that the setup is functioning.

CODE

Here's the code that was used, and it's a simple one.

#include <Wire.h>
#include <AHTxx.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);

float ahtValue;                               //to store T/RH result

AHTxx aht10(AHTXX_ADDRESS_X38, AHT1x_SENSOR); //sensor address, sensor type

void setup()
{
  #if defined(ESP8266)
  WiFi.persistent(false);  //disable saving wifi config into SDK flash area
  WiFi.forceSleepBegin();  //disable AP & station by calling "WiFi.mode(WIFI_OFF)" & put modem to sleep
  #endif

  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();
  Serial.begin(115200);
  Serial.println();
  
  while (aht10.begin() != true) //for ESP-01 use aht10.begin(0, 2);
  {
    Serial.println(F("AHT1x not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free
    delay(5000);
  }
  Serial.println(F("AHT10 OK"));
  //Wire.setClock(400000); //experimental I2C speed! 400KHz, default 100KHz
}

void loop()
{
  /* DEMO - 1, every temperature or humidity call will read 6-bytes over I2C, total 12-bytes */
  Serial.println();
  Serial.println(F("DEMO 1: read 12-bytes"));
  ahtValue = aht10.readTemperature(); //read 6-bytes via I2C, takes 80 milliseconds
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(30, 0);
  display.println(F("Temp-"));

//  Serial.print(F("Temperature...: "));
  
  if (ahtValue != AHTXX_ERROR) //AHTXX_ERROR = 255, library returns 255 if error occurs
  {


  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(35, 25);
  display.println(ahtValue);
  display.display();
//    Serial.print(ahtValue);
   
  }
  else
  {
    printStatus(); //print temperature command status
    if   (aht10.softReset() == true) Serial.println(F("reset success")); //as the last chance to make it alive
    else                             Serial.println(F("reset failed"));
  }

  delay(2000); //measurement with high frequency leads to heating of the sensor, see NOTE
  ahtValue = aht10.readHumidity(); //read another 6-bytes via I2C, takes 80 milliseconds
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(30, 0);
  display.println(F("Humd-"));
//  Serial.print(F("Humd-"));
  
  if (ahtValue != AHTXX_ERROR) //AHTXX_ERROR = 255, library returns 255 if error occurs
  {
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(35, 25);
  display.println(ahtValue);
  display.display();
 //   Serial.println(F(" +-2%"));
  }
  else
  {
    printStatus(); //print humidity command status
  }


  delay(2000); //measurement with high frequency leads to heating of the sensor, see NOTE


  /* DEMO - 2, temperature call will read 6-bytes via I2C, humidity will use same 6-bytes */
  Serial.println();
  Serial.println(F("DEMO 2: read 6-byte"));


  ahtValue = aht10.readTemperature(); //read 6-bytes via I2C, takes 80 milliseconds


  Serial.print(F("Temperature: "));
  
  if (ahtValue != AHTXX_ERROR) //AHTXX_ERROR = 255, library returns 255 if error occurs
  {
    Serial.print(ahtValue);
    Serial.println(F(" +-0.3C"));
  }
  else
  {
    printStatus(); //print temperature command status
  }


  ahtValue = aht10.readHumidity(AHTXX_USE_READ_DATA); //use 6-bytes from temperature reading, takes zero milliseconds!!!


  Serial.print(F("Humidity...: "));
  
  if (ahtValue != AHTXX_ERROR) //AHTXX_ERROR = 255, library returns 255 if error occurs
  {
    Serial.print(ahtValue);
    Serial.println(F(" +-2%"));
  }
  else
  {
    printStatus(); //print temperature command status not humidity!!! RH measurement use same 6-bytes from T measurement
  }


  delay(10000); //recomended polling frequency 8sec..30sec
}


void printStatus()
{
  switch (aht10.getStatus())
  {
    case AHTXX_NO_ERROR:
      Serial.println(F("no error"));
      break;


    case AHTXX_BUSY_ERROR:
      Serial.println(F("sensor busy, increase polling time"));
      break;


    case AHTXX_ACK_ERROR:
      Serial.println(F("sensor didn't return ACK, not connected, broken, long wires (reduce speed), bus locked by slave (increase stretch limit)"));
      break;


    case AHTXX_DATA_ERROR:
      Serial.println(F("received data smaller than expected, not connected, broken, long wires (reduce speed), bus locked by slave (increase stretch limit)"));
      break;


    case AHTXX_CRC8_ERROR:
      Serial.println(F("computed CRC8 not match received CRC8, this feature supported only by AHT2x sensors"));
      break;


    default:
      Serial.println(F("unknown status"));    
      break;
  }
}


This Sketch is for reading temperature and humidity data from an AHT10 sensor and displaying it on an OLED screen using an Arduino or similar microcontroller platform. Here's a breakdown of the code's structure and functionality:

Include Statements:

  • The code starts by including necessary libraries: Wire.h, AHTxx.h, Adafruit_SSD1306.h, and Adafruit_GFX.h. These libraries provide functions for I2C communication, working with the AHT10 sensor, and interfacing with the SSD1306 OLED display.

Macro Definitions:

  • Macro definitions are provided for the OLED display's width, height, and I2C address.

OLED Display Initialization:

  • The Adafruit_SSD1306 library is used to initialize the OLED display with the specified dimensions and I2C address.

Variable and Object Declarations:

  • ahtValue: A floating-point variable to store temperature or humidity readings from the AHT10 sensor.
  • aht10: An object of the AHTxx class representing the AHT10 sensor. It's initialized with the sensor's I2C address and sensor type.

setup() Function:

  • Disables saving WiFi configuration on ESP8266 (if defined) and puts the WiFi module to sleep.
  • Initializes the OLED display.
  • Initializes the serial communication.
  • Checks if the AHT10 sensor is connected and calibrated. If not, it retries every 5 seconds until successful.
  • Prints a message to indicate that the sensor is ready.

loop() Function:

  • Demonstrates two types of readings from the AHT10 sensor.

DEMO 1:

  • Reads temperature using aht10.readTemperature() and displays it on the OLED screen.
  • If the reading is successful, the temperature is displayed on the screen. If not, it tries a soft reset and prints the reset status.
  • Delays for 2 seconds to avoid frequent measurements.

DEMO 2:

  • Reads temperature and humidity sequentially using aht10.readTemperature() and aht10.readHumidity(AHTXX_USE_READ_DATA) respectively.
  • Prints temperature and humidity readings along with their respective accuracies.
  • Delays for 10 seconds.

printStatus() Function:

  • Prints status messages based on the error code returned by aht10.getStatus().
  • The possible statuses include:AHTXX_NO_ERROR: No error.
  • AHTXX_BUSY_ERROR: Sensor is busy, increase polling time.
  • AHTXX_ACK_ERROR: Sensor didn't return ACK, indicating connection issues.
  • AHTXX_DATA_ERROR: Received data smaller than expected, indicating connection issues.
  • AHTXX_CRC8_ERROR: Computed CRC8 doesn't match received CRC8.
  • Default: Unknown status.

Overall, this code initializes the OLED display, reads temperature and humidity data from an AHT10 sensor, displays the data on the screen, handles error statuses, and demonstrates different methods of reading the sensor data. The code is well-commented to provide explanations at each step.

RESULT

13 (46).gif
14 (50).gif

Here's the result of this build: a room temperature and humidity Meter capable of measuring real-time room temperature and humidity using the onboard AHT10 Sensor. Because of the onboard lithium cell, we don't need any external power source to run this setup.

Uses of this Meter are various, like we can keep this at our desk for getting the real time TEMP of Room or keep it in a cool environment like a freezer or some hot area like in kitchen, and it will jeep you updated about the ambient temperature and humidity at that area.

Leave a comment if you need any help regarding this project, This is it for today folks.

Thanks to Seeed Studio for supporting this project, you guys can check them out if you need great PCB and stencil service for less cost and great quality.

And I'll be back with a new project pretty soon!