Pin Reference
Pin Name Description
D2-D13 Digital I/O pins – used for on/off signals
A0-A5 Analog input pins – used for reading analoginput
GND Ground – must be connected in all circuits
5V / 3.3V Power supply pins for components like sensors
PWM (~) Pins with ~ support analog output
VIN To provide voltage from battery to arduino
Structure
void setup() {
// setting up the Arduino
pinMode();
Serial.begin(9600);
}
void loop() {
// the tell the robot what to do
}
setup() sets initial settings. loop() runs forever.
Input / Output
pinMode(pin, mode);
Sets whether a pin is an input or output.
mode can be:
INPUT - to read signals
OUTPUT - to send signals
INPUT_PULLUP - input with internal pull-up resistor
digitalWrite(pin, HIGH); // Turns pin ON (5V)
digitalWrite(pin, LOW); // Turns pin OFF (0V)
Sends voltage through a digital pin -- used to turn things on/off like LED.
digitalRead(pin);
Reads digital state (either HIGH or LOW) from an input pin like a button.
analogRead(pin); // Returns a value between 0-1023 by reading voltage
analogWrite(pin, value); // Only on PWM (~) pins that start with ~
value ranges from 0 (off) to 255 (full power).
Timing
delay(1000);
Pauses the program for a specified time in milliseconds (1000 = 1 second)
Logic & Loops
if (condition) { ... }
Executes code if the condition is true
else if (condition) { ... }
Adds more conditions
else { ... }
do if the above do not pass.
for (int i = 0; i < 10; i++) { ... }
Repeats code 10 times. Useful for counting loops.
while (condition) { ... }
Keeps running as long as condition is true
Symbol Name / Meaning Description
+ Addition Adds two values
- Subtraction Subtracts the right value from the left
* Multiplication Multiplies two values
/ Division Divides the left value by the right value
% Modulo Gives the remainder after division (e.g., 7 % 3 → 1)
== Equal to True if both values are equal
!= Not equal to True if values are not equal
< Less than True if left value is less than the right
> Greater than True if left value is greater than the right
<= Less than or equal to True if left value is less than or equal to the right
>= Greater than or equal to True if left value is greater than or equal to the right
&& AND True only if both conditions are true
|| or One must be true
! NOT Reverses the condition: !true → false, !false → true
Serial Monitor
Serial.begin(9600);
Starts communication with the computer. Use 9600 baud (default).
Serial.print("Text");
Sends text without a new line.
Serial.println(val);
Serial.println(“Text”);
Sends text with a new line (starts next message on a new line).
Others
map(value, fromLow, fromHigh, toLow, toHigh);
Re-maps a value from one range to another.
Example: map 512 (from 0–1023) to 0–100 → returns ~50.
Common Tips for Beginners
Every command ends with ;
Use // to write comments
Indent code properly for readability
Use {} to wrap code blocks in if/loop functions
Double-check your circuit before uploading
Always select the correct Board and Port in the Arduino IDE
Variables & Data Types
Type Category Name / Purpose Description
int Integer Integer number Stores whole numbers from -32,768 to 32,767
long Integer Long integer Stores larger integers from -2,147,483,648 to
2,147,483,647
unsigned Integer Positive integer only Stores 0 to 65,535
int
float Decimal Floating-point Stores decimal numbers (up to ~6–7 digits of
number precision)
char Characte Single character Stores one character or a number (0–255)
r
boolean Logical
True/false flag Stores only true or false
String Text Sequence of Stores and manipulates text
characters
byte Byte 8-bit unsigned Stores values from 0 to 255
number
Things You Can Do with Variables
Operation Symbol / Keyword Description
Declare type name; Creates a variable of a given type
Assign = Stores a value into a variable
Add/Subtract +, - Modify numeric variables
Multiply/Divide *, / Apply arithmetic operations
Update +=, -=, etc. Shortcut for modifying values
Compare ==, !=, etc. Check equality or conditions
Concatenate + Join strings together
Convert String(), int(), etc. Change data from one type to another
switch (expression) {
case value1:
// code to run if expression == value1
Part What It Does
break; switch(value) Tests a variable or expression
against multiple possible values.
case value2: case label: Defines a possible match. Runs
// code to run if expression == value2 the code under this label if
matched.
break; break; Ends the case after running.
// more cases...
Prevents fall-through to the next
case.
default: default: Runs if no case matches.
Optional, but useful as a fallback.
// code to run if no case matches
break;}