To power up a Raspberry Pi 5, connect a 27W (5V/5A) USB-C Power Delivery (PD) power supply to the USB-C port. For the Raspberry Pi 4 Model B, use a 15W (5V/3A) supply. While plugging in the official power brick is trivial for desktop use, embedded projects, robotics, and rack mounts often require alternative power injection methods and rigorous brownout debugging. A marginal power supply won't just cause a reboot; it will corrupt your SD card and degrade the SoC over time.

This guide covers the exact power specifications across current board variants, safe GPIO 5V injection procedures, and a complete Python script to monitor power health and trigger safe shutdowns.

Power Specifications by Board Variant

The Raspberry Pi Foundation has steadily increased the power envelope to support faster SoCs, USB 3.0 peripherals, and active cooling. The most critical shift occurred with the Pi 5, which requires a 5A supply to unlock full peripheral current. If you feed a Pi 5 a standard 3A USB-C supply, the firmware automatically limits the downstream USB ports to 600mA total to prevent brownouts.

Table 1: Raspberry Pi Power Requirements and PSU Sizing
Board Variant Nominal Voltage Peak Current Draw Recommended PSU Connector Peripheral Limit (if undervolted)
Raspberry Pi 5 (8GB) 5.0V DC 5.0A (25W) 27W USB-C PD (5V/5A) USB-C USB ports limited to 600mA
Raspberry Pi 4 Model B 5.0V DC 3.0A (15W) 15W USB-C (5V/3A) USB-C Throttling / Random reboots
Pi Zero 2 W 5.0V DC 1.2A (6W) 10W Micro-USB (5V/2A) Micro-USB Wi-Fi drops / SD corruption
Compute Module 4 (CM4) 5.0V DC Varies by IO board 15W+ via IO Board Board-specific Depends on carrier design
Bench Tip: When buying third-party USB-C cables for the Pi 5, look for cables explicitly rated for 100W / 5A. Standard 60W USB-C cables often use 28AWG power wires, which will drop the voltage below 4.8V under a 4A load due to cable resistance. You need 20AWG or thicker power lines inside the cable jacket.

Standard USB-C vs. GPIO 5V Injection

For 90% of builds, the USB-C port is the correct path. The USB-C port on the Pi 4 and Pi 5 routes through a dedicated Power Management IC (PMIC) and a polyfuse that protects the board from overcurrent and reverse polarity. However, in custom embedded enclosures, you may need to inject power directly via the 40-pin GPIO header.

Standard USB-C Boot Sequence

  1. Flash Raspberry Pi OS (Bookworm or newer) to a high-endurance microSD card or NVMe SSD.
  2. Insert the storage medium into the Pi.
  3. Connect your HDMI and USB peripherals before applying power (hot-plugging high-draw USB devices on the Pi 4 can cause transient brownouts).
  4. Plug the USB-C power supply into the wall, then into the Pi. The Pi has no physical power switch; it boots the moment it detects 5V on the USB-C VBUS line.

GPIO 5V Injection Procedure

If you are powering the Pi from a custom 5V buck converter, a battery pack, or a PoE HAT, you will use the GPIO header. According to the official GPIO pinout, the 5V and Ground pins are clustered on the top right of the header.

Table 2: GPIO Power Injection Pin Mapping
Pin Number BCM GPIO Function Notes for Power Injection
2 N/A 5V Power Directly feeds the 5V rail. Use for primary positive injection.
4 N/A 5V Power Parallel to Pin 2. Good for distributing current across two wires.
6 N/A Ground Primary ground return. Must be connected to PSU common ground.
9 N/A Ground Secondary ground return. Use alongside Pin 6 for high-current loads.
Safety Warning: Powering the Pi via GPIO bypasses the onboard polyfuse and PMIC protection. If your external 5V supply spikes to 6V, or if you accidentally reverse polarity, you will instantly destroy the SoC and the PMIC. Always verify your external supply with a multimeter (target 5.0V to 5.15V) before connecting it to Pins 2 and 6. For the Pi 5, ensure your external supply can handle 5A transient spikes if you are running heavy USB loads.

Debugging Power Failures: Under-Voltage Errors

The most common power-related failure in Raspberry Pi deployments is the brownout. When the voltage at the SoC drops below roughly 4.63V, the firmware triggers a throttle state. If you are running headless, you won't see the desktop lightning bolt icon. Instead, you will find this exact error string in your kernel logs:

Under-voltage detected! (0x00050005)

The hex code 0x00050005 is a bitmask. The lower bits indicate the current state, and the upper bits indicate historical state. In this case, under-voltage is happening right now, and it has happened since the last boot.

The First Three Things to Check When It Fails

  1. The USB-C Cable and Connections: Measure the voltage at the wall wart, then measure it at the Pi's GPIO 5V pin under load. If the wall wart reads 5.1V but the GPIO reads 4.6V, your cable or connectors are dropping 0.5V. Replace the cable with a shorter, thicker-gauge wire.
  2. Peripheral Backpowering: Are you powering a powered USB hub or a motor controller that is feeding 5V back into the Pi's USB ports or GPIO? Backpowering confuses the PMIC and can trigger false under-voltage flags or physically damage the USB controller.
  3. SD Card Current Spikes: Failing or low-quality microSD cards can draw massive current spikes during write operations, pulling the 5V rail down momentarily. Swap to a high-endurance card (like the SanDisk High Endurance or Samsung PRO Endurance series) or move the OS to an NVMe SSD via the PCIe connector on the Pi 5.

Python Power Monitor and Safe Shutdown Script

