Skip to main content

What is GPIO

GPIO (General Purpose Input/Output) is a pin on a microcontroller that you can control with software — set it HIGH (3.3V or 5V) or LOW (0V), or read whether an external device is pulling it HIGH or LOW.

Digital I/O Basics

ModeWhat It DoesExample
OUTPUTPin drives voltage HIGH or LOWTurn on LED, control relay
INPUTPin reads external voltage levelRead button press, detect motion
INPUT_PULLUPPin reads, with internal resistor to VCCButton without external resistor

Arduino Example

const int ledPin = 13; // OUTPUT
const int buttonPin = 2; // INPUT_PULLUP

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
if (digitalRead(buttonPin) == LOW) { // pressed (pullup inverts)
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}

Voltage Levels

BoardHIGH =LOW =Max InputNotes
Arduino Uno5V0V5V5V tolerant
ESP323.3V0V3.6VNOT 5V tolerant
Raspberry Pi3.3V0V3.6VNOT 5V tolerant
STM323.3V0V3.6V (some 5V tolerant)Check datasheet
5V signal into 3.3V pin = dead board

Always check voltage levels. ESP32 and Raspberry Pi GPIOs are NOT 5V tolerant. Use a level shifter or voltage divider when connecting 5V sensors.

Common Pitfalls

ProblemLikely CauseFix
Pin always reads HIGH or LOWNo pull-up/downUse INPUT_PULLUP or add external resistor
Pin does not output expected voltageWrong pinModeMust call pinMode() in setup()
LED on ESP32 is very dim3.3V logic, LED needs resistorUse 100-220 ohm resistor for 3.3V
GPIO pin deadOvervoltage or shortThe pin is physically damaged; use another