Embedded C on the Arduino Uno R3
Learn how the ATmega328P works beneath the familiar Arduino board. This course takes you from the first register-level C program through GPIO, timers, communication interfaces, analogue input, memory and complete sensor and module examples.
Start Learning: Open the ATmega328P Course

Who Is This Course For?
The course is for students, hobbyists and working engineers who know basic C and want to understand how a microcontroller interacts with hardware. You do not need previous experience with embedded systems. Lessons introduce the electronics and microcontroller ideas as they are needed.
The examples target an Arduino Uno R3 with an ATmega328P running at 16 MHz. Other Arduino boards may use a different microcontroller and are not interchangeable with these examples.
How The Course Works
We begin with direct ATmega328P register programming in C, so you can see how the processor configures and uses its peripherals. Later lessons introduce the course HAL and show how to organise reusable drivers. Each maintained lab also includes an Arduino IDE sketch for comparison; the lessons explain what the Arduino core handles and which peripherals it may already use.
You can build the C projects with MPLAB for VS Code and XC8, or use the supplied command-line build tool with AVR GCC. Open the comparison sketches in Arduino IDE 2.x. Each practical lesson links its source, describes the circuit and wiring, walks through the important code, and explains how to build, upload and observe the result.
What You Will Need
- An Arduino Uno R3 board with the ATmega328P and a USB data cable.
- A computer running Windows for the setup examples, with VS Code, the MPLAB extension and XC8 installed as described in the setup lessons.
- A breadboard, jumper wires, an LED and a suitable series resistor, and a push button for the first exercises.
- A multimeter is useful. Additional components are listed in the relevant module lessons.
The course starts with small, low-voltage circuits. Follow each wiring diagram, use a current-limiting resistor for LEDs, and use a suitable driver and external supply for motors, relays and other loads.
What You Will Learn
- How an embedded system differs from a general-purpose computer, and how to plan and maintain firmware.
- How the AVR CPU executes instructions and uses registers, Flash, SRAM, EEPROM, clocks and interrupts.
- How to configure GPIO and connect buttons, displays, keypads, shift registers and sensors.
- How to use timers, counters, PWM and input capture for timing, motor control, sound, servos and encoders.
- How SPI, USART and TWI/I²C transactions work, from peripheral registers to reusable drivers.
- How to sample analogue signals with the ADC and use the analogue comparator.
- How to work with EEPROM and Flash, and how to connect common sensors, displays, radios, storage devices and actuators.
- How to use state machines, ring buffers, sleep modes and the watchdog in small microcontroller projects.
Course Lessons
Use the linked lessons below in order, or open the course and choose a topic from its navigation and search.
Introduction
Setup And Installation
- Choosing MPLAB For VS Code And Arduino IDE
- Installing VS Code, MPLAB And XC8
- Connecting An Uno R3 On Windows
- Upload Uno R3 Firmware Through USB
- Usbasp And ISP Programming
- Your First Register-Level Blink
- Upload And Verify Blink
- Setup Checkpoint
Embedded Systems
- What Makes A System Embedded?
- Embedded Controller Or General-Purpose Computer?
- Case Study: An Automatic Night Light
- Microprocessors And Microcontrollers
- From Product Requirement To Maintained Firmware
- Embedded Systems Checkpoint
AVR Architecture
- The AVR Microcontroller Families
- The ATmega328P At A Glance
- ATmega328P Specifications And Practical Limits
- Uno Pin Names And ATmega328P Alternate Functions
- How The AVR CPU Executes Instructions
- Flash, SRAM, EEPROM And The AVR Address Spaces
- The Uno Clock And AVR Clock Domains
- External And Internal Interrupts
GPIO
- GPIO Concepts
- ATmega328P GPIO Registers
- Programming GPIO In C
- Reading And Debouncing A Push Button
- Interfacing A Seven-Segment Display
- Build A Running LED Pattern
- Using An IR Reflective Sensor Module
- Interfacing A 4Ć4 Matrix Keypad
- Interfacing An 8Ć8 LED Matrix
- Using The GPIO HAL
- SN74HC595 Serial-In Shift Register
- SN74HC164 Serial-In Shift Register
Timers And PWM
- Timer/counter0 On The ATmega328P
- Timer/counter1 On The ATmega328P
- Timer/counter2 On The ATmega328P
- Use A Timer For System Delays
- Control LED Brightness With PWM
- Control A DC Motor With PWM
- Generate Tones With A Buzzer
- Measure Pulse Width With Input Capture
- Drive An SG90 Servo With Timer1
- Handle Timer Events With An Interrupt
- Using The Timer HAL
- Potentiometer-Controlled Servo
- Quadrature Rotary Encoder
SPI
- SPI Concepts
- ATmega328P SPI Registers
- Programming An SPI Transaction
- Using The SPI HAL
- SPI Questions And Answers
USART
- UART And Asynchronous Serial
- ATmega328P USART Registers
- Send And Receive UART Data
- Using The UART HAL
- USART Synchronous SPI Mode
- UART Questions And Answers
TWI And I²C
- TWI And I²C Bus Concepts
- ATmega328P TWI Registers
- Program A TWI Transaction
- Using The TWI HAL
- TWI Questions And Answers
Analogue Comparator
ADC
- ADC Concepts And Sampling
- ATmega328P ADC Registers
- Read An ADC Channel In C
- Control LED PWM With A Potentiometer
- Measure Temperature With An LM35
- Handle ADC Completion With An Interrupt
- Using The ADC HAL
- Battery Voltage Indicator
Nonvolatile Memory
Sensors, Displays And Modules
- Light-Dependent Resistor Threshold Lamp
- LM335 Temperature Sensor
- BMP180 Pressure Sensor
- IR Slot Interrupter
- HC-SR04 Ultrasonic Range Finder
- MPU6050 Accelerometer And Gyroscope
- ADXL335 Three-Axis Accelerometer
- HD44780 16Ć2 Character LCD
- PCD8544 Nokia 5110 Display
- ST7735 TFT Display
- 28BYJ-48 Stepper Motor With ULN2003
- HC-05 Bluetooth Serial Link
- ESP8266 At-Command Wi-Fi
- nRF24L01++ Radio Link
- SPI Microsd Card And FAT16 Files
- 10 kΩ NTC Thermistor
- Amplified Microphone Module
- A3144 Hall-Effect Switch
- MFRC522 RFID UID Reader
- GPS Receiver And NMEA Data
- SIM800L GSM Modem
- XBee S2C Serial Radio Link
- Relay Module And Transistor Driver
- QTR-8RC Reflectance Sensor Array
- TB6612FNG And L298 Motor Driver Comparison
- L298N Motor Driver Interfacing
- TB6612FNG Motor Driver Interfacing
- Smartelex RLS08 Eight-Channel Line Sensor
- 0.96-Inch SSD1306 OLED Display
Advanced Topics
- USART Multi-Processor Communication
- Idle Sleep With A Timer Wake-Up
- Capacitive Touch With An RC Timing Method
- Watchdog Timer And Reset Diagnosis
Embedded C Foundations
- Binary, Hexadecimal And Bit Masks
- Integer Widths And Promotions
- Pointers, Registers And Address Spaces
- Volatile And Atomic Access
- Compile, Link And Inspect Firmware
- Startup, Stack And Memory Budgets
- State Machines And Cooperative Scheduling
- Ring Buffers And Interrupt Ownership
- Logic Levels, Supplies And Safe Loads
- Debugging With Traces And Instruments
- Firmware Testing, Documentation And Git
Code, Experiments And Reference Material
The course pages link to the firmware for each example. You can browse or clone the repositories directly:
- ATmega328P Lab ExperimentsĀ ā buildable examples, wiring information and exercises.
- ATmega328P HAL LibraryĀ ā reusable C peripheral and device-driver code.
- HAL API ReferenceĀ ā generated documentation for the library interfaces.
- Uno R3 PinoutĀ ā Arduino header pins and their ATmega328P functions.
- Course Markdown and rendered diagrams on GitHub.
To clone the course source and its linked repositories:
git clone --recurse-submodules https://github.com/arnabdasbwn/atmega328p-tutorial.git
Start Learning
Begin with Course Introduction And Learning Path, continue with Installing VS Code, MPLAB And XC8, and build Your First Register-Level Blink.
29 Comments
Rahul Barnwal · December 15, 2022 at 3:45 pm
Please Update the I2C part as soon as possible.
Ben · March 5, 2023 at 12:43 pm
Sir, it’s 2023, is the course still actively updated? I’m amazed and really intrested in your course structure, and glad it is free. However even if it’s not free i’d be happy to pay for full access to the finished course contents. If there’s a way to support (donate) you to finish the contents i’d be happy to help sir. Thanks
Crazy Engineer · April 5, 2023 at 11:03 am
Ben, I am short of time and thus slow in adding new content to the course, feel free to explore the internet.
Amir · December 8, 2023 at 2:49 am
New for learning
Abdullah · May 25, 2024 at 3:25 pm
Hey man, just wanted to say keep it up and take your time, this seems like an amazing course and its awesome that its free!
Also bit of a common and overused question, but I have experience with Python, a little bit of C/C++ (made a crappy and very basic text editor in C and done some projects for Arduino) but would like to ask what would be a good way to get into assembly (thought learning AVR assembly would be a good idea since arduino is such an open microcontroller) or what could be some projects I can make with AVR asm.Thanks!
Patrick Akugizibwe · August 7, 2024 at 4:35 pm
Am Interested in the course
K.Seetharaman · April 16, 2025 at 4:56 pm
sir
i am also interested to learn what is the timing and course fees,i am working in chemical industry E&I Dept
Crazy Engineer · November 9, 2026 at 10:16 pm
Tutorial is Updated. Enjoy Learning.