An interactive field manual for the board that taught a generation to blink an LED — every pin, every limit, and the twelve things that quietly break your first project.
What an Arduino Uno actually is
Strip away the branding and an Arduino Uno is three things bolted to one piece of fibreglass: an 8-bit ATmega328P microcontroller running at 16 MHz, a second chip whose only job is to translate USB into serial so you can talk to the first one, and a set of header sockets that bring every useful leg of that microcontroller out to somewhere a jumper wire can reach.
That is the whole trick. The ATmega328P on its own is a 28-pin chip that needs a crystal, a programmer, a regulated supply and a breadboard before it will do anything. The Uno is that chip pre-wired with all of its inconvenient requirements already solved, so the first thing you have to learn is code, not soldering.
It is deliberately, almost stubbornly, under-powered. A modern ESP32 has roughly 16× the SRAM, 8× the flash and a clock fifteen times faster, plus Wi-Fi. The Uno survives anyway, for four reasons that matter more than specifications:
- It is 5 V native. The vast catalogue of hobby sensors, relay boards and motor drivers built for 5 V logic plug straight in with no level shifting.
- It is deterministic. No Wi-Fi stack, no RTOS, no background tasks stealing cycles. Your
loop()is the only thing running, so timing you measure is timing you get. - It is hard to kill. A DIP-28 socket version lets you replace a dead microcontroller for pocket change; the rest of the board tolerates abuse that would end a bare ESP module.
- It is the reference. Two decades of tutorials, shields, libraries and school syllabi assume this pinout. When something goes wrong, somebody has already written it down.
Flip the board over, or look next to the USB socket. A USB-B printer-style socket and a long black DIP chip means Uno R3 (ATmega328P) — the board this guide is built around. A USB-C socket means Uno R4, which keeps the same shape and 5 V pins but swaps in a 48 MHz 32-bit Renesas chip. Nearly everything here still applies to the R4; the comparison table marks the places it does not.
Every component on the board, and why it is there
Tap any part of the diagram. Twelve components do all the work — and two of them are microcontrollers, which surprises most people.
Board anatomy explorer
A schematic layout, not a photograph — parts are drawn where they sit, sized for legibility.
The complete Uno pinout, pin by pin
Thirty documented connections. Filter by role, search by name, then tap a pin for its port register, alternate functions, current limit and the mistake people make with it.
Pinout explorer
Colour on the left edge of each pin encodes its silicon role, not its position on the board.
Pinout diagrams scraped from the Nano show A6 and A7. The Uno does not have them. The DIP-28 ATmega328P package simply does not bring those two ADC channels out to a leg — they exist only on the surface-mount TQFP/QFN versions used by the Nano and Pro Mini. Code referencing A6 on an Uno compiles happily and then reads garbage.
Specifications, and how the Uno compares
The first table is the Uno R3 datasheet reduced to what you will actually hit. The second shows when to stop reaching for an Uno.
| Parameter | Value | What this means in practice |
|---|---|---|
| Microcontroller | ATmega328P | 8-bit AVR, Harvard architecture, 131 instructions |
| Clock speed | 16 MHz | 62.5 ns per cycle; most instructions run in 1–2 cycles |
| Flash memory | 32 KB | 0.5 KB taken by the bootloader → 31.5 KB for your sketch |
| SRAM | 2 KB | All variables, buffers and the stack share 2,048 bytes |
| EEPROM | 1 KB | Survives power-off; rated ~100,000 writes per cell |
| Digital I/O pins | 14 (D0–D13) | D0/D1 are shared with USB serial — treat as 12 free |
| PWM outputs | 6 (D3, 5, 6, 9, 10, 11) | 8-bit duty, 490 Hz or 980 Hz depending on timer |
| Analog inputs | 6 (A0–A5) | 10-bit, 0–1023, one shared ADC multiplexed between them |
| ADC resolution | 10-bit | 4.88 mV per step at the default 5 V reference |
| ADC conversion time | ~100 µs | Ceiling of roughly 9,600 analogRead() calls per second |
| DC current per I/O pin | 20 mA recommended | 40 mA is the absolute maximum — past it the pin driver degrades |
| Total I/O current | 200 mA | Hard ceiling through the VCC and GND legs of the chip |
| 3.3 V pin current | 50 mA | Comes from a small LDO, not the main regulator — easily overloaded |
| Operating voltage | 5 V logic | HIGH is ~5 V out; inputs read HIGH above about 3.0 V |
| Input voltage (jack) | 7–12 V recommended | Absolute limits 6–20 V; above 12 V the regulator cooks |
| USB protection | 500 mA polyfuse | Resettable — it opens on overload and recovers when you unplug |
| External interrupts | 2 (D2 = INT0, D3 = INT1) | Only these two work with attachInterrupt() in the core |
| Hardware timers | 3 (Timer0/1/2) | Timer0 runs millis(); Timer1 is claimed by Servo |
| Board size / weight | 68.6 × 53.4 mm / 25 g | The shield form factor every Uno-compatible board copies |
| Uno R3 | Uno R4 Minima | Uno R4 WiFi | Nano | Mega 2560 | ESP32 DevKit | |
|---|---|---|---|---|---|---|
| MCU | ATmega328P | RA4M1 | RA4M1 | ATmega328P | ATmega2560 | ESP32 |
| Bits / clock | 8 / 16 MHz | 32 / 48 MHz | 32 / 48 MHz | 8 / 16 MHz | 8 / 16 MHz | 32 / 240 MHz |
| Flash | 32 KB | 256 KB | 256 KB | 32 KB | 256 KB | 4 MB |
| SRAM | 2 KB | 32 KB | 32 KB | 2 KB | 8 KB | 520 KB |
| Logic level | 5 V | 5 V | 5 V | 5 V | 5 V | 3.3 V |
| ADC bits | 10 | 14 | 14 | 10 | 10 | 12 |
| True DAC | No | 1 × 12-bit | 1 × 12-bit | No | No | 2 × 8-bit |
| Digital I/O | 14 | 14 | 14 | 14 | 54 | ~34 |
| Wi-Fi / BLE | No | No | Yes | No | No | Yes |
| USB socket | USB-B | USB-C | USB-C | Mini/Micro | USB-B | Micro/USB-C |
| Jack input | 7–12 V | 6–24 V | 6–24 V | None | 7–12 V | None |
| Shield compatible | Yes | Yes | Yes | No | Yes | No |
| Reach for it when | Learning, 5 V sensors, shields | Same shape, more headroom | Uno shape plus IoT | Breadboard builds | You ran out of pins | Wi-Fi, heavy maths |
Read that last row carefully. Ninety per cent of “I need to upgrade from the Uno” turns out to be one of two things: out of pins (go Mega) or out of SRAM (go R4 or ESP32). If you are weighing the jump, our ESP32 vs ESP8266 vs Arduino Uno R4 comparison works through it properly. Clock speed is almost never the bottleneck in a hobby project — at 16 MHz you still get around a million loop() iterations a second if you stop calling delay().
2 KB of SRAM is the thing that will bite you
The Uno has three separate memories and beginners routinely confuse them:
- Flash — 32 KB. Your compiled program. Non-volatile. The bootloader eats 512 bytes, leaving 32,256 for you. The IDE tells you how much you used.
- SRAM — 2 KB. Every variable, every array, every buffer, plus the call stack, all in 2,048 bytes. Volatile. The IDE’s estimate here is a guess, because it cannot see what your code allocates at runtime.
- EEPROM — 1 KB. Non-volatile storage for settings you want to survive a power cut. Slow to write (~3.3 ms per byte) and wears out after roughly 100,000 writes per cell.
Flash is rarely the problem. SRAM is almost always the problem, and it fails in the worst possible way: not with an error, but with your board silently rebooting, printing nonsense, or freezing — because the stack grew down into your variables and corrupted them. Budget it deliberately.
SRAM budget
Add what your sketch uses. Keep the total under about 1,500 bytes so the stack has room to breathe.
Three fixes that reclaim hundreds of bytes
Every string literal you hand to Serial.print() is copied from flash into SRAM when the board boots, and stays there forever. Wrapping it in F() leaves it in flash and streams it out character by character:
// 1. Keep string literals in flash with F() — saves 1 byte per character
Serial.println("Temperature sensor ready"); // 25 bytes of SRAM, gone forever
Serial.println(F("Temperature sensor ready")); // 0 bytes of SRAM
// 2. Pick the smallest type that fits. A pin number is never a 2-byte int.
int ledPin = 13; // 2 bytes
uint8_t ledPin = 13; // 1 byte — range 0..255
// 3. Avoid the String class. It fragments the heap and crashes slowly.
String msg = "val: "; msg += value; // heap churn, unpredictable
char msg[16]; snprintf(msg, sizeof(msg), "val: %d", value); // fixed, safe
// 4. Read your actual free SRAM at runtime — the only honest number
int freeRam() {
extern int __heap_start, *__brkval;
int v;
return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int)__brkval);
}
Print freeRam() in setup() and once a second in loop() while developing. If the number drifts downward over minutes, you have a leak — almost certainly String concatenation inside the loop.
Three ways in, and the arithmetic that stops the brownouts
More first projects die from an honest power mistake than from bad code.
The three input paths
- USB (5 V). Goes through a 500 mA resettable polyfuse straight onto the 5 V rail, bypassing the regulator. Your laptop port typically offers 500 mA total, and the board itself idles at roughly 45 mA. Call it 450 mA for everything you add.
- Barrel jack (7–12 V). Feeds the on-board linear regulator. Linear means the excess voltage becomes heat, not saved energy: at 12 V in and 300 mA out, the regulator burns (12 − 5) × 0.3 ≈ 2.1 W as heat. It will get too hot to touch and then thermally shut down. 9 V is the sweet spot.
- VIN pin. Electrically the same as the jack, minus the reverse-polarity diode. Convenient and unforgiving — one swapped wire kills the board.
Do not feed regulated 5 V into the 5 V pin while USB is also connected, and do not feed 5 V into VIN. The 5 V pin is an output of the regulator; back-driving it fights the regulator and bypasses every protection on the board. And 5 V into VIN leaves the regulator with no headroom, so the chip browns out at around 4.2 V and behaves erratically rather than failing cleanly.
The four current limits, in order of how often they are broken
- 20 mA per pin (40 mA absolute). One LED per pin is fine. A motor, a relay coil or a strip of LEDs is not.
- 200 mA total across all I/O pins together, limited by the chip’s own VCC/GND legs.
- 50 mA from the 3.3 V pin. This rail comes from a small LDO in the USB section, not the main regulator. An ESP-01 module peaking at 300 mA will crash the board instantly.
- ~450 mA usable on the 5 V rail from USB, or roughly 800 mA from the jack before the regulator’s heat becomes the limit.
Current budget
Pick your parts. The verdict checks typical draw, peak draw and whether anything is too hungry to hang off a pin.
An LED is a diode, not a resistor — connect one directly across 5 V and it draws whatever current it can until something gives. Size the resistor from Ohm’s law: R = (5 V − Vf) / I. A red LED drops about 2.0 V and wants 15 mA, so (5 − 2.0) / 0.015 = 200 Ω — use the standard 220 Ω. A blue or white LED drops around 3.2 V, so (5 − 3.2) / 0.015 = 120 Ω. When in doubt, 330 Ω is dimmer and always safe.
Three pin modes, and the one that saves you a resistor
Every digital pin has exactly three useful configurations, set with pinMode():
The pin pushes
It actively drives either 5 V (HIGH) or 0 V (LOW), sourcing or sinking up to 20 mA. Use it for LEDs, transistor gates and signal lines.
The pin listens, weakly
High impedance — it reads voltage without affecting it. With nothing connected it floats, picking up mains hum and reading randomly. This is the classic phantom-button bug.
The pin listens, and holds itself up
Enables an internal ~20–50 kΩ resistor to 5 V, so the pin idles HIGH. Wire your button from the pin to GND and pressing it reads LOW. No external resistor, no floating.
Pressed means LOW
This trips everyone once. With INPUT_PULLUP the reading is inverted: if (digitalRead(2) == LOW) means pressed. Write it as if (!digitalRead(2)) and move on.
LOW.// Button from pin 2 to GND. No external resistor needed.
// Debounced with millis() so one press is never counted twice.
const uint8_t BUTTON = 2;
const uint8_t LED = 13;
const uint16_t DEBOUNCE_MS = 40; // contacts settle in ~20-30 ms
bool lastStable = HIGH; // pull-up means idle is HIGH
bool lastReading = HIGH;
uint32_t lastChange = 0;
bool ledOn = false;
void setup() {
pinMode(BUTTON, INPUT_PULLUP); // internal resistor to 5 V
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
bool reading = digitalRead(BUTTON);
// Any change restarts the settling clock
if (reading != lastReading) {
lastReading = reading;
lastChange = millis();
}
// Accept the level only once it has held still long enough
if (millis() - lastChange >= DEBOUNCE_MS && reading != lastStable) {
lastStable = reading;
if (lastStable == LOW) { // LOW == pressed
ledOn = !ledOn;
digitalWrite(LED, ledOn);
Serial.println(F("press"));
}
}
}
millis() - lastChange and never millis() > lastChange + 40
millis() returns an unsigned long that wraps to zero after 49.7 days. Subtraction of unsigned values wraps correctly and keeps working across that rollover; addition on the right-hand side does not. Write the subtraction form every time and the bug never exists.
The Uno cannot output 2.5 V — so it fakes it very fast
There is no DAC on an ATmega328P. analogWrite() switches the pin fully on and fully off hundreds of times a second and lets the average do the work.
PWM lab
Drag the duty cycle. Watch the waveform, the average voltage, and why a linear fade looks wrong to your eye.
Left: brightness set linearly.
Right: gamma-corrected.
Same value — the right one is what your eye expects.
The gamma problem is the most useful thing in that panel. Human brightness perception is roughly logarithmic, so analogWrite(128) — mathematically half power — looks about 73% as bright, not 50%. A linear fade therefore appears to rush through the dim end and crawl through the bright end. Correct it with a power curve:
// A fade that actually looks linear. Pin 9 = Timer1 PWM.
const uint8_t LED_PIN = 9;
const float GAMMA = 2.2; // matches eye response closely enough
void setup() { pinMode(LED_PIN, OUTPUT); }
void loop() {
for (int step = 0; step <= 255; step++) {
// Map perceived brightness 0..1 onto real duty 0..255
float perceived = step / 255.0;
uint8_t duty = (uint8_t)(pow(perceived, GAMMA) * 255.0 + 0.5);
analogWrite(LED_PIN, duty);
delay(8);
}
for (int step = 255; step >= 0; step--) {
float perceived = step / 255.0;
analogWrite(LED_PIN, (uint8_t)(pow(perceived, GAMMA) * 255.0 + 0.5));
delay(8);
}
}
// Short on flash? Replace pow() with a 32-entry lookup table in PROGMEM.
// pow() and float maths together cost roughly 2 KB of flash on AVR.
Servo.h takes over Timer1 to generate its 50 Hz pulses. The moment you call servo.attach(), analogWrite() on pins 9 and 10 stops working — silently. Move your PWM output to pin 3, 5, 6 or 11 and the conflict disappears.
Ten bits, one converter, six pins taking turns
There is exactly one analog-to-digital converter inside the ATmega328P. A multiplexer switches it between A0–A5, which is why you cannot sample two pins at the same instant — analogRead() selects a channel, waits for it to settle, converts for about 100 µs, and returns.
The result is a number from 0 to 1023, mapping 0 V to the reference voltage. With the default 5 V reference each step is 5 / 1023 = 4.888 mV.
ADC converter
Slide a voltage in and read what analogRead() gives back — in decimal, binary and mapped units.
1023 or 1024? The argument that will not die
To convert a reading back to volts, divide by 1023: the ADC output is a ratio where 1023 represents full scale, so volts = raw * 5.0 / 1023.0 puts 1023 at exactly 5 V. The people arguing for 1024 are describing the converter’s internal quantisation step, which is Vref/1024. Both are right about different things; for reading a sensor, use 1023. The difference is 0.1%, far smaller than your supply’s own error.
On USB power the rail is typically 4.6–4.9 V, and it sags when the board works harder. Since the default reference is that rail, every analog reading drifts with it. For measurements that have to be accurate, either measure the actual rail with the 1.1 V internal bandgap trick, or feed a precision reference into AREF and call analogReference(EXTERNAL) — before the first analogRead(), or you short the internal reference to your external one.
// Potentiometer on A0. Oversampled and smoothed, because one raw
// analogRead() on a breadboard jitters by several counts.
const uint8_t POT = A0;
const uint8_t SAMPLES = 16; // 16 reads ~ 1.6 ms, kills most noise
float smoothed = 0;
const float ALPHA = 0.2; // 0 = frozen, 1 = no smoothing
void setup() {
Serial.begin(9600);
analogRead(POT); // throw the first one away: the mux
} // needs a moment after switching
void loop() {
uint32_t total = 0;
for (uint8_t i = 0; i < SAMPLES; i++) total += analogRead(POT);
float raw = total / (float)SAMPLES;
// Exponential moving average — one float, no history array
smoothed = ALPHA * raw + (1.0 - ALPHA) * smoothed;
float volts = smoothed * 5.0 / 1023.0;
int percent = map((int)smoothed, 0, 1023, 0, 100);
Serial.print(F("raw ")); Serial.print(smoothed, 1);
Serial.print(F(" V ")); Serial.print(volts, 3);
Serial.print(F(" % ")); Serial.println(percent);
delay(50);
}
delay() is the first thing you learn and the first thing to unlearn
During delay(1000) the processor does nothing at all. It cannot read a button, feed a sensor or answer a serial command. Try it below.
Blocking vs non-blocking
Both LEDs blink at the same rate. Hammer both buttons — only one board is listening.
delay() — blocking
Pressed 0 · registered 0 · — response rate
loop() {
digitalWrite(LED, HIGH);
delay(250); // deaf
digitalWrite(LED, LOW);
delay(250); // deaf
checkButton(); // 1 chance
}
millis() — non-blocking
Pressed 0 · registered 0 · — response rate
loop() {
if (millis() - t >= 250) {
t = millis();
toggleLed();
}
checkButton(); // every pass
}
delay(). The green listening slivers are widened here to stay visible — in a real sketch they are microseconds wide, so a real board misses even more than this one does.
The pattern that replaces delay() everywhere is the same four lines, and once it is muscle memory you can run six independent timed tasks on one 16 MHz chip without a scheduler:
// Three jobs at three different rates, zero delay() calls.
// Each task owns one timestamp variable. That is the whole technique.
const uint8_t LED = 13, BUZZER = 8, POT = A0;
uint32_t tLed = 0, tSensor = 0, tReport = 0;
const uint16_t LED_MS = 500, SENSOR_MS = 50, REPORT_MS = 1000;
bool ledOn = false;
int lastValue = 0;
void setup() {
pinMode(LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
Serial.begin(9600);
}
void loop() {
uint32_t now = millis(); // read the clock once per pass
// Task 1: blink, twice a second
if (now - tLed >= LED_MS) {
tLed = now;
ledOn = !ledOn;
digitalWrite(LED, ledOn);
}
// Task 2: sample the pot, 20 times a second
if (now - tSensor >= SENSOR_MS) {
tSensor = now;
lastValue = analogRead(POT);
if (lastValue > 900) tone(BUZZER, 2000, 30); // alarm, non-blocking
}
// Task 3: report, once a second
if (now - tReport >= REPORT_MS) {
tReport = now;
Serial.print(F("pot=")); Serial.println(lastValue);
}
// The loop still runs ~100,000 times a second, so a button added
// here would respond in microseconds.
}
When delay() is still fine
Dogma helps nobody. Use delay() freely for short waits a datasheet demands — delay(2) after powering a sensor, a delayMicroseconds(10) trigger pulse — and in sketches that genuinely have one job. The rule is about long delays in loops that need to stay responsive.
| Function | Returns / range | Rolls over | Notes |
|---|---|---|---|
millis() | unsigned long ms | 49.7 days | Driven by Timer0; stops during interrupts |
micros() | unsigned long µs | 71.6 minutes | Resolution is 4 µs, not 1 µs |
delay(ms) | — | — | Blocks; interrupts still fire |
delayMicroseconds(us) | — | — | Reliable to ~16383 µs; busy-waits |
Interrupts: for the events you cannot afford to miss
Only D2 (INT0) and D3 (INT1) support attachInterrupt(). An interrupt service routine runs the instant the pin changes, no matter what loop() is doing — which makes it perfect for rotary encoders, flow meters and tachometers, and dangerous everywhere else.
// Counting pulses from a flow meter or encoder on pin 2.
// Rules of an ISR: be fast, touch only volatile variables,
// never call delay(), Serial.print(), millis()-dependent waits,
// and never allocate memory.
const uint8_t SENSOR = 2;
volatile uint32_t pulses = 0; // volatile: changed outside loop()
void onPulse() { pulses++; } // one instruction is ideal
void setup() {
pinMode(SENSOR, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SENSOR), onPulse, FALLING);
Serial.begin(9600);
}
void loop() {
static uint32_t t = 0;
if (millis() - t >= 1000) {
t = millis();
// Copy the shared counter with interrupts off, or a pulse
// arriving mid-read gives you a torn 32-bit value.
noInterrupts();
uint32_t count = pulses;
pulses = 0;
interrupts();
Serial.print(count); Serial.println(F(" pulses/s"));
}
}
First, Serial.print() inside an ISR will eventually hang the board — it waits on an interrupt that cannot fire while you are already inside one. Second, any variable shared between an ISR and loop() must be volatile, or the compiler will cache it in a register and your loop will read a stale value forever.
Serial, I²C and SPI — three buses, three sets of stolen pins
Every bus on the Uno is wired to specific pins, and using a bus means giving those pins up. Knowing which ones in advance saves a rebuild.
| Bus | Pins | Speed | Devices | Cost of using it |
|---|---|---|---|---|
| UART (Serial) | D0 RX, D1 TX | 300–115200 baud | 1 per bus | D0 and D1 are shared with USB — you lose the Serial Monitor |
| I²C (Wire) | A4 SDA, A5 SCL | 100 / 400 kHz | ~112 addressable | Two analog inputs; needs pull-ups (usually on the module) |
| SPI | D10 SS, D11 MOSI, D12 MISO, D13 SCK | Up to 8 MHz | Many, one CS pin each | Four digital pins, including the LED pin and a PWM pin |
| SoftwareSerial | Any two digital | ≤ 57600 reliable | 1 at a time | Blocks during transfer; cannot send and receive at once |
I²C is the one to prefer. Two wires carry an OLED display, a temperature sensor, a real-time clock and an accelerometer all at once, each answering to its own address. The duplicate SDA/SCL pins printed above D13 on an R3 board are the same two pins as A4 and A5 — not extras.
// The first sketch to run on any I2C problem. Lists every device
// that answers on the bus, so you stop guessing addresses.
// Wiring: module SDA -> A4, SCL -> A5, VCC -> 5V, GND -> GND
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial) { ; } // harmless on Uno, needed on some boards
Serial.println(F("Scanning I2C bus..."));
uint8_t found = 0;
for (uint8_t addr = 1; addr < 127; addr++) {
Wire.beginTransmission(addr);
if (Wire.endTransmission() == 0) { // 0 means the device ACKed
Serial.print(F(" found 0x"));
if (addr < 16) Serial.print('0');
Serial.println(addr, HEX);
found++;
}
}
if (!found) Serial.println(F(" nothing. Check SDA/SCL and power."));
else { Serial.print(found); Serial.println(F(" device(s)")); }
}
void loop() { }
// Common addresses: 0x3C SSD1306 OLED, 0x27 or 0x3F LCD backpack,
// 0x68 DS3231/MPU6050, 0x76 or 0x77 BMP280/BME280, 0x48 ADS1115
Nine times out of ten, the baud rate in the Monitor’s dropdown does not match the number in Serial.begin(). The remaining time it is a clone board whose resonator is off-frequency at 115200 — drop to 9600 and the garbage disappears.
What actually happens when you press Upload
Step through Blink one line at a time. Every Arduino program has this skeleton, and the two functions are not optional.
Sketch stepper
Line by line, with what the chip is doing at that moment.
Behind the Upload button, four things happen in sequence. The IDE compiles your sketch with avr-gcc into a .hex file. It then toggles the serial port’s DTR line, which — through a 100 nF capacitor on the board — yanks the ATmega328P’s RESET pin low. The bootloader in the top 512 bytes of flash wakes up, listens for about a second, and avrdude streams the new program in. Then the bootloader jumps to your code and gets out of the way.
Opening the Serial Monitor also toggles DTR, which resets your board and restarts your sketch from scratch. If you have ever wondered why your counter went back to zero the moment you opened the Monitor, that is why. It is a feature — it lets upload work without you pressing Reset by hand.
Six projects, in the order that teaches the most
Each one introduces exactly one new idea and reuses everything before it. Every sketch here is complete — copy, upload, run.
Project 1 — Blink, done the grown-up way
New idea: non-blocking timing from the very first sketch, so you never have to unlearn it.
Parts: nothing. Pin 13 has an LED already soldered on.
const uint8_t LED = LED_BUILTIN; // == 13 on an Uno
const uint16_t INTERVAL = 500; // ms between changes
uint32_t lastToggle = 0;
bool state = LOW;
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
if (millis() - lastToggle >= INTERVAL) {
lastToggle = millis();
state = !state;
digitalWrite(LED, state);
}
}
Make it yours: add a second LED on pin 9 that blinks every 330 ms. Two timestamps, two if blocks, and they drift in and out of sync — proof the loop is handling both.
Project 2 — Pedestrian crossing with a request button
New idea: a state machine. Three LEDs, one button, and no delay() anywhere — the button stays live through the whole sequence.
Parts: red / amber / green LEDs with 220 Ω resistors on pins 11, 12, 13; push button from pin 2 to GND.
// A state machine: the sketch is always in exactly one named state,
// and each state knows what comes next and when.
const uint8_t RED = 11, AMBER = 12, GREEN = 13, BUTTON = 2;
enum Phase { GO, REQUESTED, WARN, STOP, CLEARING };
Phase phase = GO;
uint32_t tPhase = 0;
void setPhase(Phase p) { phase = p; tPhase = millis(); }
void lights(bool r, bool a, bool g) {
digitalWrite(RED, r); digitalWrite(AMBER, a); digitalWrite(GREEN, g);
}
void setup() {
pinMode(RED, OUTPUT); pinMode(AMBER, OUTPUT); pinMode(GREEN, OUTPUT);
pinMode(BUTTON, INPUT_PULLUP);
setPhase(GO);
}
void loop() {
uint32_t held = millis() - tPhase;
bool pressed = (digitalRead(BUTTON) == LOW); // checked every pass
switch (phase) {
case GO:
lights(false, false, true);
// Traffic gets a guaranteed 3 s of green before we interrupt
if (pressed && held > 3000) setPhase(REQUESTED);
break;
case REQUESTED: // brief acknowledgement
lights(false, false, true);
if (held > 500) setPhase(WARN);
break;
case WARN:
lights(false, true, false);
if (held > 2000) setPhase(STOP);
break;
case STOP: // pedestrians cross
lights(true, false, false);
if (held > 6000) setPhase(CLEARING);
break;
case CLEARING: // red + amber together
lights(true, true, false);
if (held > 1500) setPhase(GO);
break;
}
}
Make it yours: flash the amber during CLEARING at 4 Hz. You will need a second timestamp inside that state — the moment you add it, the technique clicks.
Project 3 — Potentiometer dimmer with a dead zone
New idea: analog in driving PWM out, plus the two fixes every real analog input needs — hysteresis and end-stop snapping.
Parts: 10 kΩ potentiometer (outer legs to 5 V and GND, wiper to A0); LED with 220 Ω on pin 9.
const uint8_t POT = A0, LED = 9;
const uint8_t DEADBAND = 4; // ignore wobble smaller than this
int shown = -1; // last value we acted on
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
int raw = analogRead(POT); // 0..1023
// A pot never quite reaches its ends. Snap the last 1% so the
// LED actually goes fully off and fully on.
if (raw < 10) raw = 0;
if (raw > 1013) raw = 1023;
int level = raw >> 2; // 1023 -> 255, cheaper than map()
// Only react to real movement, or the LED flickers at rest
if (shown < 0 || abs(level - shown) >= DEADBAND || level == 0 || level == 255) {
shown = level;
analogWrite(LED, level);
Serial.print(F("level ")); Serial.println(level);
}
}
Make it yours: apply the gamma curve from the PWM lab and compare. The knob will suddenly feel like a real dimmer rather than a switch with a vague middle.
Project 4 — Ultrasonic reversing sensor
New idea: timing an external signal with pulseIn(), and a beep whose rate encodes distance — all without blocking.
Parts: HC-SR04 (VCC→5V, GND→GND, Trig→D7, Echo→D6); passive buzzer on D8. Our HC-SR04 guide covers the sensor itself in depth.
// Sound travels ~343 m/s, so 1 cm out-and-back takes ~58 us.
// The HC-SR04 gives an echo pulse whose width is that round trip.
const uint8_t TRIG = 7, ECHO = 6, BUZZER = 8;
const uint16_t MAX_CM = 200;
const uint32_t TIMEOUT_US = 25000UL; // ~430 cm, past our range
uint32_t tPing = 0, tBeep = 0;
uint16_t distance = MAX_CM;
uint16_t readDistanceCm() {
digitalWrite(TRIG, LOW); delayMicroseconds(2);
digitalWrite(TRIG, HIGH); delayMicroseconds(10); // datasheet trigger
digitalWrite(TRIG, LOW);
uint32_t us = pulseIn(ECHO, HIGH, TIMEOUT_US);
if (us == 0) return MAX_CM; // nothing came back
uint16_t cm = us / 58;
return (cm == 0 || cm > MAX_CM) ? MAX_CM : cm;
}
void setup() {
pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT); pinMode(BUZZER, OUTPUT);
Serial.begin(9600);
}
void loop() {
uint32_t now = millis();
// Ping 10x/second. Faster than that and echoes from the previous
// ping are still bouncing around the room.
if (now - tPing >= 100) {
tPing = now;
distance = readDistanceCm();
Serial.print(distance); Serial.println(F(" cm"));
}
// Closer object -> shorter gap between beeps. Under 15 cm, solid tone.
uint16_t gap = (distance >= MAX_CM) ? 0
: (distance < 15) ? 1
: map(distance, 15, MAX_CM, 60, 900);
if (gap == 0) { noTone(BUZZER); }
else if (gap == 1) { tone(BUZZER, 2200); } // continuous
else if (now - tBeep >= gap) { tBeep = now; tone(BUZZER, 1800, 35); }
}
Make it yours: add three LEDs for green / amber / red zones. pulseIn() is the only blocking call left — and at 25 ms worst case it is worth knowing it is there.
Project 5 — Serial command console
New idea: parsing text commands from the Serial Monitor into a fixed char buffer — no String, no heap, no fragmentation.
Parts: LED on pin 9, and the USB cable you already have. Type on, off, set 128 or status into the Monitor.
const uint8_t LED = 9;
const uint8_t BUF = 24;
char line[BUF];
uint8_t len = 0;
uint8_t level = 0;
void handle(char* cmd) {
if (strcmp(cmd, "on") == 0) { level = 255; }
else if (strcmp(cmd, "off") == 0) { level = 0; }
else if (strncmp(cmd, "set ", 4) == 0) {
int v = atoi(cmd + 4);
level = constrain(v, 0, 255); // never trust input
}
else if (strcmp(cmd, "status") == 0) {
Serial.print(F("level=")); Serial.print(level);
Serial.print(F(" uptime=")); Serial.print(millis() / 1000);
Serial.println(F("s"));
return;
}
else {
Serial.print(F("? ")); Serial.println(cmd);
Serial.println(F("try: on | off | set 0-255 | status"));
return;
}
analogWrite(LED, level);
Serial.print(F("ok level=")); Serial.println(level);
}
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
Serial.println(F("ready. commands: on, off, set N, status"));
}
void loop() {
while (Serial.available()) {
char c = Serial.read();
if (c == '\n' || c == '\r') {
if (len) { line[len] = '\0'; handle(line); len = 0; }
}
else if (len < BUF - 1) {
line[len++] = c; // overflow simply ignored
}
}
// loop() stays free for everything else
}
Make it yours: add a save command that writes level to EEPROM, and read it back in setup(). Your brightness now survives a power cut.
Project 6 — Min/max logger that survives power loss
New idea: EEPROM done responsibly — EEPROM.update() instead of write(), and writes rate-limited so you never burn through the 100,000-cycle endurance.
Parts: any analog sensor or a potentiometer on A0. Optional SSD1306 OLED on A4/A5.
#include <EEPROM.h>
const uint8_t SENSOR = A0;
const int ADDR_MAGIC = 0, ADDR_MIN = 2, ADDR_MAX = 4;
const uint8_t MAGIC = 0x5A; // marks EEPROM as "ours"
const uint32_t SAVE_EVERY_MS = 60000UL; // at most once a minute
int vMin = 1023, vMax = 0;
uint32_t tSave = 0, tRead = 0;
bool dirty = false;
void loadOrInit() {
// A fresh ATmega reads 0xFF everywhere. Without a magic byte you
// would load 65535 as your minimum and never recover.
if (EEPROM.read(ADDR_MAGIC) != MAGIC) {
EEPROM.update(ADDR_MAGIC, MAGIC);
EEPROM.put(ADDR_MIN, vMin);
EEPROM.put(ADDR_MAX, vMax);
Serial.println(F("EEPROM initialised"));
return;
}
EEPROM.get(ADDR_MIN, vMin);
EEPROM.get(ADDR_MAX, vMax);
Serial.print(F("restored min=")); Serial.print(vMin);
Serial.print(F(" max=")); Serial.println(vMax);
}
void setup() {
Serial.begin(9600);
loadOrInit();
}
void loop() {
uint32_t now = millis();
if (now - tRead >= 200) {
tRead = now;
int v = analogRead(SENSOR);
if (v < vMin) { vMin = v; dirty = true; }
if (v > vMax) { vMax = v; dirty = true; }
Serial.print(v);
Serial.print(F(" min ")); Serial.print(vMin);
Serial.print(F(" max ")); Serial.println(vMax);
}
// Only touch EEPROM when something changed, and never more than
// once a minute. update() skips the write if the byte already matches.
if (dirty && now - tSave >= SAVE_EVERY_MS) {
tSave = now; dirty = false;
EEPROM.put(ADDR_MIN, vMin);
EEPROM.put(ADDR_MAX, vMax);
Serial.println(F("saved"));
}
}
// Endurance maths: one save per minute = 1,440/day. At 100,000 cycles
// that cell lasts ~69 days of continuous running. Rate-limit harder,
// or rotate across several addresses, for anything long-lived.
Make it yours: this is the natural capstone shape — sense, decide, store, report. Swap A0 for a real sensor, add the OLED, and you have a finished instrument.
Twelve things that will waste your evening
None of these are in the datasheet. All of them have cost somebody a weekend.
Your clone needs a different driver
Official boards use the ATmega16U2. Cheap clones use a CH340 or CP2102. No port appears in the IDE until you install that chip’s driver — it is not a broken board.
Pin 13 lies to you as an input
The on-board LED and its resistor hang off pin 13 permanently, pulling it toward ground. Used as INPUT it reads unreliably, and INPUT_PULLUP fights the resistor. Never put a button on pin 13.
A6 and A7 do not exist here
They are on the Nano, not the Uno. The DIP-28 package has no legs for them. Code using A6 compiles and returns noise.
Servos must not be powered from the 5 V pin
A small SG90 pulls 100–250 mA while turning and over 500 mA stalled. On USB power it browns the board out mid-sweep, which looks exactly like a code bug. Separate 5 V supply, grounds tied together.
Opening the Serial Monitor restarts your sketch
DTR toggling resets the board. Counters zero, setup() reruns. Expected behaviour, endlessly confusing.
String will crash your sketch eventually
Repeated concatenation fragments 2 KB of heap until an allocation fails. The symptom is a board that works for twenty minutes then freezes. Use char arrays and snprintf.
Floating inputs read whatever they like
An INPUT pin with nothing attached is an antenna picking up mains hum. It will report phantom presses. Always INPUT_PULLUP or an external resistor.
The Servo library kills PWM on 9 and 10
It commandeers Timer1. analogWrite() on those pins stops working the moment you attach a servo, with no warning.
The 3.3 V pin gives you 50 mA, total
It comes from a tiny LDO, not the main regulator. An ESP-01 or a hungry radio module will crash the board the instant it transmits.
int is 16 bits, so it overflows at 32,767
int x = 200 * 200; gives you −25,536. Multiplying millis values, counting beyond 32k, or summing ADC readings all need long or uint32_t.
Grounds must be common
Two power supplies with unjoined grounds means your signals have no shared reference. Sensors read nonsense and nothing in the code will fix it. Tie every GND together.
12 V into the jack makes the regulator a heater
Linear regulation burns the difference. At 12 V and 400 mA that is 2.8 W in a part the size of a grain of rice. Use 7.5–9 V and it runs cool.
Something is wrong. Let’s narrow it down.
Answer the questions. Every path ends in a specific fix, not “check your wiring”.
Fix-it tree
Twenty-two endings covering the failures that account for most support requests.
Ten questions that separate copying from understanding
Each answer comes with the reasoning. Getting one wrong is more useful than getting it right.
Arduino Uno fundamentals
No sign-in, no score kept. Just you and the silicon.
The words, in plain language
Sketch
.ino text file containing C++ that gets compiled and flashed onto the chip.Bootloader
Sourcing and sinking current
HIGH pushing current out to a load that returns to GND. Sinking is a pin set LOW accepting current from a load connected to 5 V. The ATmega328P handles both at 20 mA per pin.Pull-up and pull-down resistor
HIGH; a pull-down (to GND) makes it LOW. The Uno has pull-ups built in — use INPUT_PULLUP.Duty cycle
HIGH, expressed as a percentage. analogWrite(0) is 0%, analogWrite(255) is 100%, analogWrite(128) is roughly 50%.Volatile
Shield
ICSP
Brownout
Questions people actually ask
Is the Arduino Uno still worth learning in 2026?
What is the difference between Arduino Uno R3 and R4?
How many LEDs can an Arduino Uno drive?
Can the Arduino Uno run two programs at once?
loop(), no operating system. What you can do is make that loop handle several jobs by never blocking it — the timestamp pattern in the timing section runs as many independent timed tasks as you like on one core.Why does my Arduino Uno say “port not found” or “access denied”?
dialout group. The fix-it tree walks through each.How much current can an Arduino Uno pin supply?
Can I power an Arduino Uno from a 9 V battery?
Why does my sketch work on USB but not on battery?
What is the maximum sketch size on an Uno?
pow(), sprintf with %f, and large libraries each cost 1–2 KB. SRAM runs out first, nearly every time.Do I need to learn C++ before using an Arduino?
Reading about it only gets you so far
Our free self-paced Arduino Uno Fundamentals course takes you from this page to a working project of your own, with module quizzes and a certificate once your capstone is approved. If you would rather have someone looking over your shoulder, the 20-day live programme runs with daily assignments and review.
Written and maintained by eARgle Innovation Labs — IoT and embedded systems education.
Technical figures follow the ATmega328P datasheet and the official Arduino Uno R3 and R4 specifications. Last reviewed October 2026.
Found an error? Tell us and we will fix it, with credit.