Learning Goals 5 min
Not every pin can do every thing. UNO has PWM on some pins, interrupts on others, true analog only on A0..A5. Knowing which pin does what before wiring saves hours of debugging. By the end of this lesson you will:
- Read an Arduino pin-out diagram (the official PDFs) and identify which pins support PWM, interrupts, analog input, and 5V tolerance.
- Plan a pin map that doesn't collide with hardware peripherals (SPI / I²C / UART).
- Spot the four most common "wrong pin" mistakes on the UNO and on the Nano 33 BLE.
Warm-Up 10 min
Pull up the UNO R3 pinout diagram (search "Arduino UNO R3 pinout"). You'll see colour-coded blocks: digital pins, analog pins, PWM (~), SPI (MISO/MOSI/SCK/SS), I²C (SDA/SCL), UART (RX/TX), interrupts (INT0/INT1).
Three questions
- Can you call
analogWrite(2, 128)on a UNO? - Which two UNO pins support hardware interrupts via
attachInterrupt()? - Can you use A4 / A5 as digital I/O?
Reveal
- No. Pin 2 is digital-only on UNO. PWM pins on UNO: 3, 5, 6, 9, 10, 11 (marked with ~). Calling
analogWrite(2, 128)on UNO sets the pin HIGH if > 127, LOW otherwise — not PWM. - Pins 2 and 3 (INT0 = pin 2, INT1 = pin 3). Mega has more (2, 3, 18, 19, 20, 21).
- Yes — A0..A5 double as D14..D19. But A4 and A5 are the I²C SDA/SCL pins; if you're using I²C, those pins are taken.
New Concept · The UNO pin map dissected 25 min
Six pin properties to track
| Property | What it means |
|---|---|
| Digital I/O | Can be read with digitalRead, written with digitalWrite. Almost all pins. |
| PWM (~) | Can be PWM'd with analogWrite. Specific pins only. |
| Analog input | Can be read with analogRead. A0–A5 on UNO; more on ESP32. |
| Interrupt-capable | Can trigger attachInterrupt. Few on UNO (2, 3); many on others. |
| Hardware peripheral | Reserved for SPI / I²C / UART when those features are in use. |
| Voltage / current | UNO output ≈ 20 mA per pin, ~200 mA total. 5V tolerant on input. |
UNO R3 — every pin's talents
| Pin | Functions |
|---|---|
| 0 (RX) | Digital + hardware UART RX. Disconnect during upload. |
| 1 (TX) | Digital + hardware UART TX. Disconnect during upload. |
| 2 | Digital, INT0 interrupt. |
| 3 | Digital, INT1 interrupt, PWM (~). |
| 4 | Digital. |
| 5 | Digital, PWM (~). Faster PWM (~980 Hz) than 9/10/11. |
| 6 | Digital, PWM (~). Faster PWM. |
| 7 | Digital. |
| 8 | Digital. |
| 9 | Digital, PWM (~). Taken by Servo library. |
| 10 | Digital, PWM (~), SPI SS (default). Taken by Servo, SPI. |
| 11 | Digital, PWM (~), SPI MOSI / COPI. |
| 12 | Digital, SPI MISO / CIPO. |
| 13 | Digital, SPI SCK, on-board LED. |
| A0–A3 | Analog in, also Digital (D14–D17). |
| A4 (SDA) | Analog in / Digital, I²C SDA when Wire is used. |
| A5 (SCL) | Analog in / Digital, I²C SCL when Wire is used. |
Pin assignment strategy
- Start with mandatory pins: I²C → A4/A5; SPI → 11/12/13; UART → 0/1.
- Allocate interrupts: 2 and 3 if you need them. Use 2 for the most important interrupt.
- Allocate PWM: pick from 3, 5, 6, 9, 10, 11. Avoid 9/10 if you'll use Servo (it takes those pins' timers and breaks their PWM).
- Everything else is plain digital: 4, 7, 8, 12, 13 (don't fight the on-board LED unless you want it as a status indicator).
Nano 33 BLE pin map — the differences
- Every pin supports PWM (any digital pin can
analogWrite). Different timer assignment. - Every pin supports interrupts (call
attachInterrupt(digitalPinToInterrupt(pin), ...)). - Analog pins A0..A7 — 8 channels, default 10-bit, supports 12-bit.
- 3.3 V GPIO. Not 5 V tolerant.
- I²C on A4/A5 (same physical position as UNO, different chip pins).
- SPI on D11/D12/D13 (same shield-compatible position).
Common UNO pin mistakes
- analogWrite on a non-PWM pin. Sets HIGH or LOW only. Symptom: LED is on or off, never dim.
- SPI device on pins 11–13 + LED on pin 13. The LED flickers with every SPI write. Either move the LED or accept the flicker.
- Servo on pin 9 + LED on pin 10 expecting PWM. Servo library takes Timer1, killing PWM on both pins 9 and 10. The LED's "fade" will be on/off only.
- I²C on A4/A5 + Servo (which steals analogRead timing). Rare in practice; mostly an issue with high-frequency analog reads alongside time-sensitive I²C.
Worked Example · Pin-allocate a real project 25 min
Brief — robot with extras
UNO + L298N (2 motors) + HC-05 Bluetooth + HC-SR04 ultrasonic + OLED (I²C) + 2 buttons + 1 status LED. Allocate pins.
Step 1 — list mandatory pins
- I²C (OLED) → A4, A5.
- HC-05 SoftwareSerial → pick any digital pair, say D2 + D3 (D2 also INT0 — use anyway, not using interrupts on Bluetooth).
- USB Serial debug → D0, D1 (don't connect anything else).
Step 2 — motor driver (needs PWM on enable pins)
- L298N ENA → PWM pin → D5 (980 Hz).
- L298N ENB → PWM pin → D6 (980 Hz).
- L298N IN1, IN2 → digital → D7, D8.
- L298N IN3, IN4 → digital → D9 (avoid Servo conflict — no Servo here) or wait, D9 is also PWM. Use D9 anyway; we don't need PWM on IN pins.
- Actually re-allocate: D9 → IN3, D10 → IN4.
Step 3 — sensors
- HC-SR04 TRIG → digital, no PWM needed → D11. Wait, D11 is also SPI MOSI — fine because we're not using SPI here.
- HC-SR04 ECHO → digital, interrupt-capable preferred for accurate timing — but
pulseIndoesn't require interrupts → D12.
Step 4 — UI
- Status LED → D13 (on-board; easy).
- Button A → can't use 2/3 (taken by HC-05). Use A0 as digital → D14.
- Button B → A1 as digital → D15.
Final pin map
| Function | Pin |
|---|---|
| USB Serial | D0, D1 |
| HC-05 RX, TX | D2, D3 |
| L298N IN1, IN2 | D7, D8 |
| L298N ENA (PWM) | D5 |
| L298N ENB (PWM) | D6 |
| L298N IN3, IN4 | D9, D10 |
| HC-SR04 TRIG, ECHO | D11, D12 |
| Status LED | D13 |
| Button A, Button B | A0, A1 (used as digital) |
| OLED SDA, SCL | A4, A5 |
| Spare | D4, A2, A3 |
3 spare pins for expansion. No conflicts. Two PWM channels used out of 6 available.
Step 5 — document the map
Tape the map next to the breadboard. Future-you (or a partner) will instantly know what each pin does. This is the single biggest debugging time-saver in a multi-component project.
Try It Yourself 15 min
You need 7 PWM channels on a UNO. Can it be done with one chip?
Reveal
UNO has 6 PWM pins (3, 5, 6, 9, 10, 11). One short. Options: add a PCA9685 16-channel PWM driver on I²C; switch to Mega (15 PWM pins); use software PWM on a 7th pin (jitter-prone but works).
You want to use SPI for an SD card AND attach interrupts to two buttons. UNO. What pins for the buttons?
Reveal
SPI takes 10/11/12/13. Interrupts are on 2 and 3. They don't collide — use 2 and 3 for the buttons. (D10 is SS/CS, free to be a CS pin for the SD card.)
Servo on D9. You add analogWrite(D10, 128) for an LED fade. It doesn't fade. Why?
Reveal
The Servo library uses Timer1 which controls PWM on pins 9 AND 10. Once Servo is initialised, analogWrite on D10 does nothing useful (becomes 0/1 only). Move the LED to D3, D5, D6, or D11.
You wrote the §4 robot pin map for UNO. Move to Nano 33 BLE. Which assignments change?
Reveal
Most stay (the "Nano shape" matches UNO for I²C / SPI / digital pins). The big one: Nano 33 BLE is 3.3 V GPIO, so the HC-05's 3.3 V outputs go straight in (no level shifter needed on RX), and the L298N's 5 V supply needs only the IN pins, which accept 3.3 V signals fine. No software changes if the original used analogReadResolution(10).
Mini-Challenge · Document your live pin maps 10 min
- For each of your in-progress L3 builds (chassis, plant monitor, doorbell, etc.), draw the actual pin map.
- Mark any conflicts or surprises.
- If migrating any of these to a Nano 33 BLE or ESP32, note the equivalent pins.
Print or tape these inside the enclosure with the build. The single biggest debugging time-saver.
Recap 5 min
Every pin has a personality. Plan I²C / SPI / UART / interrupt / PWM allocation before wiring. UNO's six pin properties (digital, PWM, analog, interrupt, peripheral, voltage) cover most assignments. Document the map alongside the build. Tomorrow we go even deeper into the chip — bootloaders and using one Arduino to flash another.
- Pinout diagram
- The official PDF showing each pin's functions. Found on the Arduino docs site for every board.
- PWM pin
- A pin that can output a hardware PWM signal via
analogWrite. Marked with ~ on the UNO. - Interrupt-capable pin
- A pin that can fire an interrupt service routine on edge change. UNO: only 2, 3. Most modern boards: every pin.
- Hardware peripheral pin
- A pin wired to a specific MCU peripheral (SPI, I²C, UART). Reserved when that peripheral is in use.
- 5V tolerant
- The input accepts 5 V without damage. UNO yes; most 3.3 V boards no.
- Pin map
- The list of which physical pin does which function in your project. Always document it.
- Timer conflict
- When a library steals a hardware timer used by another peripheral. Servo + Timer1 disabling PWM on pins 9/10 is the classic UNO example.
Homework 5 min
- Print the official UNO R3 pinout. Tape inside your notebook.
- Do the same for any other boards you own.
- Read ahead to ARD-L04-05 (Bootloaders and ISP). Bring two UNOs if possible.