This project combines temperature and humidity monitoring with presence detection and automatic fan control on an ESP32. The round 1.28-inch display shows real-time DHT22 sensor readings, while the HLK-LD2410C radar module detects nearby movement. When motion is detected, the system can automatically trigger a brushed DC motor (fan) via an NPN transistor driver circuit.
The guide provides a complete wiring diagram connecting the GC9A01A display, DHT22 sensor, presence radar, and motor control circuit to the ESP32. Assembly steps cover safe component connection with power disconnected, sensor testing procedures, and firmware upload. Readers will receive the full source code, parts list, and step-by-step instructions to build a smart ventilation controller with visual feedback.
Wiring diagram

Gather all the parts
Assemble it in 5 steps
1. Conecta la pantalla sin alimentación
Desenchufa el USB. Conecta VCC a 3V3 y GND a GND. Conecta SCL a GPIO18, SDA a GPIO23, DC a GPIO27, CS a GPIO25 y RST a GPIO26.
- No uses VIN ni 5V. Guíate por las etiquetas: VCC y SDA son ambos morados.
2. Añade el DHT22 V182
Con el USB desconectado, conecta VCC a 3V3, GND a GND y DATA a GPIO32. Sigue las etiquetas del módulo, no la posición de los pines. Comparte alimentación y tierra con la pantalla. No añadas otra resistencia.
3. Prueba el sensor
Conecta el USB y pulsa Deploy. La pantalla muestra temperatura y humedad sin Wi-Fi. Si aparece Sin lectura, revisa los tres cables del sensor.
4. Añade el radar de presencia
Desenchufa el USB. Identifica los pines por las etiquetas impresas, no por la orientación del dibujo. El orden numerado por Hi-Link es 1 TX, 2 RX, 3 OUT, 4 GND y 5 VCC. Conecta VCC del radar a VIN (5 V del USB), GND a GND y OUT a GPIO33. Deja TX y RX sin conectar; solo se usan para comunicación serie y no hacen falta para detectar presencia. Reconecta el USB y prueba entrando y saliendo de la zona de detección. La pantalla conserva temperatura y humedad y muestra persona detectada cuando OUT se activa.
- No conectes VCC del radar a 3V3 ni una fuente externa a VIN mientras uses USB.
5. Cablea el motor con ambas alimentaciones desconectadas
Conecta GPIO21 a la base mediante la resistencia de 220 Ω. Une el emisor a GND común y el colector a M-. Conecta el diodo en paralelo con el motor, con la franja gris hacia M+ y el extremo sin franja hacia M-. Usa una fuente independiente del voltaje nominal del motor, positivo a M+ y negativo a GND del ESP32. El programa enciende a partir de 25 °C y apaga a 24 °C o menos. Entre ambos umbrales conserva el estado anterior; también apaga si falla la lectura.
- Verifica las patas B, C y E en la hoja de datos de tu transistor exacto. No siguen el mismo orden en todos los modelos.
- No conectes el motor a 3V3, VIN ni a un GPIO. Antes de alimentarlo verifica que la corriente de arranque o bloqueo del motor sea compatible con la corriente que el transistor puede conmutar con esta resistencia. Si no, usa un controlador de motor dimensionado para esa corriente.
Review all connections
1. Connections between "tft" and "ESP32"
2. Connections between "sensor" and "ESP32"
3. Connections between "radar" and "ESP32"
4. Connections between "base_resistor" and "ESP32"
5. Connections between "transistor" and "ESP32"
6. Connections between "motor" and "ESP32"
7. Connections between "flyback" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <Adafruit_GC9A01A.h>
#include <DHT.h>
Adafruit_GC9A01A tft(25, 27, 26);
DHT sensor(32, DHT22);
String oldTemp, oldRH, oldStatus;
constexpr int radarOutPin = 33;
constexpr int motorPin = 21;
bool motorOn = false;
uint32_t lastRead;
void center(int y, int size, uint16_t color, const String &text) {
tft.setTextSize(size);
tft.setTextColor(color);
tft.setCursor((240 - 6 * size * int(text.length())) / 2, y);
tft.print(text);
}
void update(String &old, const String &text, int y, int size, uint16_t color) {
if (old == text) return;
old = text;
tft.fillRect(40, y, 160, size * 8, 0);
center(y, size, color, text);
}
void setup() {
pinMode(motorPin, OUTPUT);
digitalWrite(motorPin, LOW);
pinMode(radarOutPin, INPUT_PULLDOWN);
tft.begin(10000000);
tft.fillScreen(0);
tft.drawCircle(120, 120, 116, 0x03EF);
center(31, 2, 0xFFFF, "DHT22");
center(65, 2, 0xFFE0, "Temperatura");
center(124, 2, 0x07FF, "Humedad");
update(oldStatus, "Iniciando...", 189, 1, 0xFFFF);
sensor.begin();
lastRead = millis();
}
void loop() {
bool present = digitalRead(radarOutPin) == HIGH;
// OUT indica presencia; no hace falta conectar TX ni RX.
static int lastPresence = -1;
if (lastPresence != present) {
lastPresence = present;
tft.fillRoundRect(53, 200, 134, 18, 5, present ? 0x07E0 : 0x2104);
center(205, 1, present ? 0x0000 : 0xFFFF,
present ? "persona detectada" : "Sin presencia");
}
uint32_t now = millis();
if (now - lastRead < 2500) return;
lastRead = now;
float h = sensor.readHumidity();
float t = sensor.readTemperature();
bool ok = isfinite(h) && isfinite(t) && h >= 0 && h <= 100 && t >= -40 && t <= 80;
// Compare in tenths, matching the DHT22 and the displayed reading.
const int tenths = ok ? lroundf(t * 10.0f) : 0;
if (!ok || tenths <= 240) motorOn = false;
else if (tenths >= 250) motorOn = true;
digitalWrite(motorPin, motorOn ? HIGH : LOW);
update(oldTemp, ok ? String(t, 1) + " C" : "-- C", 88, 3, 0xFFE0);
update(oldRH, ok ? String(h, 1) + " %" : "-- %", 147, 3, 0x07FF);
update(oldStatus, ok ? (motorOn ? "Motor: ON" : "Motor: OFF") : "Sin lectura: revisa DATA", 189, 1, ok ? 0x07E0 : 0xF800);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




