Every Arduino program (sketch) has two essential functions:
void setup() {} - Runs once at the beginning of the program. Used for initialization.
void loop() {} - Runs repeatedly after setup() finishes. This is where the main program logic goes.
A quick reference guide for Arduino development, covering essential concepts, code snippets, and hardware information for both beginners and advanced users.
|
Every Arduino program (sketch) has two essential functions:
|
|
Example:
|
|
|
Integer (whole number). Typically 2 bytes (-32,768 to 32,767). |
|
|
Unsigned integer (0 to 255). |
|
|
Long integer. Typically 4 bytes (-2,147,483,648 to 2,147,483,647). |
|
|
Floating-point number (number with decimal point). 4 bytes. |
|
|
Boolean value (true or false). |
|
|
Character. 1 byte. |
|
|
Sets the specified pin as |
|
|
Writes |
|
|
Reads the value ( |
|
|
Reads the value from the specified analog pin (0 to 1023). |
|
|
Writes an analog value (PWM signal) to a pin (0 to 255). Only works on PWM enabled pins (marked with ~ on the board). |
|
|
Configures the reference voltage used for analog input ( |
|
|
Initializes serial communication at the specified baud rate (e.g., 9600, 115200). |
|
|
Sends data to the serial port as human-readable ASCII text. |
|
|
Sends data to the serial port, followed by a carriage return and line feed. |
|
|
Gets the number of bytes (characters) available for reading from the serial port. |
|
|
Reads the first available byte of incoming serial data. |
|
|
Pauses the program for the amount of time (in milliseconds) specified as parameter. |
|
|
Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero) after approximately 50 days. |
|
|
Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero) after approximately 70 minutes. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assignment operator (assigns a value to a variable). |
|
|
Equality operator (checks if two values are equal). |
|
|
Inequality operator (checks if two values are not equal). |
|
|
Greater than operator. |
|
|
Less than operator. |
|
|
Logical AND operator (returns true if both conditions are true). |
|
|
Logical OR operator (returns true if at least one condition is true). |
|
|
Logical NOT operator (reverses the logical state of its operand). |
|
|
Addition. |
|
|
Subtraction. |
|
|
Multiplication. |
|
|
Division. |
|
|
Modulo (returns the remainder of a division). |
|
|
Attaches an interrupt to the specified pin. |
|
|
Detaches the interrupt on the specified pin. |
|
|
Re-enables interrupts (after they have been disabled by |
|
|
Disables interrupts. |
|
Libraries provide extra functionality to your sketches. To include a library:
Examples:
|
|
|
Writes a byte to the EEPROM at the specified address. |
|
|
Reads a byte from the EEPROM at the specified address. |
|
|
Writes a byte to the EEPROM at the specified address, only if the new value is different from the old value. |