Home / Embedded C Programming
Embedded C Programming: free complete tutorial with a live in-browser C sandbox and diagrams
Learn C for microcontrollers from the ground up: the C language itself, memory and pointers, bitwise operations and registers, GPIO, timers and PWM, interrupts, UART/SPI/I2C, ADC/DAC, memory-mapped I/O, RTOS basics, low power, bootloaders, build systems, debugging, MISRA-C and real chip families (AVR, STM32, ESP32). Simple English, many diagrams, 312 lessons and 628 live C examples that compile and run right in your browser, with a small simulated board for GPIO/UART/ADC/PWM output.
How to learn:Go in order. Read the theory, run the example, change it and run again, then read the checklist at the end of each lesson.
Getting Started
What Is Embedded C?2 live examplesSetting Up a Toolchain (Conceptual Overview)2 live examplesHow This Course Works (and the Live Sandbox)2 live examplesNumber Systems: Binary, Hex and Octal2 live examplesASCII and Character Encoding2 live examplesMicrocontroller vs Microprocessor2 live examplesChoosing a Chip Family for a Project2 live examplesAVR, STM32 and ESP32 at a Glance2 live examplesReading a Datasheet2 live examplesArduino-Style Libraries vs Bare-Metal C2 live examplesYour First Blink: a Full Walkthrough2 live examplesEmbedded Systems Around You2 live examplesCourse Roadmap: What You Will Learn2 live examples
C Language Refresher for Embedded
Variables and Fixed-Width Types2 live examplesstdint.h Types and Why They Matter2 live examplesOperators and Expressions2 live examplesif / else and switch2 live examplesfor, while and do-while Loops2 live examplesbreak, continue and goto2 live examplesFunctions and Scope2 live examplesstatic Local Variables2 live examplesArrays in C2 live examplesStrings and char Arrays2 live examplesPointers: the Basics2 live examplesPointer Arithmetic2 live examplesPointers and Arrays: the Relationship2 live examplesPointer to Pointer2 live examplesStructs in C2 live examplesNested Structs and Arrays of Structs2 live examplesUnions in C2 live examplestypedef for Cleaner Code2 live examplesEnums and Named Constants2 live examplesFunction Pointers2 live examplesCallbacks with Function Pointers2 live examplesRecursion and Its Cost in Embedded2 live examplesThe C Preprocessor and Macros2 live examplesHeader Files and Include Guards2 live examplesconst-Correctness in Embedded C2 live examplessizeof and Portable Code2 live examplesCommon C Pitfalls in Embedded Code2 live examples
Memory and Storage
Memory Layout: Flash, RAM, Stack and Heap2 live examplesThe Stack in Embedded Systems2 live examplesThe Heap and Why Embedded Code Avoids malloc2 live examplesThe static Keyword in Embedded C2 live examplesThe volatile Keyword Explained2 live examplesconst and Placing Data in Flash2 live examplesEndianness: Big and Little2 live examplesStruct Padding and Alignment2 live examplesLinker Sections: .data, .bss and .text2 live examplesReading a .map File2 live examplesStack Overflow and How to Catch It2 live examplesEEPROM and Non-Volatile Storage2 live examplesWear-Leveling Basics2 live examplesStoring Configuration in Flash2 live examplesCircular Buffers in Memory2 live examples
Bitwise Operations and Registers
Why Bitwise Operations Matter2 live examplesAND, OR, XOR, NOT Refresher2 live examplesLeft and Right Shifts2 live examplesSetting a Bit2 live examplesClearing a Bit2 live examplesToggling a Bit2 live examplesChecking If a Bit Is Set2 live examplesBit Masks Explained2 live examplesBit-Fields in Structs2 live examplesReading a Hardware Register2 live examplesWriting a Hardware Register2 live examplesThe Read-Modify-Write Pattern2 live examplesAtomic Bit Operations and Race Conditions2 live examplesCommon Bit-Manipulation Tricks2 live examplesRegister Naming Conventions2 live examplesBit-Banding Concept2 live examplesPacking Flags into a Single Byte2 live examplesCounting Set Bits2 live examplesExtracting a Multi-Bit Field from a Register2 live examples
GPIO: Digital Input and Output
What Is GPIO?2 live examplesDigital vs Analog Pins2 live examplesConfiguring Pin Direction2 live examplesPush-Pull vs Open-Drain Outputs2 live examplesPull-Up and Pull-Down Resistors2 live examplesWriting a Digital Output2 live examplesReading a Digital Input2 live examplesBlinking an LED2 live examplesDriving Multiple LEDs2 live examplesA "Knight Rider" LED Chaser2 live examplesReading a Push Button2 live examplesSoftware Debouncing a Button2 live examplesDriving a 7-Segment Display2 live examplesDriving a Relay or Buzzer2 live examplesGPIO Drive Strength and Speed2 live examplesCommon GPIO Mistakes2 live examplesDriving an LED Matrix2 live examplesReading a Keypad2 live examplesGPIO as a Makeshift Protocol: Bit-Banging2 live examplesInterfacing a Simple DIP Switch2 live examples
Timers and PWM
What Is a Hardware Timer?2 live examplesTimer Modes: One-Shot and Periodic2 live examplesPrescalers and Timer Resolution2 live examplesBusy-Wait Delay vs Timer Delay2 live examplesWhat Is PWM?2 live examplesPWM for LED Dimming2 live examplesPWM for DC Motor Speed Control2 live examplesPWM for Servo Control2 live examplesInput Capture Explained2 live examplesOutput Compare Explained2 live examplesMeasuring a Pulse Width2 live examplesThe Watchdog Timer as a Timer Peripheral2 live examplesA Real-Time Clock (RTC) Overview2 live examplesTimer-Based Cooperative Scheduling2 live examplesDebouncing a Button with a Timer2 live examples
Interrupts
What Is an Interrupt?2 live examplesThe Interrupt Vector Table2 live examplesWriting Your First ISR2 live examplesEnabling and Disabling Interrupts2 live examplesInterrupt Priority Levels2 live examplesNested Interrupts2 live examplesKeeping ISRs Short2 live examplesvolatile and Data Shared with an ISR2 live examplesCritical Sections: Disabling Interrupts Safely2 live examplesExternal Pin Interrupts2 live examplesTimer Interrupts2 live examplesUART Receive Interrupts2 live examplesDebouncing with an Interrupt2 live examplesInterrupt Latency Explained2 live examplesCommon Interrupt Bugs2 live examples
Serial Communication: UART, SPI, I2C
UART: The Basics2 live examplesBaud Rate Explained2 live examplesUART Framing: Start, Stop and Parity Bits2 live examplesSending Data over UART2 live examplesReceiving Data over UART2 live examplesInterrupt-Driven UART Reception2 live examplesA UART Ring (Circular) Buffer2 live examplesSPI: The Basics2 live examplesSPI Master and Slave Roles2 live examplesSPI Clock Modes: CPOL and CPHA2 live examplesSelecting Multiple SPI Devices2 live examplesI2C: The Basics2 live examplesI2C Addressing2 live examplesI2C Read and Write Transactions2 live examplesI2C with Multiple Masters2 live examplesChoosing UART, SPI or I2C2 live examplesDesigning a Simple Text Command Protocol2 live examplesChecksums and CRC Basics2 live examplesImplementing a Command Parser2 live examplesDebugging Serial Communication2 live examples
Analog I/O: ADC and DAC
What Is an ADC?2 live examplesADC Resolution and Reference Voltage2 live examplesReading a Sensor with the ADC2 live examplesADC Sampling Rate and Aliasing2 live examplesAveraging and Filtering ADC Readings2 live examplesWhat Is a DAC?2 live examplesGenerating a Simple Waveform with a DAC2 live examplesAnalog Comparators Explained2 live examplesInterfacing a Thermistor or LDR2 live examplesNoise and Grounding Basics2 live examplesMultiplexing Multiple Analog Channels2 live examplesCalibrating an Analog Sensor2 live examplesDifferential vs Single-Ended ADC Inputs2 live examplesOversampling for Extra Resolution2 live examples
Memory-Mapped I/O and Peripherals
Memory-Mapped I/O Explained2 live examplesModeling Registers as C Structs2 live examplesThe Read-Modify-Write Pitfall on Registers2 live examplesDirect Register Access vs Vendor HAL2 live examplesWhat Is DMA?2 live examplesDMA for UART and ADC2 live examplesPeripheral Clocks and Power Gating2 live examplesA Quick Tour of Bus Architectures2 live examples
RTOS Basics
Why Use an RTOS?2 live examplesTasks vs a Bare-Metal Super-Loop2 live examplesPreemptive vs Cooperative Scheduling2 live examplesTask States Explained2 live examplesContext Switching Explained2 live examplesTask Priorities2 live examplesMutexes Explained2 live examplesSemaphores Explained2 live examplesMessage Queues Between Tasks2 live examplesSoftware Timers in an RTOS2 live examplesSizing a Task Stack2 live examplesPriority Inversion and How to Avoid It2 live examplesA FreeRTOS-Style Overview2 live examplesChoosing RTOS vs Bare-Metal2 live examplesCommon RTOS Pitfalls2 live examples
Low Power Design
Why Power Consumption Matters2 live examplesMicrocontroller Sleep Modes2 live examplesWake-Up Sources2 live examplesClock-Gating Unused Peripherals2 live examplesReducing Active-Mode Current2 live examplesMeasuring Current Draw2 live examplesLow-Power Design Patterns2 live examplesDesigning for Battery Power2 live examples
Watchdog, Reliability and Safety
The Watchdog Timer Explained (In Depth)2 live examplesBrown-Out Detection2 live examplesDefensive Coding for Embedded C2 live examplesError Handling Without Exceptions2 live examplesUsing assert() in Embedded Code2 live examplesHard Fault Handlers Explained2 live examplesRedundancy and Fail-Safe Design2 live examplesMISRA-C Overview2 live examplesStatic Analysis for Embedded C2 live examples
Bootloaders and Firmware Updates
What Is a Bootloader?2 live examplesFlash Layout: Bootloader and Application2 live examplesJumping from Bootloader to Application2 live examplesFirmware Update over UART2 live examplesFirmware Update over USB or OTA (Concept)2 live examplesVersioning Firmware Images2 live examplesCRC-Checking a Firmware Image2 live examplesRollback Strategies for Updates2 live examples
Build Systems and Toolchains
Makefiles for Embedded Projects2 live examplesCMake for Embedded Projects2 live examplesLinker Scripts Explained2 live examplesStartup Code and the Reset Handler2 live examplesThe Vector Table in the Build2 live examplesCompiler Flags for Embedded Targets2 live examplesOptimization Levels and Embedded Pitfalls2 live examplesCross-Compilation Recap2 live examplesContinuous Integration for Firmware2 live examplesReproducible Firmware Builds2 live examples
Debugging Embedded Systems
JTAG and SWD Explained2 live examplesUsing a Hardware Debugger2 live examplesprintf Debugging vs Hardware Debugging2 live examplesLogic Analyzers Explained2 live examplesOscilloscopes for Firmware Developers2 live examplesCommon Embedded Bug Classes2 live examplesDebugging with Just an LED2 live examplesDebugging Interrupt-Related Bugs2 live examplesPost-Mortem and Crash Dumps2 live examplesHost-Based Unit Testing for Embedded Code2 live examples
Chip Families: AVR, STM32, ESP32
AVR Architecture Overview2 live examplesAVR-Style GPIO Registers2 live examplesSTM32 Architecture Overview2 live examplesSTM32 HAL vs Register-Level Access2 live examplesSTM32 Clock Tree Explained2 live examplesESP32 Architecture Overview2 live examplesESP32 Wi-Fi and Bluetooth in Context2 live examplesARM Cortex-M Overview2 live examplesComparing AVR, STM32 and ESP322 live examplesChoosing a Chip for Your Project2 live examplesPin Muxing and Alternate Functions2 live examplesChip-Specific Gotchas2 live examplesMigrating Code Between Chip Families2 live examplesVendor SDKs Overview2 live examplesDatasheet Walkthrough: A Worked Example2 live examples
Embedded C Design Patterns and Best Practices
State Machines in C2 live examplesPolling vs Event-Driven Design2 live examplesCircular Buffers as a Design Pattern2 live examplesThe Producer-Consumer Pattern in Firmware2 live examplesLookup Tables for Speed2 live examplesFixed-Point Math on MCUs Without an FPU2 live examplesFloating-Point on Microcontrollers and When to Avoid It2 live examplesWriting Portable Driver Code2 live examplesHardware Abstraction Layers Explained2 live examplesConfiguring Firmware with Compile-Time Constants2 live examplesLogging on Resource-Constrained Devices2 live examplesBuild Metadata and Firmware Versioning2 live examplesA Code Review Checklist for Embedded C2 live examplesWriting More Testable Embedded Code2 live examplesRefactoring Legacy Firmware Safely2 live examples
Testing and Quality for Embedded C
Why Testing Embedded Code Is Different2 live examplesUnit Testing Strategies for Firmware2 live examplesMocking Hardware in Tests2 live examplesTest-Driven Development for Embedded C2 live examplesCode Coverage for Embedded Projects2 live examplesFuzzing an Input Parser2 live examplesStatic Analysis Tools for Embedded C2 live examplesContinuous Integration Test Pipelines for Firmware2 live examplesRegression Testing Firmware Changes2 live examplesDocumentation and Changelogs for Firmware2 live examples
Embedded Networking and IoT Basics
Embedded Networking Overview2 live examplesTCP/IP Concepts on Microcontrollers2 live examplesMQTT Basics for IoT Devices2 live examplesHTTP Basics for IoT Devices2 live examplesProvisioning an IoT Device2 live examplesOTA Updates Over a Network, Revisited2 live examplesSecurity Basics for IoT Devices2 live examplesSecure Boot Concept2 live examplesEncrypting Data on Constrained Devices2 live examplesTLS on Constrained Devices (Concept)2 live examplesDevice-to-Cloud Communication Patterns2 live examplesEdge Processing vs Cloud Processing2 live examples
Embedded Interview Preparation
Embedded Interview Overview2 live examplesExplaining volatile in an Interview2 live examplesExplaining Interrupts in an Interview2 live examplesExplaining Memory Layout in an Interview2 live examplesSystem Design Questions for Embedded Roles2 live examplesBehavioral Questions for Firmware Roles2 live examplesWhiteboard Bit-Manipulation Problems2 live examplesBuilding a Portfolio of Embedded Projects2 live examplesEmbedded Job Titles and Career Paths2 live examplesWhat to Expect in Role and Salary Conversations2 live examples
Real Projects
Project: LED Toggle with a Button2 live examplesProject: Knight Rider LED Chaser2 live examplesProject: Debounced Counter with a 7-Segment Display2 live examplesProject: PWM LED Dimmer with a Potentiometer2 live examplesProject: Servo Controller via PWM2 live examplesProject: UART Command Console2 live examplesProject: UART Echo and "Chat" Server2 live examplesProject: ADC Temperature Data Logger2 live examplesProject: I2C Sensor Driver2 live examplesProject: SPI Display Driver Pattern2 live examplesProject: State-Machine Traffic Light2 live examplesProject: Watchdog-Protected Main Loop2 live examplesProject: Interrupt-Driven Button Counter2 live examplesProject: Cooperative Task Scheduler2 live examplesProject: Two-Task RTOS Demo2 live examplesProject: Low-Power Sleep/Wake Demo2 live examplesProject: Bootloader Jump-to-Application2 live examplesProject: CRC-Checked Firmware Validator2 live examplesProject: Checksum-Protected Command Protocol2 live examplesCapstone Project: Simulated Smart Thermostat2 live examples