Back to All Cheatsheet Libraries cheatsheets

Arduino

Core language functions, arduino-cli and IDE shortcuts, and wiring basics with a non-blocking timing pattern.

Total Functions: 0
Category Function Description
Digital I/OpinMode(pin, mode)Configures a pin as INPUT, OUTPUT, or INPUT_PULLUP.
Digital I/OdigitalWrite(pin, value)Sets a digital pin HIGH or LOW.
Digital I/OdigitalRead(pin)Reads HIGH or LOW from a digital pin.
Analog I/OanalogRead(pin)Reads a 0-1023 value from an analog input pin (10-bit ADC on most boards).
Analog I/OanalogWrite(pin, value)Writes a PWM (0-255) value to a supported pin — not a true analog voltage.
Timingdelay(ms)Blocks execution for the given number of milliseconds.
TimingdelayMicroseconds(us)Blocks execution for the given number of microseconds.
Timingmillis()Returns milliseconds since the board started — the standard non-blocking-timing building block.
Timingmicros()Returns microseconds since the board started.
SerialSerial.begin(baud)Opens serial communication at the given baud rate (commonly 9600 or 115200).
SerialSerial.print() / println()Writes text/values to the serial monitor, with or without a trailing newline.
SerialSerial.available()Returns the number of bytes waiting to be read from the serial buffer.
SerialSerial.read()Reads the next incoming byte from the serial buffer.
InterruptsattachInterrupt(pin, isr, mode)Runs a function automatically when a pin changes (RISING/FALLING/CHANGE).
InterruptsdetachInterrupt(pin)Disables a previously attached interrupt on a pin.
Mathmap(value, fromLo, fromHi, toLo, toHi)Re-scales a value from one numeric range to another — the standard sensor-to-output scaling helper.
Mathconstrain(value, min, max)Clamps a value to stay within a given range.
Randomrandom(min, max)Returns a pseudo-random long in the given range.
Structurevoid setup()Runs once at boot — the place for pinMode()/Serial.begin() calls.
Structurevoid loop()Runs continuously after setup() — the sketch's main body.

arduino-cli Commands

Command Description
arduino-cli board listLists connected boards and their detected port/FQBN.
arduino-cli core install arduino:avrInstalls the platform core needed to compile for a given board family.
arduino-cli sketch new MySketchScaffolds a new sketch folder with a starter .ino file.
arduino-cli compile --fqbn arduino:avr:uno MySketchCompiles a sketch for a specific board.
arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:uno MySketchUploads a compiled sketch to a board on the given serial port.
arduino-cli lib install "Servo"Installs a library by name from the Library Manager index.
arduino-cli lib search keywordSearches the library index for a keyword.
arduino-cli monitor -p /dev/ttyUSB0 -c baudrate=9600Opens a serial monitor on the given port at a given baud rate.

Arduino IDE Shortcuts

Action macOS Windows
Verify / Compile⌘RCtrl+R
Upload⌘UCtrl+U
Serial Monitor⌘⇧MCtrl+Shift+M
Serial Plotter⌘⇧LCtrl+Shift+L
New Sketch⌘NCtrl+N

Wiring Basics

Breadboard Rails

The two outer rows on each side are power rails (+ and −), shared along the whole strip — the inner rows are grouped in short 5-hole columns, not connected across the center gap.

Pull-up / Pull-down Resistors

A floating digital input reads noise — a resistor to 5V (pull-up) or GND (pull-down) gives it a defined rest state. Most boards support INPUT_PULLUP in software, skipping the physical resistor.

Current-Limiting Resistors

An LED wired directly to a pin will draw too much current and burn out — a ~220Ω-330Ω series resistor is the standard safe default for a 5V pin.

Common Ground

Every component and power source in a circuit needs a shared GND reference — a very common "nothing works" bug is simply a missing ground connection between the board and an external power supply.

Non-Blocking Timing with millis()

The pattern that replaces delay() once a sketch needs to do more than one thing at a time.

unsigned long previousMillis = 0; const long interval = 1000; void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; // toggle an LED, poll a sensor, etc. — runs every `interval` ms // without blocking the rest of loop() } }

Quick Tips

delay() blocks everything
A delay(1000) call freezes the entire sketch for a full second — no button reads, no sensor polling. Use millis()-based timing once a sketch needs to stay responsive.
Interrupt Service Routines must be fast
Keep an ISR short — no delay(), no Serial.print() — and mark any variable it touches as volatile, or the compiler may cache a stale value in the main loop.
Not every pin does PWM
analogWrite() only works on pins marked with a ~ on the board silkscreen — check the specific board's pinout before wiring a dimmable LED or motor driver.
USB power has limits
A USB port typically supplies ~500mA — motors, multiple LEDs, or servos under load need an external power supply, not the board's own 5V pin.