Digital I/O Cheatsheet

Hardware Arduino / Cheatsheet

Digital I/O Cheatsheet

pinMode, digitalWrite, digitalRead ߀” everything for pins and buttons.

Pin Configuration
pinMode(pin, OUTPUT) Configure pin to drive components (LED, relay, buzzer)
pinMode(pin, INPUT) Configure pin to read a signal ߀” floats if nothing connected
pinMode(pin, INPUT_PULLUP) Input with internal pull-up ߀” reads HIGH when open, LOW when connected to GND
Digital Output
digitalWrite(pin, HIGH) Set pin to 5 V (turns LED on, closes relay, etc.)
digitalWrite(pin, LOW) Set pin to 0 V (turns LED off, opens relay, etc.)
digitalWrite(pin, !digitalRead(pin)) Toggle a pin ߀” reads current state and flips it
Digital Input
digitalRead(pin) Returns HIGH or LOW depending on the voltage at the pin
if (digitalRead(2) == LOW) Button pressed check when using INPUT_PULLUP (pressed = LOW)
int state = digitalRead(pin); Store the pin state in a variable for later comparison
Wiring Rules
LED: pin ߆’ 220 ?© ߆’ LED+ ߆’ LEDß?’ ߆’ GND Always use a current-limiting resistor with LEDs (220߀“470 ?©)
Button (INPUT_PULLUP): pin ߆’ button ߆’ GND No external resistor needed when using INPUT_PULLUP
Max 40 mA per pin, 200 mA total Arduino Uno pin current limits ߀” use a transistor or relay for high-current loads