Arduino Cheat Sheet

The majority of content found on this cheat sheet comes from the official Arduino documentation, if you find that something is lacking please comment and I will update this post accordingly.

Including Files

#include <Adafruit_GFX.h>

Using #include <...> the compiler searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE

#include "joystick.h"

Using #include "..." the compiler searches in the same directory as the file containing the directive.

Data Types

Below is a complete list of all data types available when programming on the Arduino platform. I will try to keep this section up to date as I learn more.

Type Example Storage Range
void void setup() { ... } - -
boolean true 1 byte (8 bit) true
char 'A' 1 byte (8 bit) -
byte 128 1 byte (8-bit) 0 to 255
int 64 2 byte (16 bit) -2,147,483,648 to 2,147,483,647
word 10000 -- 2
long 186000L 4 bytes (32 bits) 2,147,483,648 to 2,147,483,647
short 13 2 bytes (16 bits) -32,768 to 32,767
float - 4 bytes (32 bits) -3.4028235E+38 to 3.4028235E+38
double 1.117 8 bytes (64 bits)* ...
string char[] "arduino" varies varies
String "arduino" varies varies
array vals[0] == 2 varies varies

Core Methods

Some useful methods / functions for writing your applications.

delay()

Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000 milliseconds in a second.)

delay(1000)

Working with IO

Useful methods when working with Arduino pins.

// Sets the pin as input (using internal pullup resistor)
pinMode(JOY_BTN, INPUT_PULLUP);

// Sets the pin as an input
pinMode(JOY_X, INPUT);

// Reads data from an analog pin (0-1024)
int aData = analogRead(pinX);

// Reads data from a digital pin (0-1)
int dData = digitalRead(pinBtn);

Working with Serial.

// Start serial @ 9600 bps
Serial.begin(9600);

// Append given value to current line
Serial.print("...");

// Append given value to line and insert a line break
Serial.println("...");

Comments

// (single line comment)
/* */ (multi-line comment)

Constants

HIGH | LOW
INPUT | OUTPUT | INPUT_PULLUP
LED_BUILTIN
true | false

Time

Math

Characters

Random Numbers

Bits and Bytes

Interrupts