Arduino Explained · 23 November 2026
How Does an Arduino Actually Work? From Your Sketch to One Pin Going HIGH
What happens between digitalWrite(13, HIGH) and 5 volts on a pin: the compiler, the upload, the bootloader, the ATmega328P, and the one bit in one register that does it.
Blink is the first program everyone runs. Two lines: set pin 13 HIGH, wait, set it LOW, wait. An LED blinks and you move on. Which is a shame, because between digitalWrite(13, HIGH) and the LED lighting up there is an entire computer doing something you can actually follow, bit by bit, all the way down.
What is a microcontroller, in an easy way?
A microcontroller is a complete computer on one chip: processor, program memory, RAM and the input/output pins, all in one package, with no operating system. The Arduino Uno’s chip is the ATmega328P, a 28-pin part with 32 KB of flash for your program, 2 KB of RAM, and an 8-bit CPU ticking at 16 MHz.
That’s the whole difference between a microcontroller and a microprocessor. A Raspberry Pi’s chip is a microprocessor: it needs external RAM, an SD card for storage, and Linux to boot, and it runs your program as one of hundreds. The ATmega runs one program, yours, starting the instant power arrives, with nothing in between. That’s why an Arduino can toggle a pin in a few nanoseconds of certainty and a Pi can’t promise anything about timing at all.
Is Arduino just C++?
Yes. The “Arduino language” is C++ with a library and a small amount of pre-processing. When you click Upload, the IDE takes your sketch, adds #include <Arduino.h> at the top, generates prototypes for your functions, and hands the result to avr-gcc, the standard GNU C++ compiler built for AVR chips. Your setup() and loop() are ordinary functions. The library supplies the main() you never see:
int main() {
init(); // start the timers that millis() and PWM use
setup(); // yours, once
for (;;) {
loop(); // yours, forever
}
}
loop() repeats because it’s called inside an infinite for. There’s no scheduler, no operating system. When loop() returns, main() calls it again. Forever.
How does the code get onto the chip?
The compiler produces a .hex file: the raw bytes of machine code. Now it has to reach the chip’s flash memory, and the chip is in the middle of running whatever was there before.
The IDE runs avrdude, which talks over the USB cable. On an Uno, USB doesn’t go to the ATmega328P directly; it goes to a second, smaller chip (an ATmega16U2) that pretends to be a serial port. avrdude first toggles the serial port’s DTR line, which, through a 100 nF capacitor, yanks the 328P’s reset pin low for a moment. The chip reboots.
The first thing it runs after reset isn’t your program. It’s the bootloader (Optiboot), half a kilobyte of code living at the top of flash, which listens on the serial pins for about a second. If avrdude shows up speaking the STK500 protocol, the bootloader accepts the new program page by page, writes it into flash, and jumps to it. If nobody shows up, it jumps to whatever program is already there. That one-second pause after you press reset is the bootloader waiting to be told what to do.
What does digitalWrite actually do?
Now the LED. Your program is running. It calls digitalWrite(13, HIGH).
The 328P doesn’t know about “pin 13”. It has three ports, B, C and D, each a group of up to eight pins, and each port is controlled by a handful of memory-mapped registers. Pin 13 on the Uno board is wired to PB5: port B, bit 5. The Arduino library keeps lookup tables in flash that translate 13 into “port B, bit 5”, and then does, in effect:
PORTB |= (1 << 5); // set bit 5 of the PORTB register
PORTB is a byte at a fixed address in the chip’s memory. Writing a 1 to its bit 5 is the entire operation. On the far side of that register, a pair of transistors connects the physical pin to 5 V (for a 1) or to ground (for a 0). Those transistors can source or sink about 40 mA at most, which is why you put a resistor in series with the LED: the pin is a switch, not a battery.
The lookup, the port read-modify-write and the checks inside digitalWrite() take around 4 microseconds on an Uno. Write to the register directly and it takes one clock cycle, 62.5 nanoseconds. Same bit, same transistors; the library just takes the scenic route so that “13” means the same thing on every board.
How does delay() work if there’s no operating system?
Because the chip has hardware timers. init() set up Timer 0 to overflow every 1.024 ms and fire an interrupt: a hardware event that pauses your code, runs a tiny function that adds one to a counter, and resumes. That counter is millis(). delay(1000) just spins in a loop reading millis() until it has grown by 1000. The CPU is doing nothing useful during that second, which is why delay() is the thing you outgrow first.
What are the 28 pins of the ATmega328P?
Twenty-three are I/O: port B (8), port C (7, of which six double as the analogue inputs A0 to A5), and port D (8, including the two serial pins). The other five are power and ground, the analogue reference, and two for the 16 MHz crystal. Every “digital pin 7” or “A3” on the board is just one of those 23, given a friendlier name by the silkscreen and a lookup table.
That’s the whole trip. C++ to machine code, serial cable to bootloader, bootloader to flash, digitalWrite to PORTB, bit 5 to two transistors, transistors to 5 V, 5 V through a resistor to an LED. Nothing in it is magic, and all of it is yours to touch.
Was this useful? The video version is on YouTube — a like or a comment there helps more people find it. New guides every week: subscribe to DigiCirq.
Topics: how does arduino work · how does an arduino work · how does arduino code work · what is a microcontroller · microcontroller vs microprocessor · is arduino just c++ · atmega328p · arduino uno pins
Keep going
What Does a Pull-Up Resistor Do? (And Why Your Button Reads Random Values Without One)
A pull-up resistor gives an input pin a definite voltage when nothing drives it. Why a floating pin reads garbage, what value to use, and pull-up vs pull-down.
11 Nov 2026
What Is a Decoupling Capacitor? (Values, Placement, and Why Your Chip Resets Without One)
A decoupling capacitor is a tiny local battery beside a chip's power pin. Why 100 nF, why it must sit close to the pin, which leg goes to ground, decoupling vs bypass.
17 Nov 2026
Button Debouncing Explained: Why One Press Counts as Three (and How to Fix It)
Mechanical switches bounce for a few milliseconds every press. Here's what that looks like on a scope, and three ways to debounce: a delay, millis(), and an RC filter.
12 Nov 2026
What Is a Flip-Flop Circuit? SR, D, JK and T Flip-Flops Explained
A flip-flop is one bit of memory made from two gates that feed each other. How the SR latch holds a value, what the clock adds, and what D, JK and T flip-flops are for.
18 Nov 2026