Arduino and ESP32 example projects
211 example projects, one for every part and for firmware techniques from watchdogs to PID, each with its circuit, full code and how it works.
Output
- Blink an LED · The "hello world" of embedded systems: switch an LED on and off from a digital pin.
- RGB LED colour fade · Mix red, green and blue with PWM to fade an RGB LED smoothly around the colour wheel.
- 7-segment counter · Count from 0 to 9 on a 7-segment display, using a lookup table of which segments make each digit.
- Bar graph level meter · Turn a potentiometer and watch a 10-LED bar graph fill up, like a volume meter.
- Play a melody · Play "Twinkle, Twinkle, Little Star" on a piezo buzzer with tone().
- MicroPython pedestrian crossing · A traffic light on a Raspberry Pi Pico in MicroPython: red, amber and green LEDs, and a button that asks to cross.
- Sine wave generator (MCP4725) · A 12-bit DAC turns a table of numbers into a real analog sine wave; watch it on the oscilloscope, and compare it with PWM.
- Nucleo-F401RE: PWM fade · Fade an LED on D9 with TIM3 channel 2 on PC7, set up in registers: prescaler, auto-reload and compare.
- Pico: dim an LED with a knob · A Raspberry Pi Pico reads a potentiometer with its 12-bit ADC and sets an LED's brightness with PWM.
- Nucleo-F767ZI: chase the three user LEDs from a timer interrupt · Bare-metal C on the STM32F767 (Cortex-M7): step LD1, LD2 and LD3 in turn from TIM6's update interrupt while the core sleeps in WFI.
- Pico: drive a NeoPixel ring with a four-instruction PIO program · Hand-assemble the WS2812 PIO program, feed it 24-bit colours through the TX FIFO, and spin a comet round a ring of eight NeoPixels at 800 kHz while the CPU sleeps.
- Nucleo-F446RE: a sine wave from the DAC with TIM6 and DMA · Bare-metal C on the STM32F446: TIM6 paces the DAC, DMA feeds it from a table, and a 1 kHz sine appears on PA4 with the CPU doing nothing.
Input
- Pushbutton toggle with debouncing · Each press of a button toggles an LED, with software debouncing so one press counts once.
- Slide switch on/off · Read a slide switch as a digital input and report when it changes position.
- Potentiometer LED dimmer · Turn a knob to set an LED's brightness: analogRead() in, analogWrite() out.
- Slide potentiometer controls a servo · Move a slider and a servo follows it: map an analog reading to an angle.
- DIP switch binary reader · Read four DIP switches as the bits of a binary number and print it in decimal.
- Keypad door lock · Enter a 4-digit code on a membrane keypad to "unlock": the Keypad library scans the rows and columns.
- Joystick direction · Read an analog joystick's two axes and its push button, and print which way it is pushed.
- Tilt alarm · A tilt switch detects when something is tipped over and sounds a buzzer.
- Touch lamp (TTP223) · Switch a lamp on and off with a capacitive touch pad, and dim it with a long touch.
- Rotary encoder counter · Count clicks of a KY-040 rotary encoder in both directions, and reset with its push button.
- Rotary phone dial as a keypad · Decode a rotary telephone dial's pulses into digits and use them to enter a PIN.
- IR remote decoder · Decode the keys of an infrared remote control with an IR receiver and the IRremote library.
- ESP32 IR remote decoder · Decode an infrared remote's keys on an ESP32-C3 with the IRremote library, and toggle an LED with the power key.
- Door alarm (reed switch) · A reed switch on the door frame closes while the door's magnet is near; open the door for more than five seconds and the alarm sounds.
- Nucleo-F401RE: a button interrupt · Count presses of the Nucleo's blue USER button with EXTI line 13 and the NVIC, all set up in registers, and toggle LD2 from the main loop.
- Black Pill: count KEY presses with an EXTI interrupt · Bare-metal C on the STM32F411: route the KEY button on PA0 to EXTI line 0, count presses in its interrupt and toggle the PC13 LED.
- Pico W in MicroPython: a call button debounced in an interrupt, with timers · MicroPython on a Raspberry Pi Pico W catches a bouncing button with Pin.irq, confirms each press with a one-shot machine.Timer, and blinks a call lamp from a periodic Timer while the main loop only reports.
Logic
- Eight LEDs from three pins (74HC595) · A 74HC595 shift register drives eight LEDs from three pins, with a light that runs back and forth.
- Read eight switches through three pins (74HC165) · A 74HC165 shift register reads a DIP switch's eight positions into one byte, three pins in total.
- Logic gates truth table · Two buttons feed AND, OR and XOR gates; LEDs show each output and the board prints the truth table.
- Settings in an external EEPROM (24LC256) · Store a settings record with a checksum in a 24LC256 I²C EEPROM, using page writes and ACK polling.
- 16 more pins with an I/O expander (MCP23017) · Drive eight LEDs and read a button through an MCP23017 on I²C, with an interrupt instead of polling.
- Eight more pins (PCF8574) · Read four buttons and light four LEDs through a PCF8574, the I²C expander with no registers, woken by its INT pin.
- Divide a clock by two with a D flip-flop · Wire a D flip-flop's inverted output back to its input to halve a clock, and watch one bit of memory change only on the rising edge.
- Eight analog inputs on one pin (CD4051) · A CD4051 multiplexer picks one of eight analog signals for a single analog pin: read four knobs through it, one channel at a time.
Sensors
- Automatic night light · A light sensor (LDR) turns an LED up as the room gets darker.
- NTC thermometer · Measure temperature with an NTC thermistor and the Beta equation.
- Automatic lamp (BH1750) · Measure light in lux with a BH1750 and dim a lamp up as the room gets darker, smoothed so it does not flicker.
- DHT22 weather station · Read temperature and humidity from a DHT22 and work out the "feels like" heat index.
- Two thermometers on one wire (DS18B20) · Find two DS18B20 temperature sensors on a single 1-Wire pin by their addresses and read both.
- Barometer and altimeter (BMP280) · Read air pressure and temperature from a BMP280 over I²C and estimate the altitude from them.
- Fan thermostat (LM35) · Read an LM35 with the 1.1 V reference for tenth-degree steps, and switch a fan with hysteresis so it does not chatter.
- Motion alarm · A PIR motion sensor triggers a buzzer and an LED when someone walks by.
- Ultrasonic distance meter · Measure distance with an HC-SR04 by timing an ultrasonic echo with pulseIn().
- Flame detector · Detect a flame with an infrared flame sensor and sound an alarm.
- Thermocouple over-temperature alarm (MAX6675) · Read a K-type thermocouple up to 1024 °C through a MAX6675 and sound an alarm above a set temperature.
- Gas leak detector · Read an MQ-2 gas sensor's concentration and alarm when it passes a threshold.
- Plant watering alarm (soil moisture) · Measure soil moisture as a percentage and switch a pump relay on when the plant is dry.
- Sound level meter · Read the small and big microphone modules side by side and react to loud sounds.
- Tank level gauge (water level sensor) · Show how full a tank is on an LED bar graph and warn when it is nearly empty or about to overflow.
- Heart rate monitor · Count heartbeats from a pulse sensor's waveform and work out beats per minute.
- Precision voltmeter (ADS1115) · Measure voltages to a fraction of a millivolt with a 16-bit ADS1115 and compare it with the board's 10-bit ADC.
- Power meter (INA219) · Measure the voltage, current and power of a load with an INA219, and add up the energy it uses.
- Real-time clock · Keep the date and time with a DS1307 real-time clock over I²C, using RTClib.
- Alarm clock (DS3231) · Set a DS3231's alarm, catch its INT/SQW pin with an interrupt, and sound a buzzer until a button stops it.
- Tilt angles with an MPU6050 · Read acceleration and rotation from an MPU6050 and work out pitch and roll.
- Digital scale · Weigh things with a load cell and an HX711 amplifier: tare it, scale it, read grams.
- Overcurrent trip (ACS712) · Measure a load's current with an ACS712, zero it at start-up, average out the noise, and latch a trip when it stays over the limit.
- Timestamped light logger (ESP32-C3) · Log light levels with the time from a DS3231 on an ESP32-C3, and mark each reading dark or light, all on one I²C bus.
- Weather station (BME280) · Read temperature, humidity and air pressure from one BME280, work out the dew point and altitude, and light an LED when the air is damp.
- Comfort meter (AHT20) · An AHT20 measures temperature and humidity; a green LED means comfortable, red too dry or too damp, yellow too hot or cold.
- SHT31 without a library (CRC check) · Talk to an SHT31 with Wire alone: send its 16-bit command, wait out the measurement, and check each word's CRC-8 before trusting it.
- Digital compass (QMC5883L) · Read the Earth's magnetic field on three axes, turn it into a heading and a compass point, and point a servo needle north.
- Orientation from 9 axes (MPU9250) · Roll and pitch from the accelerometer, turn rate from the gyroscope, and a heading from the magnetometer hidden behind the MPU9250's I²C bypass.
- Parking sensor (VL53L0X) · A laser time-of-flight sensor measures the distance to the wall in millimetres; a buzzer beeps faster as you get closer and holds a tone when you should stop.
- Revolution counter (Hall sensor) · A magnet on a wheel passes a Hall effect switch once a turn; an interrupt counts the turns and the sketch works out the speed.
- Water meter with shut-off (YF-S201) · Count a flow sensor's pulses to measure litres a minute and the total, and close the valve (a relay) once two litres have run.
- More analog inputs over SPI (MCP3008) · An MCP3008 adds eight 10-bit analog inputs over SPI: read a joystick and a knob through it, single-ended and as a differential pair.
- Nucleo-F401RE: read a potentiometer · Read a potentiometer on A0 with ADC1, set up in registers: 12-bit conversions on channel 0, printed in millivolts.
- Nucleo-G071RB: read a potentiometer with ADC, DMA and DMAMUX · Bare-metal C on the STM32G071: bring the G0's ADC up (regulator, calibration, ready flag) and let DMA, routed by DMAMUX, keep eight readings in memory.
- Nucleo-L552ZE-Q: gap-free ADC capture with DMA double-buffer mode · Bare-metal C on the STM32L552 (Cortex-M33 at 110 MHz): a timer paces the ADC, the DMA fills two buffers in turn through DMAMUX, and the CPU reads whichever one has just finished.
- Pico 2: a floating-point filter on the Cortex-M33 · A Raspberry Pi Pico 2 smooths a noisy knob with a float low-pass filter on its FPU, works out the voltage in double precision on its coprocessor, and dims an LED to match.
- Pico 2 in MicroPython: a thermometer with an alarm light · MicroPython on a Raspberry Pi Pico 2 reads an NTC thermistor on its ADC, works out the temperature with the Steinhart-Hart formula, and lights a warning LED when it gets too warm.
- Pico 2 in MicroPython: five minutes of temperature in RAM · MicroPython on a Raspberry Pi Pico 2 reads a thermistor a thousand times a second on a timer and keeps the last five minutes, 300 000 readings, in one bytearray; a button prints their minimum, maximum and mean.
- Find a tone with a DFT · The Uno builds a test signal (a tone the knob tunes, a 120 Hz hum and noise), runs a 64-point discrete Fourier transform on it, and lights the LED bar at the strongest frequency.
- "TinyML: classify a motor's vibration on an Uno" · Turn a window of vibration samples into four features, then score them with a tiny trained model (a two-layer network in a few hundred bytes) that tells normal running from imbalance and a worn bearing.
- Pico in MicroPython: an I2C climate display that copes with a missing sensor · MicroPython on a Raspberry Pi Pico reads an AHT20 over machine.I2C, checks its CRC, draws the reading on an SSD1306 OLED with framebuf, and says so when the sensor is not there.
- Pico in MicroPython: a water meter that counts pulses in PIO · A four-instruction PIO program, written in MicroPython with rp2.asm_pio, counts a flow sensor's pulses on its own; the CPU takes a snapshot of the count with StateMachine.exec and works out litres a minute and the total.
Displays
- Hello on a 16×2 LCD · Print text and a running timer on a character LCD driven in 4-bit mode with LiquidCrystal.
- 20×4 LCD over I²C · Drive a 20×4 character LCD with only two wires through its I²C backpack.
- OLED graphics · Draw text and a bouncing ball on a 128×64 OLED with the Adafruit SSD1306 library.
- Colour TFT display · Draw colour text and shapes on a 240×320 ILI9341 TFT over SPI.
- 8×8 LED matrix animation (MAX7219) · Draw a smiley and a beating heart on an 8×8 LED matrix driven by a MAX7219 over three wires.
- NeoPixel rainbow ring · Spin a rainbow around a 16-LED NeoPixel ring with the Adafruit NeoPixel library.
- NeoPixel matrix smiley · Draw a colour-changing smiley face on an 8×8 NeoPixel matrix from a bitmap.
- Stopwatch on a 4-digit display (TM1637) · Count seconds and hundredths on a TM1637 4-digit display, with a button to start, stop and reset.
- Chained NeoPixels · Chain three single NeoPixels DOUT to DIN and run a light along them.
- Dial gauge on a colour TFT (ST7789) · Draw a round gauge on a 240x240 ST7789 display and move its needle with a knob, redrawing only what changes.
- Bar meter on a 1.3" OLED (SH1106) · Show a knob's value as a number and a bar on a 1.3" SH1106 OLED, with the library made for its controller.
- Thermometer on a Nokia 5110 LCD · Show an LM35's temperature in large digits on a Nokia 5110 LCD, with its backlight, its contrast setting and the minimum and maximum seen.
- Nucleo-F401RE: I2C OLED · Drive a 128×64 SSD1306 OLED with your own I2C1 driver on PB8 and PB9: start, address, data and stop, register by register.
Communication
- Modbus RTU sensor over RS-485 (MAX485) · Poll an industrial temperature and humidity sensor with Modbus RTU through a MAX485 transceiver.
- GPS position and speed (NEO-6M) · Parse NMEA sentences from a NEO-6M GPS with TinyGPSPlus and print position, speed, altitude and UTC time.
- Bluetooth remote control (HC-05) · Switch an LED and read a sensor from a phone through an HC-05 Bluetooth module.
- RFID door lock (MFRC522) · Unlock a servo latch for one known card and refuse others, counting each card's visits in its own memory.
- CAN bus dashboard (MCP2515) · Read engine-speed frames from another node on a CAN bus, show them, and send a status frame back.
- Data logger on a microSD card · Log timestamped sensor readings to a CSV file on a microSD card, and read settings from a file on the card.
- Two Arduinos over Serial · One Arduino's button switches another Arduino's LED: two boards, two sketches, one serial link between them.
- Two Arduinos on a CAN bus · A knob on one Arduino dims an LED on another: each board has its own MCP2515, and frames cross the CAN bus.
- ESP32 and Arduino over Serial · An Arduino Uno reads a knob and sends it to an ESP32-C3 over a serial link; the ESP32 dims an LED to match and answers.
- Two Arduinos over I²C (master and slave) · One Uno is the I²C master, the other a slave at address 8: the master sends a brightness and asks for the slave's button.
- Weather over Wi-Fi (ESP32-C3) · Join the Wi-Fi, set the clock over NTP, fetch the temperature from a web API every 10 s and post each reading back.
- MQTT sensor node (ESP32-C3) · Publish a reading to an MQTT broker every 2 s, switch an LED from a command topic, and announce the node with a retained status and a last will.
- HTTPS and certificates (ESP32-C3) · Fetch JSON over HTTPS, verifying the server against a certificate authority, and see a spoofed server refused.
- Over-the-air update (ESP32-C3) · Check an update server for a newer version, download it over HTTP into the other app partition, and reboot into it.
- Wireless button (two nRF24L01s) · A button on one Arduino lights an LED on another over 2.4 GHz radio, and the sender knows each packet arrived from its acknowledgement.
- Long-range sensor link (two SX1278 LoRa radios) · One Arduino sends a sensor reading over LoRa every two seconds; the other prints it with the signal strength and SNR it arrived with.
- SMS remote control (SIM800L) · Switch a pump by text message through a SIM800L modem, reply with its state, and send an alert when a float switch trips.
- Nucleo-F401RE: Serial commands · A command line on USART2, set up in registers: type commands in the serial monitor to switch LD2 and read the clock and uptime.
- Nucleo-H743ZI2: non-blocking serial with the USART's FIFO · Bare-metal C on the STM32H743 (Cortex-M7 at up to 480 MHz): queue text in a ring buffer and let the USART's FIFO threshold interrupt send it, so printing never makes the main loop wait.
- Pico: a USB serial device, from enumeration to bulk packets · The Pico's Serial is a USB CDC device. Watch it enumerate, read its own device descriptor and the host's line coding, and time a burst of bulk packets from a small command console.
- Pico W: the LED on the radio, and a Wi-Fi status light · A Raspberry Pi Pico W blinks its LED, which hangs off the Wi-Fi chip rather than the RP2040, joins a WPA2 network and shows on a red LED when it could not.
- Pico W in MicroPython: Pin("LED") and the WLAN · MicroPython on a Raspberry Pi Pico W blinks the LED on its radio, scans for Wi-Fi, joins a WPA2 network with a deadline and reports its address, or why it could not connect.
- Pico 2 W: join Wi-Fi, or start an access point of its own · A Raspberry Pi Pico 2 W joins the home network when it can and, when it can't, starts its own Wi-Fi access point, while it filters a sensor on its FPU and shows it on an LED.
- ISO-TP: send 50 bytes over 8-byte CAN frames · Two Nucleo-F446RE boards on one CAN bus: a tester splits a 50-byte message into ISO-TP frames, and the ECU paces it with flow control.
- Pico 2 W in MicroPython: a WLAN with a deadline and a setup access point · MicroPython on a Raspberry Pi Pico 2 W scans for Wi-Fi, gives joining five seconds, starts an access point when that fails, and dims an LED from a knob all along.
- Pico W: upload sensor readings as JSON over HTTP · A Raspberry Pi Pico W joins Wi-Fi, POSTs a soil-moisture reading as JSON to a web API every 3 s, and takes its reporting interval from the server's answer.
- UDS: read the VIN, live data and fault codes · A tester asks an ECU for its VIN, a live coolant temperature and its fault codes with UDS services 0x22, 0x19 and 0x14, over ISO-TP on CAN.
- Pico 2 W in MicroPython: an MQTT device with telemetry and commands · MicroPython on a Raspberry Pi Pico 2 W joins Wi-Fi, publishes a knob's reading as JSON telemetry every 2 s, and switches an LED from commands the cloud publishes, with a retained status and a last will.
- UDS: sessions, seed and key, and a protected write · A tester opens an extended session, unlocks an ECU with security access (seed and key), and writes a protected value, with the ECU refusing a wrong key and timing out an idle session.
Motors
- Servo sweep · Sweep a hobby servo back and forth from 0° to 180° with the Servo library.
- Stepper motor with an A4988 · Drive a NEMA stepper motor with STEP and DIR through an A4988 driver, accelerating with AccelStepper.
- Microstepping with a DRV8825 · Pulse STEP yourself and switch a DRV8825 between full steps and quarter steps with its mode pins.
- 28BYJ-48 stepper with a ULN2003 · Turn the cheap 5 V geared stepper from Arduino kits through its ULN2003 board with the Stepper library.
- DC motor speed and direction · Control a DC motor's speed with PWM and its direction with an L298N H-bridge.
- Bipolar stepper with an L298N · Use both H-bridges of an L298N to drive a bipolar stepper motor with the Stepper library.
- Servos on a PCA9685 · Drive two servos from a PCA9685 16-channel PWM board over I²C, with the Adafruit library.
- NEMA 23 stepper on a TB6600 drive · Run a NEMA 23 stepper from a 24 V supply through an opto-isolated TB6600 drive, set by its DIP switches.
- Two-hand gauge (biaxial stepper) · Drive both hands of a biaxial stepper from two knobs, as a speedometer and a tachometer share one dial.
- Jog a NEMA 34 with a DM542T and an E-stop · Jog a NEMA 34 stepper both ways with push buttons, set the speed with a knob, and stop it with a fail-safe E-stop.
- Position a servo motor with a pulse/direction drive · Move an industrial servo motor to exact angles through its drive, and use the drive's INP and ALM outputs to know when it has arrived or failed.
- Two-wheel robot drive (TB6612FNG) · Drive a two-wheeled robot's motors through a TB6612FNG: forward, spin on the spot, brake and coast, with PWM speed.
- Knob-controlled motor (L293D) · One knob sets a DC motor's speed and direction through an L293D: turn left to reverse, right to go forward, the middle to stop.
- Nucleo-F401RE: pan-tilt camera head on a stepper turntable · Pan an MG996R and tilt an SG90 with TIM3 PWM, turn a NEMA 17 turntable through a TMC2209 with TIM2 step interrupts, all powered from a 12 V supply and an LM2596, commanded over the Serial Monitor.
- Nucleo-F030R8: 28BYJ-48 stepper with a servo gauge · Half-step a 28BYJ-48 through a ULN2003 with BSRR writes on the F030R8, and show how far round it is on an SG90 gauge driven by TIM3, everything powered from a 4 × AA pack.
- Nucleo-F446RE: camera slider with limit switches · Step a NEMA 17 through a DRV8833 from GPIO, home and reverse on limit switches with EXTI interrupts, and pan a camera with an FS90R continuous servo, all from a 2S Li-ion pack and an MB102 module.
- Pico 2: a PID speed loop in float, double and fixed point · A Raspberry Pi Pico 2 times one PID speed controller three ways, float on the Cortex-M33's FPU, double on the RP2350's coprocessor and Q16.16 fixed point, then runs it live with a knob for the target and an LED for the drive.
Industrial
- Machine safety circuit with an E-stop · Wire an emergency stop through a dual-channel safety relay to a motor contactor, add start/stop from an Arduino, and show the state on a stack light.
- Count parts with a 24 V proximity sensor · Read a PNP inductive sensor through an optocoupler module, count parts, and signal each finished batch on a stack light through a solid-state relay.
- A latching relay that remembers its position · Set and reset a bistable relay with 100 ms pulses from two buttons, and see it hold a 24 V lamp on with no power in its coils.
- Time a 5 s on-delay with a timer relay · Power a multi-function timer relay through an interface relay, and have the Arduino measure how long its contact takes to close through an optocoupler.
- Start-stop motor circuit with overload protection · The classic self-holding start-stop circuit with a circuit breaker and a thermal overload relay, watched by an Arduino through an optocoupler module.
- Hand-Off-Auto selector with a panel meter · Read a three-position HAND-OFF-AUTO selector switch through optocouplers, drive a 24 V pilot light through an SSR, and watch its voltage on a panel meter.
- Guard door interlock with a limit switch · Read a guard door's limit switch and a start button, run a machine only while the door is closed, and stop it with a red light and buzzer the moment it opens.
- Bottle filling with capacitive and photoelectric sensors · Detect a bottle with a photoelectric sensor and its liquid level with a capacitive sensor, run a pump through an SSR until it is full, and count the bottles.
- Pico 2: a 400 KB black-box recorder in the RP2350's SRAM · A Raspberry Pi Pico 2 samples a sensor 10 000 times a second on a timer interrupt and keeps the last 20 seconds, 400 KB of readings, in its 520 KB of SRAM; a button prints a summary of them.
RTOS
- FreeRTOS tasks and a shared Serial port · Three FreeRTOS tasks on an Uno: two LEDs blink at their own rates while a third reports, with a mutex guarding Serial.
- FreeRTOS queue from a sensor task to an output task · One task samples a potentiometer and sends readings through a queue; another receives them and dims an LED.
- FreeRTOS interrupt to task with a semaphore · A button interrupt gives a semaphore from the ISR; a task wakes, debounces the press and toggles an LED.
- FreeRTOS on the ESP32 with no library · The ESP32's Arduino core runs on FreeRTOS: a sampler task, a queue, a dimmer task and a software timer, with nothing to install.
- Write your own cooperative scheduler (no library) · A table of tasks run on time from loop(), in plain C with no library, and a measurement of its weak spot: one slow task delays all the others.
- Write your own preemptive RTOS kernel (no library) · A real preemptive kernel in about 150 lines for the Uno: task stacks, a 1 ms tick, an assembly context switch, priorities and taskDelay.
- RTOS: priority inversion, and the mutex that fixes it · Three FreeRTOS tasks share a lock. With a binary semaphore the high-priority task waits behind a medium one; with a mutex, priority inheritance cuts the wait to the length of the lock.
- RTOS: a machine start interlock with an event group · Three FreeRTOS tasks each watch one condition (guard door, temperature, start button) and set a bit in an event group; the motor task waits for all three bits at once, and stops when one drops.
- RTOS: catch a periodic task missing its deadline · A FreeRTOS control task runs every 128 ms with vTaskDelayUntil and measures its own release jitter, run time and missed deadlines, while a knob adds work until it overruns.
Firmware
- Watchdog that rescues a hung sketch · Feed a watchdog from the main loop, hang the sketch with a button, and count the resets it recovers from in EEPROM.
- Settings that survive a reboot (EEPROM and CRC) · Keep a settings struct in EEPROM with a CRC-8, fall back to defaults when it is blank or corrupt, and change it over Serial.
- Write a driver (PCF8574) · Wrap a chip in a small driver: a struct for its state, functions for its operations, and a callback for its events.
- Microwave controller (event-driven state machine) · Turn buttons, a door switch and a timer into events in a queue, and let one state machine decide what each means.
- Washing machine (hierarchical state machine) · Nest Fill, Wash and Spin inside a Running state, so one rule pauses all three, and resume where it left off.
- Tune a PID loop (simulated heater) · Hold a heater at a set temperature with a PID controller, and tune Kp, Ki and Kd while watching the Serial Plotter.
- Current meter without floats (fixed point) · Turn an ACS712's ADC reading into milliamps with one integer multiply and a shift, and time it against division and float.
- Pins through registers (macros and inline functions) · Drive LEDs and read a button through DDRB, PORTB and PIND with bit macros and inline functions, and time it against digitalWrite.
- Unit tests that run on the board · A ring buffer and a tiny test framework of three macros: ten tests run at start-up on the Uno, print PASS or FAIL with the line, and light a green or red LED.
- Integer traps on an 8-bit chip · Six short C bugs that the Uno makes visible because its int is 16 bits, each next to its fix, with the MISRA rule or compiler warning that would have caught it.
- "C++ on a microcontroller: classes, RAII and templates" · A Pin class, an interrupt lock that frees itself, and a ring buffer template checked at compile time, with no heap, no exceptions and no virtual calls, on an Uno.
- Nucleo-F401RE: move the vector table to RAM · Read the vector table the chip boots from, copy it into RAM, point VTOR at the copy, and swap the SysTick handler while the program runs.
- Pico: blink through the SIO registers · Blink two LEDs on a Raspberry Pi Pico by writing its SIO registers and timing them with the RP2040's 1 MHz timer, through the Pico SDK under the Arduino core.
- Nucleo-F401RE: where every variable lives · Print the address of a constant, an initialised global, a zeroed one, a static, a local, a heap block and a function, check them against the linker's symbols, and measure stack use by painting it.
- Pico: blink two LEDs with PIO, the CPU idle · Hand-assemble a six-instruction PIO program and run it on two state machines, which blink two LEDs at their own rates while the CPU does nothing for them.
- Nucleo-F401RE: count CPU cycles with the DWT · Time pieces of C to the clock cycle with the Cortex-M4's DWT cycle counter, and see what the compiler made of them: division against shifts, float against double, volatile against plain.
- Pico: two cores, a FIFO and a spin lock · Core 1 samples a knob and blinks an LED while core 0 reports and dims a second LED. Words cross between the cores through a FIFO, and a counter both cores increment shows why shared data needs a spin lock.
- Nucleo-F401RE: a boot loader with A/B slots and CRC · A boot loader checks two firmware images with the STM32's CRC unit, rejects the newer one because a word was written wrong, and starts the older, intact one.
- Nucleo-F446RE: a clock and alarm with the RTC · Bare-metal C on the STM32F446: set the RTC's calendar, sleep until its wake-up timer ticks each second, and light LD2 when the alarm goes off.
- Nucleo-WBA55CG: a stopwatch on a 32-bit timer, with an EXTI button · Bare-metal C on the STM32WBA55 (Cortex-M33): raise the clock to 100 MHz on a PLL with a fractional divider, time with a 32-bit timer, and take B1 on its own EXTI line.
- Pico 2: mixing audio with the Cortex-M33's DSP instructions · A Raspberry Pi Pico 2 mixes two Q15 audio tracks and runs the mix through a 16-tap FIR filter twice, in plain C and with the Cortex-M33's SIMD and saturating instructions, and prints how much faster the DSP path is.
- Pico 2 in MicroPython: a second core with _thread · MicroPython on a Raspberry Pi Pico 2 starts a function on core 1 with _thread. Core 1 reads a knob a few hundred times a second and smooths it; core 0 dims an LED from the result and reports it, and a lock keeps what they share whole.
Control
- Motor speed PID (encoder and flywheel) · Hold a 12 V motor at a set speed: count its encoder on interrupts, add a feedforward, close a PI loop, and tune it live while a load pulls on the shaft.
- Heater PID (lag, dead time and a door) · Hold an aluminium block at 60 °C with a 20 W heater and an LM35: a slow plant whose sensor lags and whose heat arrives late, and a door that opens.
- Line follower: bang-bang, then PD · A two-wheel robot follows black tape round a 1.6 m oval: first bang-bang, which zigzags and loses the line on the bends, then PD on the line's position from all five IR sensors, tuned live from the World tool.
- Obstacle avoider with an ultrasonic sensor · A two-wheel robot roams a room of boxes: it pings ahead with its ultrasonic sensor every 60 ms, turns on the spot when something is closer than 35 cm, and drives on once the way is clear.
- ESP32-C3 line follower with wheel encoders · The two-wheel robot on an ESP32-C3: five IR readings on its 12-bit ADC, PD steering on LEDC PWM, and the wheels counted on interrupts from slotted encoder discs slow enough for its pins.
- Nucleo-F401RE line follower in bare-metal C · The two-wheel robot on a Nucleo-F401RE, registers only: ADC1 reads the five IR sensors in turn, TIM2 makes the two motors' PWM, and TIM3 and TIM1 count the wheel encoders in hardware, in encoder mode.
- Pico line follower in MicroPython · The two-wheel robot on a Raspberry Pi Pico in MicroPython: three IR sensors on its ADC, the outer two through their comparators, PD steering on two PWM outputs, all in one polled loop.
- Water tank level (PI, anti-windup, a drain) · Hold a water column at 150 mm with a 12 V pump and a level sensor: a slow, non-linear plant, a PI loop that must not wind up while it fills, a float switch as the safety stop, and a drain to open.
- Pico water tank in MicroPython · The water tank's level loop on a Raspberry Pi Pico in MicroPython: the level sensor on its ADC, the pump's MOSFET on a PWM output, the float switch polled, and gains you can change over the REPL's serial line.
- Cart-pole balance (state feedback) · Balance a 300 mm pole on a belt-driven cart: two quadrature encoders on interrupts, a 2 ms loop, and full state feedback on the pole's angle and rate and the cart's place and speed. Nudge it and watch it recover. A Pro rig.
- Nucleo-F401RE cart-pole in bare-metal C · Balance the cart-pole on a Nucleo-F401RE with registers only: TIM3 and TIM1 count both encoders in hardware, in encoder mode, TIM2 makes the motor's PWM, and SysTick runs the state-feedback loop every 2 ms. A Pro rig.
Basic
- Breadboard: button and LED · Build a circuit on a breadboard: a pushbutton that lights an LED, and how the breadboard joins them.
- Mini breadboard: an LED and its resistor · Build the smallest useful circuit on a mini breadboard: a resistor and an LED in a row of strips, driven from a pin.
- Switch a lamp with a relay · Use a relay to switch a separate circuit (an LED "lamp") on and off from a microcontroller pin.
- Drive a relay with a transistor · Switch a bare relay coil from a pin through an NPN transistor, with a base resistor and a flyback diode.
- Full breadboard: power rails and an external pull-up · Use a full-size breadboard's power rails to share 5 V and GND, and read a button through an external pull-up resistor instead of the internal one.
- See UART and I²C on a logic analyzer · Probe a sketch's Serial output and its I²C traffic with an 8-channel logic analyzer and decode each byte.
- Oscilloscope basics: see PWM, a voltage and a pulse · Learn the oscilloscope step by step: Autoset, reading frequency and duty, cursors, AC coupling and catching a single pulse.
- Mega: two LED chasers on whole ports · Use what an Arduino Mega has that an Uno does not: complete 8-bit ports on its header. Drive PORTA and PORTC with one register write each to run two LED bars in opposite directions.
- Nano: the analog-only pins A6 and A7 · Read a knob on A7, one of the two Nano pins that can only measure voltage, and use it to dim an LED on a PWM pin.
- "C basics: a Morse code beacon from a string" · Turn any text into Morse code on an LED and a buzzer, with a lookup table of strings and one small function per job.
- ESP32-S3: a button toggles an LED · Run a first sketch on the ESP32-S3: toggle an LED with a button on GPIO 5, debounce it, and report the count over the serial port.
- "C basics: an LED chaser that walks with a pointer" · Six LEDs play patterns stored in arrays; a pointer walks each pattern to its end marker, and the button points it at the next one.
- ESP32-C5: a button toggles an LED · Run a first sketch on the ESP32-C5: toggle an LED with a button on GPIO 5, debounce it, and report the count over the serial port.
- "C basics: three blinkers, one struct" · Three LEDs blink at their own rates without delay(), each described by a struct in an array, and updated by one function through a pointer.
- ESP32-C6: a button toggles an LED · Run a first sketch on the ESP32-C6: toggle an LED with a button on GPIO 5, debounce it, and report the count over the serial port.
- "C basics: an electronic die" · Press the button to roll: the face is drawn on seven LEDs with a switch statement, and a tally checks the die is fair.
- ESP32-H2: a button toggles an LED · Run a first sketch on the ESP32-H2: toggle an LED with a button on GPIO 5, debounce it, and report the count over the serial port.
- ESP32-P4: a button toggles an LED · Run a first sketch on the ESP32-P4: toggle an LED with a button on GPIO 5, debounce it, and report the count over the serial port.
- Measuring Voltages with a Multimeter · Three multimeters check an Uno's circuit: a pin switching between 0 V and 5 V, a voltage divider's middle, and an input that nothing drives.
- Nucleo-F401RE: blink an LED · A first bare-metal program on an STM32: blink LD2 and an LED on D7 by writing GPIOA's registers, timed by SysTick.
- Blue Pill: blink with the F1's CRH register · Bare-metal C on the STM32F103: set pins up with the F1's four-bit CRL and CRH fields and blink the board's PC13 LED and one on PB12.