Atlas Robotics
FundamentalsBasic

What is GPIO? The essential multipurpose pin on every microcontroller

Atlasbot · 20/8/2026 · 10 min read

What is GPIO? The essential multipurpose pin on every microcontroller
GPIO operates in INPUT and OUTPUT modes

Open any STM32 or ESP32 pinout and you will see that most of the pins are called GPIO. This is the most basic and most used type of pin in embedded programming — understanding how it works properly is the first step before wiring up any components.

Two basic modes: INPUT and OUTPUT

GPIO (General Purpose Input/Output) is a multi-purpose pin on the microcontroller, which can be programmed to operate in 1 of 2 modes:

  • INPUT (input): MCU reads voltage status on pins — used to receive signals from buttons, switches, digital sensors...
  • OUTPUT (output): MCU actively sets the pin to HIGH or LOW — used to control LEDs, relays, or send signals to other components.

Important point: you can configure the same physical pin as INPUT or OUTPUT depending on your needs, and can be changed right in the code - that's why it's called "general purpose", different from specialized pins with fixed functions.

In short: GPIO is 1 pin, many roles - reading (INPUT) or writing (OUTPUT) are all decided by the code, not fixed in hardware.

GPIO pins are often more "versatile" than digital INPUT/OUTPUT

On most modern microcontrollers, a pin marked GPIO can actually be switched to multiple alternate functions other than the usual digital INPUT/OUTPUT — selected via software configuration (often called pin multiplexing/mux):

  • Read analog through ADC (see article Digital vs Analog).
  • Output PWM to control motor speed/LED brightness.
  • Acts as communication pin UART/I2C/SPI with other sensors/modules.

This is why a chip only has ~30-50 physical pins but supports dozens of different peripherals — not each peripheral has its own pin, but many peripherals "share" the same set of GPIO pins, choosing which function at a time through software configuration.

Technical details

Parameters

Number of available GPIO pins and maximum current per pin on popular boards:

Board/ChipNumber of available GPIOsMaximum current per leg
Arduino Uno (ATmega328P)~20 feet~40mA
STM32F103C8T6 ("Blue Pill")~37 feet~20-25mA
ESP32~34 pins (some indicate input)~40mA

Register / Bit / Byte

The pinMode()/digitalWrite() function that Arduino provides is essentially just a wrapper for setting/clearing bits in real hardware registers. On STM32, 3 main registers control the GPIO of each port:

  • GPIOx_MODER — mode register, uses 2 bits per pin: 00 = input, 01 = output, 10 = alternate function, 11 = analog.
  • GPIOx_ODR (Output Data Register) — each bit corresponds to 1 pin, set bit = output HIGH, clear bit = output LOW.
  • GPIOx_IDR (Input Data Register) — reads the current voltage level on each pin, mentioned in the Bit/Byte article.
For example: set pin PA5 (LED on Nucleo board) as OUTPUT
GPIOA_MODER bits 10-11 (corresponding to pin 5) = 01
→ GPIOA->MODER |= (0b01 << (5 * 2));   // set 2 bits at pin 5

Practical applications

In the robot control circuit, GPIO OUTPUT is often used to turn on/off the ENABLE pin of the motor driver (L298N, TB6612) — MCU only needs to put 1 pin on HIGH/LOW to enable or completely disable the motor, separate from the speed control PWM signal. In the opposite direction, multiple GPIO INPUT pins are often used at the same time to read the limit switches at both ends of the lifting mechanism's journey - each switch has its own pin, read in parallel to know exactly which limit the mechanism has reached.

Practical examples: reading push buttons, controlling LEDs

// Arduino
void setup() {
  pinMode(13, OUTPUT);      // Pin 13 is OUTPUT, which controls the LED
  pinMode(2, INPUT_PULLUP); // Pin 2 is INPUT, has a built-in pull-up resistor (see article Pull-up/Pull-down)
}

void loop() {
  int buttonState = digitalRead(2);
  if (buttonState == LOW) {          // push button pulls the foot down to LOW when pressed
    digitalWrite(13, HIGH);          // turn on LED
  } else {
    digitalWrite(13, LOW);           // turn off LED
  }
}
// STM32 HAL — same logic, written at a lower level
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);    // OUTPUT: turns on LED
GPIO_PinState state = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0); // INPUT: read button press

The two code snippets above do the same thing — Arduino is more abstract (1 line digitalWrite), STM32 HAL is more detailed (specifying port GPIOA/GPIOB and pin number GPIO_PIN_x) — but the underlying hardware is identical: read/write voltage level on 1 pin.

Common mistakes

  • Forgot to pinMode()/configure pin before using — on many platforms, GPIO pin defaults to unknown or INPUT state — forgetting to declare OUTPUT causes digitalWrite() to not have the expected effect.
  • Reading an unconnected INPUT pin (floating) — an unconnected INPUT pin (no HIGH, no clear LOW) will read a random value due to electromagnetic interference from the surrounding environment — always need a pull-up/pull-down resistor when reading buttons/switches (see next article in the category).
  • Exceeding the maximum allowable current for each pin — each GPIO pin can only withstand a limited current (usually 20-40mA depending on the chip, see datasheet) — plugging a high-power LED or small motor directly into the OUTPUT pin may burn the pin, see Voltage/Current/Power article.
  • Confusion between push-pull and open-drain output — push-pull mode (common default) actively pulls pins to HIGH or LOW; Open-drain mode only actively pulls down to LOW, while HIGH requires an external pull-up resistor - the wrong mode causes the circuit to not work even though the code is logically correct.

Conclusion

GPIO is the foundation of nearly all hardware interactions in embedded programming — understanding INPUT/OUTPUT modes, along with the ability to switch to alternative functions, is a requirement for reading any wiring diagram. The next article in this section delves into pull-up/pull-down resistors — the solution to the "floating pin" problem mentioned above.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

What is GPIO? The essential multipurpose pin on every microcontroller — Atlas Robotics