To build a robust embedded system, you need a way to monitor power health and shut the Pi down safely if power is about to be lost (e.g., via a UPS signal or a physical button). The following Python script targets the Raspberry Pi 5 and 4B running Raspberry Pi OS (Bookworm). It uses the gpiozero library to monitor a physical shutdown button on GPIO 17, blinks an LED on GPIO 27 during shutdown, and queries the firmware for historical under-voltage events.

import subprocess
import sys
import time
import signal
from gpiozero import Button, LED

# --- Pin Definitions ---
# Connect a momentary push button between GPIO 17 and GND
SHUTDOWN_BUTTON_PIN = 17
# Connect an LED anode to GPIO 27, cathode to GND (with 220 ohm resistor)
STATUS_LED_PIN = 27

# Initialize GPIO components
shutdown_btn = Button(SHUTDOWN_BUTTON_PIN, pull_up=True, bounce_time=0.1)
status_led = LED(STATUS_LED_PIN)

def check_throttle_status():
    """Queries the Pi firmware for under-voltage and thermal throttling history."""
    try:
        result = subprocess.run(
            ['vcgencmd', 'get_throttled'],
            capture_output=True,
            text=True,
            check=True
        )
        # Output looks like: throttled=0x50005
        hex_val = result.stdout.strip().split('=')[1]
        throttled_bits = int(hex_val, 16)
        
        # Bitmask checks based on Raspberry Pi firmware documentation
        if throttled_bits & 0x10000:
            print('WARNING: Under-voltage has occurred since last boot.')
        if throttled_bits & 0x1:
            print('CRITICAL: Under-voltage is happening RIGHT NOW.')
            
        if throttled_bits & 0x20000:
            print('WARNING: Thermal throttling has occurred.')
            
    except subprocess.CalledProcessError as e:
        print(f'Error querying vcgencmd: {e}')
    except Exception as e:
        print(f'Unexpected error in throttle check: {e}')

def safe_shutdown():
    """Initiates a safe OS shutdown and blinks the LED."""
    print('Shutdown button pressed. Initiating safe shutdown...')
    status_led.blink(on_time=0.2, off_time=0.2)
    try:
        subprocess.run(['sudo', 'shutdown', '-h', 'now'], check=True)
    except subprocess.CalledProcessError as e:
        print(f'Shutdown command failed: {e}')

def cleanup_and_exit(signum, frame):
    """Handles graceful exit if the script is stopped via terminal."""
    print('\nExiting monitor script. Cleaning up GPIO...')
    status_led.off()
    shutdown_btn.close()
    sys.exit(0)

if __name__ == '__main__':
    # Catch SIGINT (Ctrl+C) and SIGTERM for safe cleanup
    signal.signal(signal.SIGINT, cleanup_and_exit)
    signal.signal(signal.SIGTERM, cleanup_and_exit)
    
    print('Raspberry Pi Power & Shutdown Monitor Active.')
    print('Press Ctrl+C to exit.')
    
    # Run initial power health check
    check_throttle_status()
    
    # Turn on LED to indicate system is running
    status_led.on()
    
    # Bind the button to the shutdown function
    shutdown_btn.when_pressed = safe_shutdown
    
    # Keep script alive
    while True:
        time.sleep(1)

How to deploy this script: Save it as power_monitor.py. To run it automatically on boot, create a systemd service file at /etc/systemd/system/power-monitor.service that executes /usr/bin/python3 /home/pi/power_monitor.py as root (required for the shutdown command).

Extending and Simplifying Your Power Build

Depending on your deployment environment, you may need to scale your power architecture up or down.

How to Simplify

If you are tired of dealing with custom buck converters, GPIO wiring, and brownout debugging, simplify by using the official Raspberry Pi 27W USB-C Power Supply paired with the Active Cooler. The Active Cooler draws roughly 1.5W under full fan load, but because the official PSU is tuned exactly to the Pi 5's PMIC negotiation profile, it eliminates the voltage drop variables inherent in third-party chargers. For software, disable the Python monitor script and rely entirely on the built-in vcgencmd cron-job logging.

How to Extend

For industrial, automotive, or remote IoT deployments, standard USB-C power is insufficient. Extend your build using these methods:

  • PoE+ (Power over Ethernet): Use the official Raspberry Pi PoE+ HAT. This delivers up to 25.5W over standard Cat6 Ethernet. It includes an isolated flyback converter and a cooling fan. Ensure your network switch supports the 802.3at (PoE+) standard, not just 802.3af, which only provides 15.4W (barely enough for a Pi 4 with peripherals).
  • UPS HATs: For graceful shutdowns during mains failures, integrate a UPS HAT like the PiJuice or the Waveshare UPS HAT. These use 18650 Li-ion cells or LiPo pouches with dedicated I2C battery management ICs that can send an I2C interrupt to the Pi's GPIO to trigger the safe_shutdown() function in the script above when the main power rail drops.
  • Automotive 12V to 5V Buck Converters: If powering a Pi from a car or solar 12V battery, do not use cheap linear regulators (like the 7805); they will overheat and fail. Use a switching buck converter rated for at least 8A (like those based on the LM2596 or MP1584 chips, properly heatsinked) to step 12V-14.4V down to a stable 5.1V, feeding directly into the GPIO 5V pins.

By matching your power supply topology to the exact current envelope of your specific Pi variant, and utilizing firmware-level throttling logs, you can eliminate the vast majority of random reboots and SD card corruptions that plague embedded Raspberry Pi projects. For deeper hardware-level documentation on the Pi 5's DA9091 PMIC and power sequencing, refer to the official Raspberry Pi hardware documentation.