
Arduino Cheatsheet
Values
int 3,-4
bool true ,false
Integer Operations
sum +3+4== 7
difference -6-8== -2
product *2*7== 14
quotient /7/3== 2
remainder %7%3== 1
Boolean Operations
equality == 4== 4
inequality < > 6>4
<= >= 5<= 7
not ! !(5<2)
!= 5!= 3
and && (4<5) && (7>3)
and/or || (4>9) || (4>2)
Assignment
initialisation int x=73;
int y;
updating x=37;
Abbreviations
x=x+1x++ or ++x
x=x-1x-- or --x
x=x+y x += y
x=x-y x -= y
x=x*y x *= y
x=x/y x /= y
x=x%y x %= y
Comments
// single line comment
/* ... */ multiple lines between the *s
If Blocks
Optionally run blocks of code depending on various
conditions. if is required, else if and else
blocks are optional but else should come last if
you use it.
if (a ge <13){
pr i nt (" C hi l d ") ;
}el se if (a ge <18){
pr i nt (" T ee n ag e r ") ;
}el se if (a ge <60){
pr i nt (" A du l t ") ;
}else {
pr i nt (" R e sp e ct e d Eld e r ") ;
}
For Loops
For loops run a block of code until a counter is
invalid. The following prints the numbers 0 to 9:
fo r (in t i=0;i<10;i=i+1){
pr i nt (i) ;
}
The first statement initialises the counter before
the loop runs. The second gives the condition for
the block to be run (when it is false , the loop
stops). The last says what happens in between it-
erations.
Common Functions
Digital pins can be in one of two modes, INPUT
if you want to check the voltage such as with a
switch, OUTPUT if you want to turn the pins on/off
such as with an LED. The voltages can be set to
HIGH (5 V) or LOW (0 V).
pinMode(pin,mode)
digitalRead(input_pin)
digitalWrite(output_pin,voltage)
delay(time)
The delay time is in milliseconds.
Main Functions
void se t up ( ) {
// code here runs when the
// Arduino starts
}
void loop( ) {
// this code runs again and
// again after setup until
// power is lost
}