Sub topic 14
Wiring habits that protect the board
This chapter assumes you know Ohm's law (V = I × R), can read a breadboard circuit diagram, and know the digital pin and pinMode basics from earlier chapters. It covers the habits that keep an Uno R3 alive: limiting current, respecting voltage, and wiring in a safe order. Most dead boards come from a small set of mistakes, and each one is easy to avoid once you can see why it hurts.
Why wiring mistakes damage a board
The ATmega328P microcontroller drives each output pin with small transistors. They can only pass so much current before they overheat. The datasheet gives these limits for the chip on the Uno:
| Limit | Value | Meaning |
|---|---|---|
| Recommended current per I/O pin | 20 mA | Design target for continuous use |
| Absolute maximum per I/O pin | 40 mA | Damage is likely beyond this |
| Total across all I/O pins | 200 mA | Sum of everything the chip supplies or sinks |
| Voltage on any pin | -0.5 V to VCC + 0.5 V | Roughly 0 to 5 V on an Uno |
| 3.3V pin output | 50 mA | Supplied by the on-board regulator |
A pin never "chooses" how much current to deliver. The circuit connected to it decides, according to Ohm's law. If you give it a path with almost no resistance, it tries to pass far more than 40 mA, and the pin transistor fails. Every habit below comes down to one of two rules: put resistance in the path, or keep voltage inside the 0 to 5 V range.
Always limit current to LEDs
An LED has almost no resistance once it conducts. Without a series resistor, it draws whatever the pin can push until something burns out. The resistor value follows from the supply voltage, the LED's forward voltage (Vf), and the current you want:
R = (Vsupply − Vf) / I
For a red LED (Vf about 2 V) on a 5 V pin at about 10 mA, R = (5 − 2) / 0.010 = 300 Ω. The nearest common value, 330 Ω, gives about 9 mA.
| Resistor | Current (red LED, Vf ≈ 2 V) | Result |
|---|---|---|
| 220 Ω | about 14 mA | Bright, within limits |
| 330 Ω | about 9 mA | Good default |
| 1 kΩ | about 3 mA | Dim but visible |
| none | pin limit or higher | Likely damage to the LED or the pin |
The resistor can go on either side of the LED. The order in the series path does not change the current.
Avoid direct shorts
A short circuit is a path from a power rail to ground with nothing to limit the current. On a breadboard, shorts usually come from three places:
- A jumper wire connecting 5V directly to GND, or a loose component leg bridging two rails.
- An output pin set HIGH while wired directly to GND, or set LOW while wired directly to 5V.
- A button wired from an output pin to GND, where the code later drives that pin HIGH.
The third case is common. If you use INPUT_PULLUP as in the button example, the pin is an input and the pressed button simply pulls it LOW. If you instead configure the pin as OUTPUT and drive it HIGH, pressing the button creates a near-direct path from the pin to GND. Match the pin's mode to what the circuit expects.
Keep voltages in range
Inputs must stay between 0 V and about 5 V. Three situations push a signal outside that range:
- Higher-voltage sensors. A 12 V signal wired straight to a pin will destroy it. Use a voltage divider or a level-shifter module to bring the signal down.
- Mixing 3.3 V and 5 V devices. A 3.3 V sensor's output is safe for the Uno to read. The reverse is the problem: an Uno output at 5 V can damage a 3.3 V-only input, so put a divider or level shifter between them.
- Negative voltages. Audio signals or AC-coupled sources swing below 0 V. Bias them to a mid-level with resistors, and never connect them directly.
Analog readings follow the same rule. If a sensor can exceed 5 V, the ADC input is at risk, not just the reading.
Never power loads from a pin
An I/O pin is a signal source, not a power supply. A small LED fits within the limit. Motors, relays, buzzers with coils, servos, and LED strips do not. The correct pattern is to let the pin switch a transistor, and let the transistor carry the load current from a separate supply.
Inductive loads (motors, relays, solenoids) also need a flyback diode across the coil. When the transistor switches off, the coil produces a brief voltage spike in the opposite direction. The diode gives that spike a safe path. Without it, the spike can destroy the transistor or reach the board.
// Pin 8 switches an NPN transistor (for example 2N2222) through a 1 kOhm
// base resistor. The load runs from its own supply, not from the Uno pin.
// The load's supply ground must connect to an Uno GND pin.
const int loadPin = 8;
void setup() {
digitalWrite(loadPin, LOW); // set the output level before enabling output
pinMode(loadPin, OUTPUT); // so the pin never briefly pulses HIGH
}
void loop() {
digitalWrite(loadPin, HIGH); // transistor on, load runs
delay(2000);
digitalWrite(loadPin, LOW); // transistor off, load stops
delay(2000);
}Writing the level before calling pinMode matters on AVR boards. At power-up, pins are inputs. Writing HIGH to an input pin enables its internal pull-up, so the order above avoids a short pulse at the wrong level when the pin becomes an output.
The 1 kΩ base resistor limits the pin current to roughly (5 − 0.7) / 1000, or about 4 mA. That is well inside the 20 mA target.
Share a common ground
When a circuit uses two supplies, such as the USB-powered Uno and a separate battery pack for a motor, the grounds must be connected. Voltages are only meaningful relative to a reference. Without a shared GND, the transistor in the example cannot see the signal from pin 8 correctly, and the circuit behaves erratically or not at all. Connect the external supply's negative terminal to an Uno GND pin. Never connect the positive terminals together.
Respect the board's total budget
Each pin's limit is only part of the picture. The 200 mA chip total and the supply's limit also apply:
- When powered over USB, the board is limited by the USB port, typically 500 mA, and a resettable fuse on the board trips near that figure. The 5V pin shares this budget with the board's own consumption of roughly 50 mA.
- The 3.3V pin is limited to 50 mA.
- When powered through the barrel jack or VIN, the on-board 5V regulator turns excess voltage into heat. At 12 V input, drawing 300 mA on 5V wastes about 2 W in the regulator, which makes it too hot to touch. Use 7 to 9 V, or power heavy loads separately.
A practical habit is to add up the current of everything you connect. Eight LEDs at 10 mA each is 80 mA, which fits. Eight LEDs at 25 mA each is 200 mA and runs the chip at its limit.
Order of operations
Wire carefully and in the same order each time:
Other small habits help as well:
- Disconnect or power down before moving wires. Changing connections on a live board is how rails get bridged by accident.
- Touch a grounded metal object before handling the board in dry conditions. Static discharge can damage the chip.
- Keep the board on a non-conductive surface. Metal desks can short the pins on the underside.
- Use color conventions, such as red for 5V and black for GND, so a swapped wire is easy to spot.
- If the USB port disconnects or the board resets when a load turns on, the supply is overloaded or a short exists. Unplug and inspect before retrying.
Common errors and symptoms
| Symptom | Likely cause | Fix |
|---|---|---|
| Board resets when a motor starts | Motor drawing from the 5V rail causes a voltage dip | Power the motor from a separate supply with a shared GND |
| LED is very bright, then dies | No series resistor | Add 220 to 330 Ω |
| Pin reads random values | Floating input | Use `INPUT_PULLUP` or an external resistor |
| Upload fails with a circuit attached | Something connected to pin 0 or 1 | Disconnect it during upload |
| Regulator is too hot | High VIN with a large load on 5V | Lower VIN or split the load |
| One pin stops working | It exceeded 40 mA or took a voltage spike | Replace the chip or use a different pin |
Exercise
You want to light a blue LED (forward voltage about 3 V) from pin 6 at about 10 mA, and you also want a small 5 V relay coil that draws 70 mA to switch on from pin 7. For each, say what parts you need between the pin and the load, and why the relay cannot be wired directly to the pin.
Show answer
For the LED, R = (5 − 3) / 0.010 = 200 Ω, so use 220 Ω in series (about 9 mA). For the relay, 70 mA exceeds the 40 mA absolute maximum for a pin, so pin 7 must drive a transistor (for example an NPN with a roughly 1 kΩ base resistor, giving about 4 mA from the pin). The relay coil runs from the 5V supply or a separate supply through the transistor. A flyback diode goes across the coil to absorb the voltage spike when it switches off, and any separate supply must share ground with the Uno.