Arduino Reference
Free reference guide: Arduino Reference
About Arduino Reference
The Arduino Reference is a searchable cheat sheet covering the complete Arduino programming API across six hardware-oriented categories: Digital I/O (pinMode, digitalWrite, digitalRead, shiftOut, pulseIn), Analog (analogRead, analogWrite PWM, analogReference, analogReadResolution, map), Serial communication (Serial.begin, Serial.println, Serial.read, Serial.available, Serial.parseFloat), Libraries (Wire for I2C, SPI, Servo motor control, LiquidCrystal LCD, EEPROM), Interrupts (attachInterrupt, detachInterrupt, noInterrupts/interrupts, volatile variables), and Timers (millis, micros, delay, delayMicroseconds, and the non-blocking millis() pattern).
This reference is built for hardware makers, robotics enthusiasts, electronics students, and embedded systems developers who program Arduino boards such as the Uno, Mega, Nano, Due, and Zero. Each entry includes a short description of the function signature and a practical C++ code snippet — for example, converting analogRead output to voltage, measuring ultrasonic distance with pulseIn, or controlling a servo motor angle. The map() function entry shows a complete example of mapping a potentiometer reading to a PWM output.
The six categories mirror the typical learning path: start with digital I/O, progress through analog signals and serial debugging, incorporate libraries for sensors and actuators, and finally master interrupt-driven and non-blocking timer designs. All content runs in your browser with full dark mode support and is completely free, with no downloads or account required.
Key Features
- Digital I/O: pinMode, digitalWrite, digitalRead, shiftOut for shift registers, and pulseIn for ultrasonic sensors
- Analog: analogRead (0–1023), analogWrite PWM (0–255), analogReference, analogReadResolution (12-bit for Due/Zero), and map()
- Serial communication: Serial.begin, print/println, read, available, and parseFloat for sensor data input
- Built-in libraries: Wire (I2C), SPI, Servo motor control, LiquidCrystal LCD, and EEPROM read/write
- External interrupts: attachInterrupt with RISING/FALLING/CHANGE modes, detachInterrupt, and volatile variable usage
- Global interrupt control: noInterrupts() and interrupts() for protecting critical sections in ISR-shared data
- Timer functions: millis(), micros(), delay() (blocking), delayMicroseconds(), for all timing needs
- Non-blocking delay pattern: millis()-based periodic execution that avoids blocking the main loop
Frequently Asked Questions
What categories does this Arduino reference cover?
Six categories: Digital I/O (pinMode, digitalWrite, digitalRead, shiftOut, pulseIn), Analog (analogRead, analogWrite, analogReference, map), Serial communication, Libraries (Wire/I2C, SPI, Servo, LiquidCrystal, EEPROM), Interrupts (attachInterrupt, volatile), and Timers (millis, micros, delay, non-blocking pattern).
What is the difference between delay() and the millis() non-blocking pattern?
delay() halts the entire program for the specified milliseconds — no other code runs during that time. The millis() non-blocking pattern stores the last execution timestamp and checks elapsed time in each loop iteration, allowing the Arduino to perform other tasks (e.g., read sensors, update LEDs) while waiting for an interval to pass.
How does analogRead work and what values does it return?
analogRead() measures the voltage on an analog pin (A0–A5 on Uno) and returns a 10-bit integer from 0 to 1023, where 0 represents 0V and 1023 represents the reference voltage (default 5V). To convert to voltage: voltage = val * (5.0 / 1023.0). On Due/Zero you can increase resolution to 12 bits with analogReadResolution(12).
What does analogWrite do on Arduino?
analogWrite() outputs a PWM (Pulse Width Modulation) signal on supported pins. The value range is 0–255, where 0 is always LOW and 255 is always HIGH. It is commonly used to control LED brightness or motor speed. Note: it does not output a true analog voltage.
How do I use attachInterrupt correctly?
Call attachInterrupt(digitalPinToInterrupt(pin), ISR_function, mode) where mode is RISING, FALLING, or CHANGE. The ISR function must be short, avoid delay(), and any shared variable must be declared volatile. Use noInterrupts()/interrupts() to protect multi-byte reads of shared variables in the main loop.
What is the Wire library used for?
The Wire library implements the I2C (Two-Wire Interface) protocol. It is used to communicate with I2C-compatible sensors and peripherals such as temperature sensors, OLEDs, and real-time clock modules. Call Wire.begin() in setup() to initialize the bus, then use Wire.beginTransmission(), Wire.write(), and Wire.endTransmission() to send data.
How do I control a servo motor with Arduino?
Include the Servo library, create a Servo object, call myServo.attach(pin) to bind it to a PWM pin, then use myServo.write(angle) to set the position (0–180 degrees). The library handles the PWM timing automatically, so you do not need to generate the pulses manually.
What does pulseIn measure and how is it used for ultrasonic distance sensing?
pulseIn(pin, HIGH) measures the duration of a HIGH pulse on a pin and returns the value in microseconds. For HC-SR04 ultrasonic sensors, you trigger the sensor, then measure the ECHO pin pulse width. Distance (cm) = duration * 0.034 / 2, where 0.034 cm/us is the speed of sound and you divide by 2 for the round trip.