Environmental Temperature and Humidity Monitor
Introduction
Due to continuous rainy weather and large temperature differences recently, many microcontroller circuit board pins have become rusty. Therefore, placing a temperature and humidity sensor indoors is very necessary. When the humidity is appropriate, each microcontroller board can be taken out to be sun-dried to remove moisture. To prevent development boards from sitting idle forever, I took out my M61-32S-Kit and DIYed this project to meet my needs.
Parts List
Name | Quantity | Description |
AI-M61-32S-Kit | 1 | Core control MCU |
Panel Board | 1 | Simplifies circuit connections |
Jumper Wires | Several | Circuit connections |
DHT11 Temperature & Humidity Sensor | 1 | Detects temperature and humidity data, transmits to MCU |
Sliding Potentiometer | 1 | Controls the brightness of the 1.8-inch SPI screen |
1.8-inch SPI Screen | 1 | Displays temperature and humidity data |
Breadboard Power Module | 1 | Provides power to the breadboard |
Breadboard DC Power Cable | 1 | Supplies power to the breadboard |
Electronic Components Introduction
Breadboard Power Module
This module accepts two power input options: USB Type-A and DC (7–12V). Using two voltage conversion chips, it can convert input voltage to 3V or 5V (selectable via jumper cap).
DHT11 Temperature & Humidity Sensor
The DHT11 digital temperature and humidity sensor features a calibrated digital output. It contains a resistive humidity sensing component and an NTC temperature sensor. Each DHT11 sensor is calibrated in a highly accurate humidity calibration chamber. Calibration coefficients are stored in OTP memory and used during signal processing — no user recalibration required. Single-wire serial interface simplifies system integration. Compact size, ultra-low power consumption, and transmission distance over 20 meters.
Sliding Potentiometer
A sliding potentiometer typically has three pins: one input and two outputs. When connected in series to the circuit, the varying resistance controls output through voltage division.
1.8-inch SPI Screen
SPI-driven, using 8 wires:
- GND: Power ground
- VCC: 5V power
- SCL: SPI clock line
- SDA: SPI MOSI
- RES: Can connect to any MCU drive-capable pin (optional)
- DC: Optional
- CS: SPI chip select
- BL: Connect to ground to turn off the screen; connect to VCC for max brightness
For brightness control: connect BL to the sliding potentiometer and the other end of the potentiometer to GND.
Pin Mapping
AI-M61-32S | DHT11 | 1.8-inch SPI Screen | 3-Pin Sliding Potentiometer |
5V (to breadboard 5V) | 5V | 5V | |
GND (to breadboard GND) | GND | GND | Middle pin (to GND) |
IO13 (SCL) | SCL (clock) | ||
IO13 (MOSI) | SDA (data) | ||
IO12 (CS) | CS (chip select) | ||
BL (brightness control) | Left 1 | ||
IO26 | RES (reset) | ||
IO27 | DC (not used) | ||
IO25 | Signal pin |
Core Code Explanation
Sending Start Signal
bflb_gpio_set(gpio, DHT_PIN);
bflb_mtimer_delay_ms(50);
bflb_gpio_reset(gpio, DHT_PIN);
bflb_mtimer_delay_ms(20);
bflb_gpio_set(gpio, DHT_PIN);
bflb_mtimer_delay_us(30);
Receiving DHT11 Response
bflb_gpio_init(gpio, DHT_PIN, GPIO_INPUT | GPIO_PULLUP | GPIO_SMT_EN);
while (bflb_gpio_read(gpio, DHT_PIN) == 1) {}while (bflb_gpio_read(gpio, DHT_PIN) == 0) {}while (bflb_gpio_read(gpio, DHT_PIN) == 1) {}
Reading DHT11 Data
uint8_t data[5] = {0};for (int i = 0; i < 5; i++) {
data[i] = 0;
for (int j = 0; j < 8; j++) {
while (bflb_gpio_read(gpio, DHT_PIN) == 0) {}
bflb_mtimer_delay_us(30);
if (bflb_gpio_read(gpio, DHT_PIN) == 1) {
data[i] |= (1 << (7 - j));
...
Read more »