Build a Digital Thermostat Demo
SensorsAutomationActuators
Read a real temperature, compare it to a threshold, and physically switch a fan — closed-loop control you can actually see and feel.
8 real parts included
Total for this kit: 1,895.00 ฿
Doesn't include any order discount you may get at checkout.
What you'll need
ESP32-C3 SuperMini Development Board — Wi-Fi & Bluetooth, USB-C
670.00 ฿
AHT20 Temperature & Humidity Sensor Module — I2C
260.00 ฿
0.96" I2C OLED Display Module — 128×64, White
285.00 ฿
Logic-Level MOSFET Switch Module — 3-5V
23.00 ฿
5V Mini DC Fan — 40mm
132.00 ฿
830-Point Solderless Breadboard
125.00 ฿
Jumper Wire Kit — Male-Male, Male-Female, Female-Female
220.00 ฿
USB-C Data & Charging Cable — 1m
180.00 ฿
Wiring Diagram
Starter Code
// Digital Thermostat Demo — ESP32-C3 SuperMini + AHT20 + OLED + MOSFET fan
#include <Wire.h>
#include <Adafruit_AHTX0.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// --- Pins — adjust to match your board's silkscreen if different ---
#define SDA_PIN 8
#define SCL_PIN 9
#define FAN_MOSFET_PIN 3
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C
Adafruit_AHTX0 aht;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const float TEMP_THRESHOLD_C = 27.0; // fan turns on above this
const float HYSTERESIS_C = 0.5; // fan turns off once temp drops this far below threshold
bool fanOn = false;
void setup() {
Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);
pinMode(FAN_MOSFET_PIN, OUTPUT);
digitalWrite(FAN_MOSFET_PIN, LOW); // fan off at boot
if (!aht.begin()) {
Serial.println("AHT20 not found — check wiring");
while (1) delay(1000);
}
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
Serial.println("SSD1306 not found — check wiring");
while (1) delay(1000);
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
}
void updateFan(float tempC) {
if (!fanOn && tempC >= TEMP_THRESHOLD_C) {
fanOn = true;
} else if (fanOn && tempC <= (TEMP_THRESHOLD_C - HYSTERESIS_C)) {
fanOn = false;
}
digitalWrite(FAN_MOSFET_PIN, fanOn ? HIGH : LOW);
}
void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
float tempC = temp.temperature;
float rh = humidity.relative_humidity;
updateFan(tempC);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 0);
display.print(tempC, 1);
display.println(" C");
display.setTextSize(1);
display.setCursor(0, 20);
display.print("Humidity: ");
display.print(rh, 0);
display.println(" %");
display.setCursor(0, 35);
display.print("Threshold: ");
display.print(TEMP_THRESHOLD_C, 1);
display.println(" C");
display.setCursor(0, 50);
display.print("Fan: ");
display.println(fanOn ? "ON" : "OFF");
display.display();
Serial.print("Temp: "); Serial.print(tempC);
Serial.print(" C Humidity: "); Serial.print(rh);
Serial.print(" % Fan: "); Serial.println(fanOn ? "ON" : "OFF");
delay(1000);
}Not sure about a step? Ask us