GPS speedometer and clock
A bike or car speedometer that needs no wheel sensor: satellites do the measuring.
Shop by category
Shop all componentsThe ESP32 has two cores and runs FreeRTOS, so you can run several tasks at once instead of cramming everything into loop(). Here one task reads the slow DHT22 every two seconds and passes the result through a queue, while another task redraws the OLED animation many times a second. Neither waits for the other. Understanding tasks and queues is the key step from beginner sketches to reliable ESP32 firmware.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger.
freertos_tasks.inoVerify & upload in Electrolark#include <Wire.h>
#include <DHT.h>
#include <Adafruit_SSD1306.h>
DHT dht(4, DHT22);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
QueueHandle_t readings;
struct Reading { float t; float h; };
void sensorTask(void*) {
for (;;) {
Reading r = { dht.readTemperature(), dht.readHumidity() };
xQueueOverwrite(readings, &r); // keep only the latest value
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
void displayTask(void*) {
Reading last = { 0, 0 };
int x = 0;
for (;;) {
Reading r;
if (xQueuePeek(readings, &r, 0) == pdTRUE) last = r;
oled.clearDisplay();
oled.setTextSize(2); oled.setCursor(0, 0);
oled.printf("%.1fC %.0f%%", last.t, last.h);
x = (x + 3) % 128;
oled.fillRect(0, 40, x, 8, WHITE); // an animation that never stalls
oled.display();
vTaskDelay(pdMS_TO_TICKS(30));
}
}
void setup() {
Wire.begin(21, 22);
dht.begin();
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(WHITE);
readings = xQueueCreate(1, sizeof(Reading));
xTaskCreatePinnedToCore(sensorTask, "sensor", 4096, NULL, 1, NULL, 0);
xTaskCreatePinnedToCore(displayTask, "display", 4096, NULL, 1, NULL, 1);
}
void loop() { vTaskDelay(portMAX_DELAY); }
The first DHT22 read takes about two seconds. The display shows zeros until the sensor task has run.
A task must delay or yield. Do not write a loop that never calls vTaskDelay.
Only one task should use the I2C bus. Here only the display task touches it.
It lets time-critical work such as Wi-Fi stay separate from your own tasks, and lets two jobs truly run at the same time.
No, they are available by default on the ESP32 Arduino core.
It passes data between tasks safely without them overwriting each other.
5 parts: ESP32-WROOM-32 38-Pin Development Board, DHT22 AM2302 Digital Temperature & Humidity Sensor, 0.96" OLED Display 128x64, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a advanced project and takes about 2 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (freertos_tasks.ino).
About ₹724 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Creating FreeRTOS tasks pinned to a core; Passing data safely through a queue; Why blocking delays are a problem.
Ideas that reuse this build: ESP32 OTA wireless update. They are listed under Take it further on this page.
A bike or car speedometer that needs no wheel sensor: satellites do the measuring.
Records where you went every five seconds, ready to open on a map.
Two boards, two radios: press the button at the gate and it rings indoors.
Check temperature, humidity and pressure from any phone on your Wi-Fi.
Learning project. Check every circuit and the datasheet of each part before you power it up.