Skip to content
You Start with one site
Amounts in Start with one site
Engineering · Embedded Systems & Electronics

Embedded Programming: ESP32

Program the ESP32 in C with ESP-IDF. Nine connected devices, from a mood lamp to two sensor nodes that work outdoors on batteries.

Found this useful?
The two nodes of the last lesson: the outdoor node, asleep for 5 minutes, sends 23.5 °C, 61.2 %, soil 42 % and 3.12 V over TLS to the broker, which keeps 23.5; the indoor node, always on, shows 23.5 °C on its OLED and web page. An OTA server waits for the outdoor node.

A router restarts at night, and the device never joins again. A plant dries out, and the sensor beside it knew for two days. A node on a roof has a bug, and someone must climb up with a cable. With Wi-Fi on, two AA cells are empty in less than a day.

In this course you build devices that expect these faults. Each lesson adds one part: Wi-Fi that joins again, a web page, MQTT, Bluetooth, updates over the air and deep sleep. The last lesson joins them into two nodes, one outdoors and one indoors.

How each lesson goes
  1. 1Start from a faultThe router is off for 60 s. Does the device join again?
  2. 2See how the chip does itEvents, tasks, the flash map, the pins.
  3. 3Write it in CESP-IDF calls, with settings in menuconfig.
  4. 4Flash it and harden itTest with a phone or a browser, then plan for each failure.
You will be able to
  1. Write ESP-IDF firmware in C that keeps working when the Wi-Fi drops
  2. Send readings and alerts over HTTP, MQTT and Bluetooth, encrypted where it matters
  3. Update firmware over the air, and plan a node for months on two AA cells

New to this? Know C and new to the ESP32? Start with lesson 1: install ESP-IDF and build the mood lamp.

You need An ESP32 DevKitC (a second one for lesson 9), a breadboard and the few parts of each lesson. ESP-IDF on Windows, Mac or Linux.

The engineering behind it

How a device far from anyone sends its readings out, and keeps sending when the network fails.

Lessons
Lesson 1 · 14 minESP-IDF and Dual-Core ArchitectureA mood lamp: one core draws the colors while the other listens for your typed commands.ESP-IDFmenuconfigTwo coresQueues Lesson 2 · 16 minGPIO, Peripherals, and DriversA lamp with a bare wire for a switch: a short touch switches it, a long touch dims it, and it remembers.Touch pinsLEDC PWMGPIO matrixNVS Lesson 3 · 14 minWi-Fi and Network ConfigurationA survey tool that scans nearby networks every 10 seconds and shows them on its own page.STA + APEventsReconnectSmartConfig Lesson 4 · 18 minHTTP Server and REST APIA thermostat that decides by itself and serves its own page at thermostat.local.HTTP serverRESTmDNSHysteresis Lesson 5 · 20 minMQTT and Cloud CommunicationA plant monitor that sends each reading, and an alert when the soil is dry, to your phone.MQTTQoSTLSLast will Lesson 6 · 16 minBluetooth Low Energy (BLE)A sensor any phone nearby can read, with no router and no password.GAPGATTNotificationsWith Wi-Fi Lesson 7 · 17 minOTA Updates and Secure BootNew firmware over Wi-Fi, and the old one back by itself when the new one fails.OTA slotsRollbackSecure bootFlash encryption Lesson 8 · 23 minPower Management and Deep SleepA weather node that sleeps at about 10 µA between readings. You work out its battery life before you fit it.Deep sleepWake sourcesRTC memoryPower budget Lesson 9 · 17 minConnected Sensor NetworkTwo nodes: one outdoors on batteries, one indoors with a display, joined through an MQTT broker.Deep sleepMQTT over TLSOLEDOTA
More about this course

Every number has a reason

A node does not wake every 5 minutes because it sounds right. Each number comes from the battery, the network or the thing you measure.

  • Wake intervalsets the battery life: on paper 48 days at 5 minutes, 283 days at 30, on two AA cellsPower
  • Hysteresis0.5 °C each side of the target, so the relay does not switch on and off all the timeControl
  • QoS levelQoS 1 for readings, where a repeat does no harm; QoS 2 for alerts, sent onceMQTT
  • Advertising interval100 ms is found quickly; 1000 ms saves a batteryBluetooth
  • Two OTA slotsthe old firmware stays, so a failed update goes back to itUpdates

The board decides. The network tells people.

