Project Overview
Arduino (ATmega328P) GPIO sinking vs sourcing current: You will learn how an Arduino pin sources or sinks current when driving an LED or module input, and how to keep your MCU within safe current limits.
This guide explains sinking vs sourcing in plain English, shows the wiring differences with diagrams, lists the current limits that matter, and connects the concept to relay modules, transistors, and driver boards.
- Time: 15 to 25 minutes
- Skill level: Beginner
- What you will build: Two LED circuits (sourcing and sinking) and a simple understanding of when to use a relay or transistor instead of a GPIO pin
Parts List
From ShillehTek
- Arduino Nano V3.0 (or UNO) - the ATmega328P-based board used in the examples
- 830-Point Breadboard - for quickly building and comparing both wiring styles
- DuPont Jumper Wires (120-pc) - for breadboard connections
- 1-Channel 5V Relay Module - a classic example of an "active LOW" input and why GPIO needs help switching coils
- L298N Motor Driver Board - for higher-current loads where direct GPIO drive is not appropriate
External
- A couple of LEDs and 220 ohm resistors
- One pushbutton
- Optional: a 2N2222 or 2N3904 NPN transistor for the transistor demo
Note: The ATmega328P has a 40 mA absolute maximum per pin, but 20 mA is the commonly used safe continuous value. Also watch the total current across all pins combined.
Step-by-Step Guide
Step 1 - Learn the plain-English definition
Goal: Understand what it means for a GPIO pin to source current versus sink current.
What to do: Think of current like water flow in a pipe and the Arduino pin like a faucet you can push from or pull into.
-
Sourcing means the pin pushes current out. You wire the load (LED + resistor) between the pin and GND. Current flows out of the pin, through the LED, to ground.
digitalWrite(pin, HIGH)turns it on. -
Sinking means the pin pulls current in. You wire the load between +5 V and the pin. Current flows into the pin from the load.
digitalWrite(pin, LOW)turns it on.
Expected result: You can look at a wiring diagram and correctly say whether the pin is sourcing or sinking current.
Step 2 - Wire sourcing vs sinking, side by side
Goal: See the physical wiring difference and the logic difference (HIGH vs LOW) in a concrete LED example.
What to do: Build the two LED circuits on a breadboard: one where the pin sources current to the LED, and one where the pin sinks current from the LED.
Code:
// SOURCING: pin -> LED -> resistor -> GND
// digitalWrite(13, HIGH) -> LED ON
// digitalWrite(13, LOW) -> LED OFF
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
// SINKING: +5V -> resistor -> LED -> pin
// digitalWrite(13, LOW) -> LED ON
// digitalWrite(13, HIGH) -> LED OFF
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Expected result: You understand why the sinking version is inverted (LOW turns the LED on), which is the same pattern used by many "active LOW" relay modules.
Step 3 - Memorize the current limits that protect your Arduino
Goal: Know the numbers that keep an ATmega328P-based Arduino alive.
What to do: Use these limits as your decision point for whether a GPIO pin can directly drive a load.
- Per-pin absolute maximum: 40 mA.
- Per-pin safe continuous: 20 mA.
- Total across all pins combined: 200 mA.
An LED at 20 mA is fine. A 12 V relay coil drawing 75 mA is not. Wiring a relay coil straight to a GPIO pin can destroy that pin, and sometimes the whole MCU.
Expected result: You can quickly classify a load as safe for direct GPIO drive or not.
Step 4 - Connect the concept to relay modules
Goal: Understand why relay boards exist and what the GPIO is really doing when you drive one.
What to do: Treat a relay module input as a low-current control signal, not as the relay coil itself. Relay boards (like the 1-channel 5 V relay module) include an opto-isolator and an NPN transistor so the Arduino can sink only a few milliamps to switch a coil that needs much more current.
Expected result: You understand that the module does the heavy lifting and the Arduino pin is only signaling.
Step 5 - Review the NPN transistor "current sink" pattern
Goal: Learn the textbook method for switching higher-current loads with a low-current GPIO signal.
What to do: Follow the standard NPN low-side switch idea: the Arduino pin sources a small base current, and the transistor sinks the larger load current.
Code:
// Arduino pin -> 1k resistor -> transistor BASE
// Load+ -> +supply
// Load- -> transistor COLLECTOR
// transistor EMITTER -> GND
//
// digitalWrite(pin, HIGH) -> transistor saturates
// -> load current sinks through the transistor
// The Arduino pin only sources ~5 mA into the base.
For motor-class loads, skip the bare transistor and use a real driver like the L298N motor driver board.
Expected result: You can describe why a transistor protects the GPIO while allowing higher load current.
Step 6 - Decide when to sink vs source
Goal: Apply sinking and sourcing to common Arduino situations.
What to do: Use these rules of thumb when you choose a wiring style:
- Indicator LEDs: either works. Sourcing is often more intuitive (HIGH = on).
- Logic-level inputs to other ICs: sinking is often safer because a pull-up can be shared on a bus.
- Active LOW peripherals: you sink to enable (common for reset lines, chip selects, and many relay modules).
- Loads bigger than 20 mA: do not drive directly. Use a transistor, MOSFET, relay module, or driver board.
Expected result: You can choose a wiring approach and avoid overloading a GPIO pin.
Conclusion
Sourcing and sinking are two directions of the same current flow. With an Arduino (ATmega328P), knowing whether your pin is sourcing or sinking and staying near the 20 mA per-pin guideline helps prevent dead GPIO pins and unstable projects. When your load needs more than a few milliamps, use a relay module, transistor, MOSFET, or a driver board so the GPIO only handles the control signal.
This guide was inspired by "Sinking Vs Sourcing Current in Arduino" on Instructables, with images credited to the original author of that source tutorial.
Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.


