Arduino Quick Reference Cheatsheet
For more information visit: [Link]
Program Flow / Control Pin Configuration - INPUT vs OUTPUT Data \ Variable Types
/* Each Arduino Sketch must contain the pinMode(pin, INPUT/OUTPUT/INPUT_PULLUP); const (indicates a constant data type)
following two functions */ void (null data type)
OUTPUT Control int (integer -32,768 to 32,767)
void setup() float (floating point / decimal numbers)
digitalWrite(pin, val); // val: HIGH or LOW arrayName[] – list of elements (any type)
{
analogWrite(pin, val); // val: 0 to 255. String (array of characters)
// runs only once.
}
tone(pin, freq); // freq in Hertz
void loop() System constants / functions
tone(pin, freq, duration); //duration in ms
{
noTone(pin); // stop tone on pin HIGH / LOW
// runs repeatedly.
OUTPUT / INPUT / INPUT_PULLUP
}
Reading INPUTs millis(); //returns # of milliseconds
delay(time_millis); // pauses program in ms buttonPress = digitalRead(pin); // any pin micros(); //returns # of microseconds
delayMicroseconds(time_micros); //pause s sensorVal = analogRead(pin); // A0-A5 pins
Basic Logic Math Operators
Communication
= // assignment
Simple if()-else [Link](baudrate); + // addition
[Link](“”); // print data out - // subtraction
if(condition) [Link](“”); // print with new line
{ * // multiplication
//true condition code here / // division
x = [Link](); // reads a single byte % // modulus
} // data
else x = [Link](); // read the next
{ // available integer Logic Operators
//false statement code here == // is equal to?
} Looping != // is not equal to?
----------------- while(condition) < // less than
Compound if()-else if()-else { > // greater than
} <= // less than or equal
if(condition1) >= // greater than or equal
for(init; condition; update variable)
{ && // compound AND
{
//true condition1 code here || // compound OR
}
} ! // NOT (inverse)
else if(condition2)
{ Comments/Debug
//true condition2 code here /* this is a multiline comment. nothing Libraries
} between here will be run or executed */ #include <libraryName.h>
else
{ // this is a single libraryName objectName;
//false statement code here // line comment
} // read library documentation for usage.
rev. 0.2