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.
Basic 5 min
Wire seven LEDs, each with a 220 Ω resistor. Put six on the UNO's PWM pins: 3, 5, 6, 9, 10 and 11. Put the seventh on pin 4.
Write a sketch that gives each LED a different brightness with analogWrite: 20, 60, 100, 140, 180, 220. Give the LED on pin 4 a value of 128.
It works if the six PWM LEDs show six clear steps of brightness. Write down what the pin 4 LED does, then try it at 100.
Challenge 1 5 min
This UNO project logs to an SD card over SPI. Two buttons use interrupts. A status LED should stay calm. It has three pin faults.
const int SD_CS_PIN = 10;
const int BUTTON_A_PIN = 2;
const int BUTTON_B_PIN = 12;
const int STATUS_LED_PIN = 13;
volatile bool aPressed = false;
volatile bool bPressed = false;
void onA() {
aPressed = true;
}
void onB() {
bPressed = true;
}
void setup() {
pinMode(BUTTON_A_PIN, INPUT_PULLUP);
pinMode(BUTTON_B_PIN, INPUT_PULLUP);
pinMode(STATUS_LED_PIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(BUTTON_A_PIN), onA, FALLING);
attachInterrupt(digitalPinToInterrupt(BUTTON_B_PIN), onB, FALLING);
}
void loop() {
}Find each fault, say which pin talent it breaks, and move the pin.
It works if the sketch compiles and both buttons sit on interrupt pins. Only SPI may use 11, 12 and 13.
Challenge 2 5 min
Build this: a servo on D9 and an LED with a 220 Ω resistor on D10. Upload the sketch.
#include <Servo.h>
const int SERVO_PIN = 9;
const int LED_PIN = 10;
Servo arm;
void setup() {
arm.attach(SERVO_PIN);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
for (int level = 0; level <= 255; level++) {
analogWrite(LED_PIN, level);
arm.write(map(level, 0, 255, 0, 180));
delay(10);
}
}- Describe what the LED really does.
- Explain the cause in one sentence, using the word "timer".
- Move the LED to fix it, and change one line of code to match.
It works if the servo sweeps and the LED fades smoothly at the same time.
Challenge 3 · Pin-allocate a tricky brief 10 min
A UNO must run all of these at once:
- An SD card on SPI.
- An I²C OLED.
- One servo.
- Two buttons that use interrupts.
- Three LEDs that must dim with
analogWrite. - An HC-SR04 and a buzzer.
- Follow the four-step strategy. Write the
const intpin block. - One part cannot be given the pin talent it needs. Find it.
- Give two different fixes for that part.
It works if your pin block compiles with no pin used twice. You must also name the part that does not fit.
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.
Extra Mission 5 min
Part 1 — Design a gadget with a busy pin map
Design a gadget with at least six parts — a desk pet robot, a game buzzer box, a room alarm. On paper, give it a full UNO pin map.
Your design must include:
- The gadget's one job, in one sentence.
- A pin table with every part and the talent each pin needs (PWM, interrupt, analog, bus).
- The spare pins left for later.
- One clash you avoided, and how.
Part 2 — Make it
Wire at least four of the parts exactly as your map says. Write a test sketch that uses your const int block and checks each part in turn. Print "OK" to the Serial Monitor after each one.
Bring back next class: your pin map, the uploaded sketch, and a photo of the circuit. For ARD-L04-05, bring two UNOs if you can.