⚙ PROGRAM STRUCTURE
setup() – Runs once when program starts
loop() – Runs repeatedly after setup
#include <file.h> – Includes a library
#define NAME value – Defines constant or macro
const – Declares unchangeable variable
return – Exits a function, returns value
{ } – Groups statements
; – Ends a statement
🔢 DATA TYPES
int – Integer (−32,768 to 32,767)
long – 32-bit integer
float – Decimal number
double – Same as float on most boards
char – Single character (‘A’, ‘1’, etc.)
byte – Unsigned 8-bit integer (0–255)
boolean – True or false
String – Text storage and manipulation
array[] – Stores multiple values
struct – Custom grouped data type
⚡ DIGITAL I/O
pinMode(pin, mode) – Set pin as INPUT, OUTPUT, or INPUT_PULLUP
digitalWrite(pin, value) – Output HIGH or LOW
digitalRead(pin) – Read digital signal
tone(pin, frequency) – Generate tone
noTone(pin) – Stop tone
pulseIn(pin, value) – Measure pulse length
shiftOut(dataPin, clockPin, bitOrder, value) – Shift bits out serially
shiftIn(dataPin, clockPin, bitOrder) – Shift bits in serially
🔁 ANALOG I/O
analogRead(pin) – Reads analog voltage (0–1023)
analogWrite(pin, value) – Outputs PWM signal (0–255)
analogReference(type) – Sets analog reference voltage
analogReadResolution(bits) – Sets ADC resolution
analogWriteResolution(bits) – Sets PWM resolution
🕒 TIME FUNCTIONS
delay(ms) – Pause for milliseconds
delayMicroseconds(us) – Pause for microseconds
millis() – Time since program start (ms)
micros() – Time since start (µs)
MATH FUNCTIONS
min(x, y) – Returns smaller of two values
max(x, y) – Returns larger of two values
abs(x) – Returns absolute value
constrain(x, a, b) – Limits value between a and b
map(x, inMin, inMax, outMin, outMax) – Re-maps value from one range to
another
pow(x, y) – x raised to the power y
sqrt(x) – Square root
sin(x) – Sine (x in radians)
cos(x) – Cosine
tan(x) – Tangent
round(x) – Round to nearest integer
ceil(x) – Round up
floor(x) – Round down
💬 SERIAL COMMUNICATION
[Link](baudRate) – Starts serial communication
[Link](value) – Prints value
[Link](value) – Prints value with newline
[Link]() – Reads one byte from serial buffer
[Link]() – Returns number of bytes available
[Link](value) – Sends binary data
[Link]() – Reads integer from input
[Link]() – Waits for data to finish sending
[Link]() – Stops serial communication
🔀 CONTROL STRUCTURES
if(condition) – Executes code if true
else – Executes code if false
else if – Additional condition check
switch(variable) – Executes one case based on variable
case – Defines a case inside switch
default – Runs if no case matches
for(init; condition; increment) – Repeats loop with counter
while(condition) – Loops while condition true
do { } while(condition) – Loops at least once
break – Exits loop or switch
continue – Skips to next loop iteration
goto label – Jumps to label (avoid use)
BITWISE & BYTE OPERATIONS
& – AND
| – OR
^ – XOR
~ – NOT
<< – Shift left
>> – Shift right
bitRead(x, n) – Reads bit n of x
bitSet(x, n) – Sets bit n of x
bitClear(x, n) – Clears bit n of x
bitWrite(x, n, b) – Writes bit n with value b
💾 RANDOM & UTILITY
randomSeed(seed) – Seeds the random generator
random(min, max) – Returns random number
sizeof(variable) – Returns variable size (bytes)
F("string") – Stores string in Flash memory
🔌 COMMUNICATION LIBRARIES
[Link]() – Start I2C
[Link](address) – Start I2C transmission
[Link](value) – Send data to I2C
[Link]() – End transmission
[Link](address, num) – Request data from I2C
[Link]() – Read received byte
[Link]() – Initialize SPI bus
[Link](data) – Send and receive SPI data
[Link](pin) – Attach servo to pin
[Link](angle) – Set servo position
[Link]() – Detach servo
[Link](address) – Read EEPROM byte
[Link](address, value) – Write EEPROM byte
[Link](address, value) – Update only if different
⚙ INTERRUPTS
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) – Attach interrupt
to pin
detachInterrupt(interrupt) – Remove interrupt
noInterrupts() – Disable interrupts globally
interrupts() – Enable interrupts globally
volatile – Marks variable safe for ISR
ADVANCED MEMORY & COMPILER
PROGMEM – Store variable in Flash memory
#ifdef / #ifndef / #endif – Conditional compilation
#pragma – Compiler instruction
__DATE__, __TIME__ – Compilation date and time
SPECIAL UTILITIES
word(high, low) – Combines two bytes
highByte(x) – Extracts high byte
lowByte(x) – Extracts low byte
isAlpha(char) – Checks if alphabetic
isDigit(char) – Checks if numeric
isSpace(char) – Checks for space character