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
Yogesh Modi · November 12, 2018 at 3:10 am
How can i take this course?
Crazy Engineer · November 12, 2018 at 8:21 am
Hi Yogesh, Thanks a lot to check this course. I am currently writing the Tutorial and it is in progress. It will take a couple of Months to complete. This Course is completely Industry Specific. I am writing and hosting each topic one after another. So You can come back to the page each week and see a new topic and follow the sequence. Till then you can explore other free websites for tutorials. I will let you know when I finish the write-up.
photon · April 6, 2019 at 5:58 pm
Ummm. How do I ACTUALLY view the course??? There’s only a few things open. Are you still working on this, or is this it?
Thanks for having atleast something. Its been really hard to find good tutorials teaching this exact topic!
Crazy Engineer · April 16, 2019 at 8:15 pm
Hi, Thanks for Appreciating. I am currently working on this. I will be Updating the rest of the topics. Till then Happy Making and Programming.
Dandi · December 21, 2019 at 2:12 pm
Hey, any updates? I’d love to have see more content by you. the tutorials so far are very professional and instructive. Kudos
Crazy Engineer · December 31, 2019 at 7:35 pm
Thanks, Dandi. I am trying my best to have time to write the full tutorial.
Njoku Okechukwu Valentine · December 30, 2018 at 10:15 am
Good day Sir.
What a good work you are doing! Keep it up. But how can linux (mint 19) try out this program codes and stuff.
I have browsed and there seems not to be Atmel Studio for linux users.
Thanks in advance
Crazy Engineer · December 30, 2018 at 11:42 am
Hi Nojoku,
Thanks for seeing the tutorial. You are right Atmel Studio is only for Windows. But don’t worry Linux has Cross Compilers in it to support AVR.
Here are a few resources that can help you.
http://techawarey.com/embedded/setup-of-avr-cross-compiler-in-ubuntu-linux-mint-fedora/
https://electronics.stackexchange.com/questions/66145/avr-how-to-program-an-avr-chip-in-linux/66163
http://www.tldp.org/HOWTO/Avr-Microcontrollers-in-Linux-Howto/x207.html
Please Subscribe to my YouTube for Project Videos https://www.youtube.com/c/ArnabDasBwn
MANIKANTAN K V · March 26, 2020 at 4:49 pm
Im very much intrested on the content of the tutorial,how can i access it .still some contents are not available. is it complete soon?
Crazy Engineer · March 31, 2020 at 10:02 pm
I am under progress to add more content. Please explore the web meantime.
PETER · May 23, 2020 at 8:35 pm
HOW CAN I TAKE THIS COURSE PLEASE
George E Cole · January 29, 2021 at 1:18 am
Ditto Peter. I’d be interested in having access to more of the course content. I stumbled over your taster article which detailed some of the concepts of register/port/pin manipulation I had gleened from (various) other resources. The contents of your trutorial would seem to put together a lot of what I want to learn. I’ve ditched Arduino (using it as a bootstrap loader) for naked ATMega328Ps – as I’m as interested in the glue electronics and pcb assembly as software. Link Njoku, I’m no Windoze fan, so am using Visual Studio Code / Platformio (on Mac – which looks like Linux 😉 ) and is a pretty nice environment. I’m a retired and rusty embedded systems engineer revisiting my past. How things have changed since the 80’s 🙂
Crazy Engineer · February 6, 2021 at 11:32 pm
Thank you, George, for visiting my tutorial. Thank you for sharing your experience and views. I am working hard for delivering more tutorials. Stay Tuned.
rene caillet · February 2, 2021 at 5:10 pm
Bonjour,
Ce que vous avez fait jusqu’à présent est super et j’apprends beaucoup. Vivement la suite, je ne trouve pas de meilleurs tutoriel que le votre.
Encore merci pour le temps consacré aux autres.
René
Crazy Engineer · February 6, 2021 at 11:35 pm
Dear Rene, Thank You for visiting my page and finding my tutorial interesting and helpful. I am working hard to deliver more tutorials, Stay Tuned.
Cher René, Merci d’avoir visité ma page et d’avoir trouvé mon tutoriel intéressant et utile. Je travaille dur pour fournir plus de tutoriels, Restez à l’écoute.
Chirag · April 7, 2021 at 4:29 pm
Is this course open source or any fees for this course?
Crazy Engineer · April 14, 2021 at 3:26 pm
Hi Chirag, This course is completely free and open. Please learn from this and share it with your friends.
Sangaran D K · September 2, 2021 at 8:56 am
When your full course is will be available? Kindly answer me.
Crazy Engineer · September 2, 2021 at 9:40 pm
Some Part is Available for Access, Thanks For Choosing
uttam · September 15, 2021 at 6:13 pm
How can i take this course?
Dhruv · September 7, 2022 at 4:06 pm
Please make it accessible as soon as possible…course looks interesting