Sub topic 14
Wiring Habits That Protect the Arduino Uno
Assume you know basic voltage, current, and resistance, and that you can use setup() and loop() in the Arduino IDE. The Uno is forgiving, but incorrect wiring can permanently damage its pins or voltage regulators. Safe wiring starts by treating every pin as an electrical component with limits.
Use a resistor with an LED
An LED is a diode that emits light. It does not safely limit its own current. Connect a resistor in series with the LED to limit current.
A typical connection is:
- Uno digital pin 9 → 220 Ω or 330 Ω resistor → LED anode, the longer leg
- LED cathode, the shorter leg → GND
- Set pin 9 as an output
Without the resistor, the LED and the Uno pin may draw excessive current. The LED can fail, and the pin can be damaged.
const int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}Give inputs a defined state
An input pin must not be left electrically unconnected. An unconnected input is called a floating input. It can randomly read HIGH or LOW because it picks up electrical noise.
For a push button, use the Uno's internal pull-up resistor. Wire one side of the button to pin 2 and the other side to GND. The input reads HIGH when released and LOW when pressed.
const int buttonPin = 2;
const int ledPin = LED_BUILTIN;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop() {
bool pressed = digitalRead(buttonPin) == LOW;
digitalWrite(ledPin, pressed ? HIGH : LOW);
}The logic is inverted because pressing the button connects the pin to ground.
Respect electrical limits
A pin set HIGH outputs approximately 5 V on a standard Uno. A pin set LOW is close to 0 V. Do not connect an output directly to 5 V or GND if the output might drive the opposite level. That creates a short circuit.
Use these habits:
- Keep ordinary LED and signal loads near 20 mA or less per pin. The ATmega328P datasheet gives absolute maximum ratings, not a target operating condition.
- Do not power motors, relays, servos, or strips of LEDs directly from an I/O pin. Use a transistor or a suitable driver circuit.
- Connect the grounds of the Uno and an external supply when their signals must interact.
- Check polarity before applying power.
- Turn off power while changing jumper wires.
- Never connect two output pins together.
| Situation | Safer practice |
|---|---|
| Driving an LED | Use a series resistor |
| Reading a button | Use `INPUT_PULLUP` or an external pull resistor |
| Driving a motor | Use a transistor, driver, and separate supply |
| Using an external module | Confirm its voltage and share GND when required |
Exercise
Exercise
Why does a button connected between pin 2 and GND use INPUT_PULLUP, and why does the code treat LOW as pressed?
Show answer
INPUT_PULLUP gives the input a defined HIGH state when the button is open. Pressing the button connects the pin to GND, so it reads LOW.