On the chip
Control
  • The thermostat switches its own relay
  • The firmware decides, not the page
  • Works with no network at all

The test: does it still work when the router is off?

Over the network
Reports and changes
  • A page shows the reading and sets the target
  • An alert reaches a phone far away
  • New firmware arrives with no cable

The test: does it tell someone, and recover when the link drops?

Why ESP-IDF

Plain CThe official tools from Espressif, the maker of the chip.
All of the chipWi-Fi, Bluetooth, OTA, secure boot and the flash map.
Two cores, one FreeRTOSTasks and queues from lesson 1.
Made for productsRollback, signed firmware and flash encryption (lesson 7).
Settings in one filemenuconfig writes them beside your code.
Windows, Mac and LinuxThe same steps on every system.

Honest limits. Arduino for the ESP32 is quicker to start and is built on ESP-IDF, with less of the chip open to you. What you learn here, tasks, events and the flash map, explains what Arduino does underneath.

Before you start

  • C: pointers, structs and callbacks
  • IP addresses, TCP and HTTP basics
  • One ESP32 DevKitC (two for the last lesson)
  • A Wi-Fi network; a phone hotspot works
The full course notes

The ESP32 brings Wi-Fi and Bluetooth to embedded systems for under $5. This course teaches you to build connected devices using ESP-IDF (the official framework), not Arduino wrappers. Each lesson produces a working networked project, progressing from local peripherals to cloud-connected IoT nodes with OTA updates and battery optimization. #ESP32 #IoT #EmbeddedSystems

Why ESP-IDF?

The Official Framework

ESP-IDF is what Espressif uses internally. It gives you full access to Wi-Fi, BLE, OTA, secure boot, partition tables, and the dual-core FreeRTOS scheduler. Arduino-ESP32 is a wrapper around ESP-IDF with limitations.

Production-Grade IoT

OTA firmware updates, flash encryption, secure boot v2, and partition management. These are not optional extras; they are what separates a prototype from a product. Lessons 7 and 8 cover them in depth.

Wi-Fi + BLE + FreeRTOS

Dual-core with FreeRTOS SMP, full Wi-Fi stack (STA/AP/mesh), BLE 4.2/5.0, and MQTT/HTTP client libraries. All running concurrently. The ESP32 is a complete IoT platform on a single chip.

Connects to Everything

MQTT brokers, REST APIs, phone apps via BLE, web dashboards. Each lesson connects the ESP32 to something new. By the capstone, you have a complete sensor network.

Course Structure

Each lesson follows a consistent cycle:

  1. The Connected Problem A real IoT scenario. Not “connect to Wi-Fi” but “build a browser-controlled thermostat.”

  2. ESP-IDF Internals How the relevant subsystem works: event loops, task model, protocol stack, partition layout.

  3. Implementation Write firmware in C using ESP-IDF APIs. Configure with menuconfig. Handle errors, edge cases, and reconnections.

  4. Build, Flash, and Connect Flash via USB, connect to the network, and verify with real clients (browser, phone, MQTT explorer).

  5. Hardening Error recovery, watchdog supervision, and connection resilience patterns you need for real deployments.

Lessons

Lesson 1: ESP-IDF Toolchain and Dual-Core Architecture

ESP-IDF Toolchain and Dual-Core Architecture. Install ESP-IDF, understand menuconfig, partition tables, and the dual-core FreeRTOS model. Build an RGB mood lamp where one core runs color animations and the other handles serial commands. Build: RGB mood lamp. Parts: ESP32 DevKitC, RGB LED (common cathode), resistors.

Lesson 2: GPIO, Peripherals, and Driver Framework

GPIO, Peripherals, and Driver Framework. Explore the GPIO matrix, LEDC PWM controller, pulse counter (PCNT), and RMT peripheral. Build a capacitive touch lamp dimmer using the ESP32’s built-in touch pins. Build: Capacitive touch lamp dimmer. Parts: Bright LED or small LED strip.

Lesson 3: Wi-Fi and Network Configuration

Wi-Fi and Network Configuration. Master the Wi-Fi driver: STA/AP/STA+AP modes, event model, SmartConfig provisioning, and scan capabilities. Build a Wi-Fi signal mapper that scans nearby access points and serves results as a webpage. Build: Wi-Fi signal mapper. Parts: No new parts.

Lesson 4: HTTP Server and REST API

