Arduino API
A reference to the Arduino Programming Language.
Compact version of the Arduino Language Reference. This document is a TLDR; of the Arduino API.
Please note that as of 2024/01/15, this article is still a work in progress.
Functions
Digital I/O
Method & Parameters | Description | Returns |
---|---|---|
| Reads the state of a digital pin. |
|
| Writes a state to a digital pin. | Nothing |
* | Define the mode of a pin. | Nothing |
*Available modes are:
(0)INPUT
(1)OUTPUT
(2)INPUT_PULLUP
(3)INPUT_PULLDOWN
(4)OUTPUT_OPENDRAIN
Analog I/O
Method & Parameters | Description | Returns |
---|---|---|
| Reads the value of an analog pin in a 10-bit resolution (0-1023).* |
|
| Sets ADC read resolution in bits. | Nothing |
| Changes the voltage reference for a board.** | Nothing |
| Writes a value to a PWM supported pin in a 8-bit resolution (0-255).** | Nothing |
| Sets write resolution for a board. | Nothing |
- *The value range changes based on the resolution. 0-1023 is 10-bit resolution, 0-4096 is 12-bit and so on.
- **Each board/architecture has a set of different reference voltages available.
- ***The value range changes based on the resolution. 0-255 is default (8-bit).
Advanced I/O
Method & Parameters | Description | Returns |
---|---|---|
| Generates a square wave on specified pin, with 50% duty cycle. | Nothing |
| Stops generation of square wave on the specified pin. | Nothing |
| Reads a pulse (either HIGH or LOW) on a pin and returns the length of the pulse (in microseconds) |
|
| Returns the length of the pulse (in microseconds) |
|
* | Shifts in a byte of data one bit at a time, and returns the value of the bit read. |
|
** | Shifts out a byte of data one bit at a time. | Nothing |
- *The
parameter is eitherbitOrder
(MSBFIRST
) or1
(LSBFIRST
) (most / least significant bits).0
- **The pin used for
needs to be configured as anshiftOut()
, usingOUTPUT
pinMode()
Time
Method & Parameters | Description | Returns |
---|---|---|
| Freezes program execution for specified number of milliseconds. | Nothing |
| Freezes program execution for specified number of microseconds. | Nothing |
| Returns milliseconds passed since program start. |
|
| Returns microseconds passed since program start. |
|
Math
Method & Parameters | Description | Returns |
---|---|---|
| Calculates the absolute value of a number. |
|
| Constrains a number to be within a range. |
|
| Re-maps a number from one range to another. |
|
| Returns the greater of two values. |
|
| Returns the smaller of two values. |
|
| Raises a base to the power of an exponent. |
|
| Calculates the square of a number. |
|
| Calculates the square root of a number. |
|
Trigonometry
Method & Parameters | Description | Returns |
---|---|---|
| Calculates the cosine of an angle in radians. |
|
| Calculates the sine of an angle in radians. |
|
| Calculates the tangent of an angle in radians. |
|
Characters
Method & Parameters | Description | Returns |
---|---|---|
| Checks if the character is an alphabetic character. |
|
| Checks if the character is an alphanumeric character. |
|
| Checks if the character is a 7-bit ASCII character. |
|
| Checks if the character is a control character. |
|
| Checks if the character is a digit (0-9). |
|
| Checks if the character is a printable character, excluding space. |
|
| Checks if the character is a hexadecimal digit (0-9, A-F, a-f). |
|
| Checks if the character is a lowercase alphabetic character. |
|
| Checks if the character is a printable character, including space. |
|
| Checks if the character is a punctuation character. |
|
| Checks if the character is a whitespace character. |
|
| Checks if the character is an uppercase alphabetic character. |
|
| Checks if the character is a whitespace character according to method. |
|
Random Numbers
Method & Parameters | Description | Returns |
---|---|---|
| Generates a pseudo-random number between 0 and . |
|
| Seeds the random number generator. | Nothing |
Bits and Bytes
Method & Parameters | Description | Returns |
---|---|---|
| Gets the value of a specific bit. |
|
| Clears a specific bit. | Nothing |
| Reads the value of a specific bit. |
|
| Sets a specific bit. | Nothing |
| Writes a value to a specific bit. | Nothing |
| Returns the high byte of an . |
|
| Returns the low byte of an . |
|
External Interrupts
Method & Parameters | Description | Returns |
---|---|---|
| Attaches an interrupt to a specific pin. | Nothing |
| Detaches an interrupt from a specific pin. | Nothing |
Interrupts
Method & Parameters | Description | Returns |
---|---|---|
| Enables interrupts globally. | Nothing |
| Disables interrupts globally. | Nothing |
Stream
Method & Parameters | Description | Returns |
---|---|---|
| Returns the number of bytes available in the serial buffer. |
|
| Reads the next byte from the serial buffer. |
|
| Waits for the transmission of outgoing serial data to complete. | Nothing |
| Searches for a target string in the serial buffer. |
|
| Searches for a target string until a specified termination string is found. |
|
| Returns the next byte in the serial buffer without removing it. |
|
| Reads characters from the serial buffer into a buffer. |
|
| Reads characters from the serial buffer into a buffer until a terminator is found. |
|
| Reads characters from the serial buffer into a String until a newline character is found. |
|
| Reads characters from the serial buffer into a String until a specified terminator is found. |
|
| Reads characters from the serial buffer and converts them to an integer. |
|
| Reads characters from the serial buffer and converts them to a float. |
|
| Sets the maximum duration for , , , and . | Nothing |
Serial
Method & Parameters | Description | Returns |
---|---|---|
| Checks if the Serial object is available. |
|
| Returns the number of bytes available for reading. |
|
| Returns the number of bytes available for writing. |
|
| Initializes the Serial communication with the specified baud rate. |
|
| Ends the Serial communication. |
|
| Searches for a target string in the serial buffer. |
|
| Searches for a target string until a specified termination string is found. |
|
| Waits for the transmission of outgoing serial data to complete. |
|
| Reads characters from the serial buffer and converts them to a float. |
|
| Reads characters from the serial buffer and converts them to an integer. |
|
| Returns the next byte in the serial buffer without removing it. |
|
| Prints data to the serial port. |
|
| Prints data to the serial port followed by a newline character. |
|
| Reads the next byte from the serial buffer. |
|
| Reads characters from the serial buffer into a buffer. |
|
| Reads characters from the serial buffer into a buffer until a terminator is found. |
|
| Reads characters from the serial buffer into a String until a newline character is found. |
|
| Reads characters from the serial buffer into a String until a specified terminator is found. |
|
| Sets the maximum duration for , , , and . |
|
| Writes a byte to the serial port. |
|
| Called when data is available in the serial buffer. |
|
SPI
Method & Parameters | Description | Returns |
---|---|---|
| Creates an SPISettings object with the specified clock, bit order, and data mode. |
|
| Initializes the SPI library. |
|
| Begins an SPI transaction with the specified settings. |
|
| Ends the current SPI transaction. |
|
| Ends the SPI library. |
|
| Sets the bit order (MSBFIRST or LSBFIRST) for SPI communication. |
|
| Sets the clock divider for SPI communication. |
|
| Sets the data mode for SPI communication. |
|
| Transfers a byte over SPI. |
|
| Specifies which interrupt to use for SPI transactions. |
|
I2C (Wire)
Method & Parameters | Description | Returns |
---|---|---|
| Initializes the Wire library. |
|
| Ends the Wire library. |
|
| Requests data from a slave device with the specified address and quantity of bytes. |
|
| Begins a transmission to the slave device with the specified address. |
|
| Ends the transmission and returns the status. |
|
| Writes a byte to the I2C bus. |
|
| Returns the number of bytes available for reading. |
|
| Reads a byte from the I2C bus. |
|
| Sets the I2C clock frequency. |
|
| Sets a function to be called when data is received by the slave. |
|
| Sets a function to be called when the master requests data from the slave. |
|
| Sets the timeout for I2C operations. |
|
| Clears the timeout flag. |
|
| Returns the timeout flag status. |
|
Variables
Enums
Enum Type | Enumeration | Description |
---|---|---|
|
| Logical HIGH and LOW values ( and ). |
| / / / /
| Constants for specifying pin modes ( , , , , ). |
| Constant representing the built-in LED pin.* | |
| Boolean constants for true and false ( and ). |
Conversion
Method & Parameter | Description |
---|---|
| Type casting to unsigned int. |
| Type casting to unsigned long. |
| Type casting to byte. |
| Type casting to char. |
| Type casting to float. |
| Type casting to int. |
| Type casting to long. |
| Type casting to word. |
Data Types
Method & Parameter | Description |
---|---|
| Collection of variables of the same type. |
| Boolean data type. |
| Boolean data type (synonym for bool). |
| 8-bit unsigned data type. |
| 8-bit character data type. |
| Double-precision floating-point data type. |
| Single-precision floating-point data type. |
| Integer data type. |
| Long integer data type. |
| Short integer data type. |
| Unsigned integer data type. |
| Sequence of characters (not a primitive type). |
| String class in Arduino. |
| Unsigned 8-bit character data type. |
| Unsigned integer data type. |
| Unsigned long integer data type. |
| Represents the absence of a type. |
| 16-bit unsigned data type. |
Variable Scope & Qualifiers
Method & Parameter | Description |
---|---|
| Qualifier to define constants. |
| Not a specific keyword; refers to variable scope. |
| Qualifier to declare static variables. |
| Qualifier to declare volatile variables. |
Utilities
Method & Parameter | Description |
---|---|
| Qualifier to store data in program memory. |
| Operator to determine the size of a data type or variable. |
Structure
Sketch
Method & Parameter | Description |
---|---|
| Main function for continuous code execution. |
| Initialization function, called once at startup. |
Control Structure
Method & Parameter | Description |
---|---|
| Exits a loop or switch statement. |
| Skips the rest of a loop iteration. |
| Executes a block of code repeatedly while a specified condition is true. |
| Part of the if-else statement. |
| Creates a loop with a specified initialization, condition, and increment. |
| Transfers control to a labeled statement. |
| Conditional statement for decision-making. |
| Exits a function and optionally returns a value. |
| Multi-way branch statement. |
| Creates a loop with a specified condition. |
Further Syntax
Method & Parameter | Description |
---|---|
| Macro definition for code substitution. |
| Includes a file in the source code. |
| Block comment for multiple lines. |
| Single line comment. |
| Statement terminator. |
| Block of code, often used with control structures. |
Arithmetic Operators
Method & Parameter | Description |
---|---|
| Modulo operator for finding the remainder of a division. |
| Multiplication operator. |
| Addition operator. |
| Subtraction operator. |
| Division operator. |
| Assignment operator. |
Comparison Operators
Method & Parameter | Description |
---|---|
| Checks if two values are not equal. |
| Checks if the left value is less than the right value. |
| Checks if the left value is less than or equal to the right value. |
| Checks if two values are equal. |
| Checks if the left value is greater than the right value. |
| Checks if the left value is greater than or equal to the right value. |
Boolean Operators
Method & Parameter | Description |
---|---|
| Inverts the logical value, true becomes false and vice versa. |
| Logical AND operator, returns true if both operands are true. |
| Logical OR operator, returns true if at least one operand is true. |
Pointer Access Operators
Method & Parameter | Description |
---|---|
| Returns the memory address of a variable. |
| Accesses the value pointed to by a pointer. |
Bitwise Operators
Method & Parameter | Description |
---|---|
| Performs bitwise AND operation. |
| Shifts bits to the left. |
| Shifts bits to the right. |
| Performs bitwise XOR (exclusive OR) operation. |
| Performs bitwise OR operation. |
| Inverts all bits. |
Compound Operators
Method & Parameter | Description |
---|---|
| Performs a modulo operation and assigns the result to the left operand. |
| Performs a bitwise AND operation and assigns the result to the left operand. |
| Multiplies the left operand by the right operand and assigns the result to the left operand. |
| Increments the value of the operand by 1. |
| Adds the right operand to the left operand and assigns the result to the left operand. |
| Decrements the value of the operand by 1. |
| Subtracts the right operand from the left operand and assigns the result to the left operand. |
| Divides the left operand by the right operand and assigns the result to the left operand. |
| Performs a bitwise XOR operation and assigns the result to the left operand. |
| Performs a bitwise OR operation and assigns the result to the left operand. |
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.