HTTP Server and REST API. Build an HTTP server with RESTful endpoints, JSON parsing, mDNS discovery, and a responsive web UI served from SPIFFS. Build a browser-controlled thermostat with real sensor input. Build: Browser-controlled thermostat. Parts: DHT22 temperature/humidity sensor, relay module.

Lesson 5: MQTT and Cloud Communication

MQTT and Cloud Communication. Implement MQTT with QoS levels, TLS encryption, persistent sessions, and last will messages. Build a plant soil moisture monitor that sends alerts to your phone via a free MQTT broker. Build: Soil moisture monitor with alerts. Parts: Capacitive soil moisture sensor.

Lesson 6: Bluetooth Low Energy (BLE)

Bluetooth Low Energy. Implement GAP and GATT: advertising, scanning, services, characteristics, notifications. Handle BLE and Wi-Fi coexistence. Build a BLE environmental beacon that any phone can read. Build: BLE environmental beacon. Parts: Reuse DHT22.

Lesson 7: OTA Updates and Secure Boot

OTA Updates and Secure Boot. Configure OTA partition schemes, implement firmware rollback, enable flash encryption and secure boot v2, and sign firmware images. Build a remotely updateable sensor node. Build: OTA-updateable sensor node. Parts: Reuse existing.

Lesson 8: Power Management and Deep Sleep

Power Management and Deep Sleep. Master deep sleep modes, ULP coprocessor programming, RTC memory persistence, and multiple wake sources. Build a solar-ready weather node optimized for months of battery life. Build: Solar-ready weather node. Parts: 2xAA battery holder.

Lesson 9: Capstone: Connected Sensor Network

Connected Sensor Network Project. Combine everything: build a two-node system with an outdoor sensor (battery, deep sleep, MQTT publish) and an indoor display (OLED, always-on, MQTT subscribe). A complete IoT deployment. Build: Two-node sensor network. Parts: SSD1306 OLED (or reuse from prior courses).

Parts Kit

PartQuantityFirst UsedApproximate Cost
ESP32 DevKitC1-2Lesson 1$4-6 each
RGB LED (common cathode) + resistors1Lesson 1$0.50
Bright LED or small LED strip1Lesson 2$1-2
DHT22 temperature/humidity sensor1Lesson 4$2-3
Relay module (5V, 1-channel)1Lesson 4$1
Capacitive soil moisture sensor1Lesson 5$1-2
2xAA battery holder1Lesson 8$0.50
SSD1306 OLED display1Lesson 9$3-4

Total estimated cost: $18-28 (with two ESP32 DevKitC boards for the capstone)

Skill Progression

SkillLessons 1-3Lessons 4-6Lessons 7-9
ConnectivityGPIO, touch, Wi-Fi scan/connectHTTP server, MQTT, BLEOTA, deep sleep + wake, mesh
ProtocolsFreeRTOS SMP, event loopsREST, MQTT QoS, GATTTLS, secure boot, flash encryption
PowerAlways-onWi-Fi power saveDeep sleep, ULP, battery budgeting
Productionmenuconfig, partitionsError recovery, reconnectionOTA rollback, firmware signing

Prerequisites

Embedded C experience required

You should be comfortable with:

  • C programming (pointers, structs, callbacks, function pointers)
  • Basic networking concepts (IP addresses, TCP/UDP, HTTP basics)
  • Our Embedded Programming: ATmega328P course or equivalent bare-metal experience

Helpful but not required:

  • FreeRTOS basics (covered in STM32 course lesson 8, or learned here from scratch)
  • Our PCB Design with KiCad lessons 5-6 (design your own ESP32 board)
  • MQTT/IoT protocol familiarity

Getting Started

  1. Get an ESP32 DevKitC (or similar ESP32 development board with USB). For the capstone, a second board is ideal.

  2. Install ESP-IDF following the official Getting Started Guide. Lesson 1 walks through the process.

  3. Download the ESP32 Technical Reference Manual from Espressif (PDF) (datasheet). These cover every peripheral register and electrical specification.

  4. Set up a Wi-Fi network you can connect to. A phone hotspot works if needed.

  5. Start with Lesson 1. The course builds connectivity progressively, lesson by lesson.

  6. Test with real clients. Use a web browser, phone BLE scanner app, and MQTT Explorer to interact with your builds.

© 2021-2026 SiliconWit®. All rights reserved.

9 lessons, in order.

SiliconWit makes these courses. We also run siliconwit.io, a monitoring service.