gavmac00/arduino-docs huggingface dataset:
delay(500);
  }
}
Notes and Warnings
Please note that variables must be either globally defined, OR defined with the static keyword, in order to work with PROGMEM.
The following code will NOT work when inside a function:
const char long_str[] PROGMEM = "Hi, I would like to tell you a bit about myself.\n";
The following code WILL work, even if locally defined within a function:
const static char long_str[] PROGMEM = "Hi, I would like to tell you a bit about myself.\n"
The F() macro
When an instruction like :
Serial.print("Write something on  the Serial Monitor");
is used, the string to be printed is normally saved in RAM. If your sketch prints a lot of stuff on the Serial Monitor, you can easily fill the RAM. If you have free FLASH memory space, you can easily indicate that the string must be saved in FLASH using the syntax:
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Variables
            >  Utilities
            > Sizeof
          
sizeof()
          [Utilities]
          
Description
The sizeof operator returns the number of bytes in a variable type, or the number of bytes occupied by an array.
Syntax
sizeof(variable)
Parameters
Syntax
sizeof(variable)
Parameters
variable: The thing to get the size of. Allowed data types: any variable type or array (e.g. int, float, byte).
Returns
The number of bytes in a variable or bytes occupied in an array. Data type: size_t.
Example Code
The sizeof operator is useful for dealing with arrays (such as strings) where it is convenient to be able to change the size of the array without breaking other parts of the program.
This program prints out a text string one character at a time. Try changing the text phrase.
char myStr[] = "this is a test";
void setup() {
  Serial.begin(9600);
}
void loop() {
  for (byte i = 0; i < sizeof(myStr) - 1; i++) {
    Serial.print(i, DEC);
    Serial.print(" = ");
    Serial.write(myStr[i]);
Serial.print(" = ");
    Serial.write(myStr[i]);
    Serial.println();
  }
  delay(5000);  // slow down the program
}
Notes and Warnings
Note that sizeof returns the total number of bytes. So for arrays of larger variable types such as ints, the for loop would look something like this.
int myValues[] = {123, 456, 789};
// this for loop works correctly with an array of any type or size
for (byte i = 0; i < (sizeof(myValues) / sizeof(myValues[0])); i++) {
  // do something with myValues[i]
}
Note that a properly formatted string ends with the NULL symbol, which has ASCII value 0.
See also
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Variables
            >  Constants
            > Integerconstants
          
Integer Constants
          [Constants]
          
Description
Integer constants are numbers that are used directly in a sketch, like 123. By default, these numbers are treated as int but you can change this with the U and L modifiers (see below).
Normally, integer constants are treated as base 10 (decimal) integers, but special notation (formatters) may be used to enter numbers in other bases.
Base
Example
Formatter
Comment
10 (decimal)
123
none
2 (binary)
0b1111011
leading "0b"
characters 0&1 valid
8 (octal)
0173
leading "0"
characters 0-7 valid
16 (hexadecimal)
0x7B
leading "0x"
characters 0-9, A-F, a-f valid
Decimal (base 10)
This is the common-sense math with which you are acquainted. Constants without other prefixes are assumed to be in decimal format.
Example  Code:
n = 101;  // same as 101 decimal ((1 * 10^2) + (0 * 10^1) + 1)
Binary (base 2)
Only the characters 0 and 1 are valid.
Example  Code:
n = 0b101; // same as 5 decimal ((1 * 2^2) + (0 * 2^1) + 1)
Octal (base 8)
Only the characters 0 through 7 are valid. Octal values are indicated by the prefix "0" (zero).
Example  Code:
n = 0101; // same as 65 decimal ((1 * 8^2) + (0 * 8^1) + 1)
It is possible to generate a hard-to-find bug by (unintentionally) including a leading zero before a constant and having the compiler unintentionally interpret your constant as octal.
Hexadecimal (base 16)
Hexadecimal (base 16)
Valid characters are 0 through 9 and letters A through F; A has the value 10, B is 11, up to F, which is 15. Hex values are indicated by the prefix "0x". Note that A-F may be upper (A-F) or lower case (a-f).
Example  Code:
n = 0x101;  // same as 257 decimal ((1 * 16^2) + (0 * 16^1) + 1)
Notes and Warnings
U & L formatters:
By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with:
a 'u' or 'U' to force the constant into an unsigned data format. Example: 33u
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Variables
            >  Constants
            > Constants
          
constants
          [Constants]
          
Description
Constants are predefined expressions in the Arduino language. They are used to make the programs easier to read. We classify constants in groups:
Defining Logical Levels: true and false (Boolean Constants)
Defining Logical Levels: true and false (Boolean Constants)
There are two constants used to represent truth and falsity in the Arduino language: true, and false.
false
false is the easier of the two to define. false is defined as 0 (zero).
true
true is often said to be defined as 1, which is correct, but true has a wider definition. Any integer which is non-zero is true, in a Boolean sense. So -1, 2 and -200 are all defined as true, too, in a Boolean sense.
Note that the true and false constants are typed in lowercase unlike HIGH, LOW, INPUT, and OUTPUT.
Defining Pin Levels: HIGH and LOW
When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to: HIGH and LOW.
HIGH
HIGH
The meaning of HIGH (in reference to a pin) is somewhat different depending on whether a pin is set to an INPUT or OUTPUT. When a pin is configured as an INPUT with pinMode(), and read with digitalRead(), the Arduino (ATmega) will report HIGH if:
a voltage greater than 3.0V is present at the pin (5V boards)
a voltage greater than 2.0V is present at the pin (3.3V boards)
A pin may also be configured as an INPUT with pinMode(), and subsequently made HIGH with digitalWrite(). This will enable the internal 20K pullup resistors, which will pull up the input pin to a HIGH reading unless it is pulled LOW by external circuitry. This can be done alternatively by passing INPUT_PULLUP as argument to the pinMode() function, as explained in more detail in the section "Defining Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT" further below.
When a pin is configured to OUTPUT with pinMode(), and set to HIGH with digitalWrite(), the pin is at:
5 volts (5V boards)
3.3 volts (3.3V boards)
In this state it can source current, e.g. light an LED that is connected through a series resistor to ground.
LOW
The meaning of LOW also has a different meaning depending on whether a pin is set to INPUT or OUTPUT. When a pin is configured as an INPUT with pinMode(), and read with digitalRead(), the Arduino (ATmega) will report LOW if:
a voltage less than 1.5V is present at the pin (5V boards)
a voltage less than 1.0V (Approx) is present at the pin (3.3V boards)
When a pin is configured to OUTPUT with pinMode(), and set to LOW with digitalWrite(), the pin is at 0 volts (both 5V and 3.3V boards). In this state it can sink current, e.g. light an LED that is connected through a series resistor to +5 volts (or +3.3 volts).
Defining Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT
Digital pins can be used as INPUT, INPUT_PULLUP, or OUTPUT. Changing a pin with pinMode() changes the electrical behavior of the pin.
Pins Configured as INPUT
Arduino (ATmega) pins configured as INPUT with pinMode() are said to be in a high-impedance state. Pins configured as INPUT make extremely small demands on the circuit that they are sampling, equivalent to a series resistor of 100 Megohms in front of the pin. This makes them useful for reading a sensor.
If you have your pin configured as an INPUT, and are reading a switch, when the switch is in the open state the input pin will be "floating", resulting in unpredictable results. In order to assure a proper reading when the switch is open, a pull-up or pull-down resistor must be used. The purpose of this resistor is to pull the pin to a known state when the switch is open. A 10 K ohm resistor is usually chosen, as it is a low enough value to reliably prevent a floating input, and at the same time a high enough value to not draw too much current when the switch is closed. See the Digital Read Serial tutorial for more information.
If a pull-down resistor is used, the input pin will be LOW when the switch is open and HIGH when the switch is closed.
If a pull-up resistor is used, the input pin will be HIGH when the switch is open and LOW when the switch is closed.
Pins Configured as INPUT_PULLUP
The ATmega microcontroller on the Arduino has internal pull-up resistors (resistors that connect to power internally) that you can access. If you prefer to use these instead of external pull-up resistors, you can use the INPUT_PULLUP argument in pinMode().
See the Input Pullup Serial tutorial for an example of this in use.
Pins configured as inputs with either INPUT or INPUT_PULLUP can be damaged or destroyed if they are connected to voltages below ground (negative voltages) or above the positive power rail (5V or 3V).
Pins Configured as OUTPUT
Pins Configured as OUTPUT
Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. ATmega pins can source (provide current) or sink (absorb current) up to 40 mA (milliamps) of current to other devices/circuits. This makes them useful for powering LEDs because LEDs typically use less than 40 mA. Loads greater than 40 mA (e.g. motors) will require a transistor or other interface circuitry.
Pins configured as outputs can be damaged or destroyed if they are connected to either the ground or positive power rails.
Defining built-ins: LED_BUILTIN
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Variables
            >  Constants
            > Floatingpointconstants
          
Floating Point Constants
          [Constants]
          
Description
Similar to integer constants, floating point constants are used to make code more readable. Floating point constants are swapped at compile time for the value to which the expression evaluates.
Example Code
Example Code
float n = 0.005;  // 0.005 is a floating point constant
Notes and Warnings
Floating point constants can also be expressed in a variety of scientific notation. 'E' and 'e' are both accepted as valid exponent indicators.
floating-point constant
evaluates to:
also evaluates to:
10.0
10
2.34E5
2.34 * 10^5
234000
67e-12
67.0 * 10^-12
0.000000000067
See also
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Digital io
            > Digitalread
          
digitalRead()
          [Digital I/O]
          
Description
Reads the value from a specified digital pin, either HIGH or LOW.
Syntax
digitalRead(pin)
Parameters
pin: the Arduino pin number you want to read
Returns
HIGH or LOW
Example Code
pin: the Arduino pin number you want to read
Returns
HIGH or LOW
Example Code
Sets pin 13 to the same value as pin 7, declared as an input.
int ledPin = 13;  // LED connected to digital pin 13
int inPin = 7;    // pushbutton connected to digital pin 7
int val = 0;      // variable to store the read value
void setup() {
  pinMode(ledPin, OUTPUT);  // sets the digital pin 13 as output
  pinMode(inPin, INPUT);    // sets the digital pin 7 as input
}
void loop() {
  val = digitalRead(inPin);   // read the input pin
  digitalWrite(ledPin, val);  // sets the LED to the button's value
}
Notes and Warnings
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Digital io
            > Digitalwrite
          
digitalWrite()
          [Digital I/O]
          
Description
Write a HIGH or a LOW value to a digital pin.
Description
Write a HIGH or a LOW value to a digital pin.
If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.
If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor. See the Digital Pins tutorial for more information.
If you do not set the pinMode() to OUTPUT, and connect an LED to a pin, when calling digitalWrite(HIGH), the LED may appear dim. Without explicitly setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor.
Syntax
digitalWrite(pin, value)
Parameters
Syntax
digitalWrite(pin, value)
Parameters
pin: the Arduino pin number.
value: HIGH or LOW.
Returns
Nothing
Example Code
The code makes the digital pin 13 an OUTPUT and toggles it by alternating between HIGH and LOW at one second pace.
void setup() {
  pinMode(13, OUTPUT);    // sets the digital pin 13 as output
}
void loop() {
  digitalWrite(13, HIGH); // sets the digital pin 13 on
  delay(1000);            // waits for a second
  digitalWrite(13, LOW);  // sets the digital pin 13 off
  delay(1000);            // waits for a second
}
Notes and Warnings
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Digital io
            > Pinmode
          
pinMode()
          [Digital I/O]
          
Description
Configures the specified pin to behave either as an input or an output. See the Digital Pins page for details on the functionality of the pins.
As of Arduino 1.0.1, it is possible to enable the internal pullup resistors with the mode INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pullups.
Syntax
pinMode(pin, mode)
Parameters
pin: the Arduino pin number to set the mode of.
mode: INPUT, OUTPUT, or INPUT_PULLUP. See the Digital Pins page for a more complete description of the functionality.
Returns
Nothing
Example Code
The code makes the digital pin 13 OUTPUT and Toggles it HIGH and LOW
void setup() {
  pinMode(13, OUTPUT);    // sets the digital pin 13 as output
}
void loop() {
  digitalWrite(13, HIGH); // sets the digital pin 13 on
  delay(1000);            // waits for a second
  digitalWrite(13, LOW);  // sets the digital pin 13 off
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Bits and bytes
            > Highbyte
          
highByte()
          [Bits and Bytes]
          
Description
Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type).
Syntax
highByte(x)
Parameters
x: a value of any type
Returns
Data type: byte.
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Bits and bytes
            > Bitread
          
bitRead()
          [Bits and Bytes]
          
Description
Reads a bit of a number.
Syntax
bitRead(x, n)
Parameters
x: the number from which to read.
n: which bit to read, starting at 0 for the least-significant (rightmost) bit.
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Bits and bytes
            > Bitwrite
          
bitWrite()
          [Bits and Bytes]
          
Description
Writes a bit of a numeric variable.
Syntax
bitWrite(x, n, b)
Parameters
x: the numeric variable to which to write.
Parameters
x: the numeric variable to which to write.
n: which bit of the number to write, starting at 0 for the least-significant (rightmost) bit.
b: the value to write to the bit (0 or 1).
Returns
Nothing
Example Code
Demonstrates the use of bitWrite by printing the value of a variable to the Serial Monitor before and after the use of bitWrite().
void setup() {
  Serial.begin(9600);
  while (!Serial) {}  // wait for serial port to connect. Needed for native USB port only
  byte x = 0b10000000;  // the 0b prefix indicates a binary constant
  Serial.println(x, BIN); // 10000000
  bitWrite(x, 0, 1);  // write 1 to the least significant bit of x
  Serial.println(x, BIN); // 10000001
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Bits and bytes
            > Lowbyte
          
lowByte()
          [Bits and Bytes]
          
Description
Extracts the low-order (rightmost) byte of a variable (e.g. a word).
Syntax
lowByte(x)
Parameters
x: a value of any type
Returns
Data type: byte.
See also
LANGUAGE word()
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Bits and bytes
            > Bitset
          
bitSet()
          [Bits and Bytes]
          
Description
Sets (writes a 1 to) a bit of a numeric variable.
Syntax
bitSet(x, n)
Parameters
x: the numeric variable whose bit to set.
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Bits and bytes
            > Bitclear
          
bitClear()
          [Bits and Bytes]
          
Description
Clears (writes a 0 to) a bit of a numeric variable.
Syntax
bitClear(x, n)
Parameters
x: the numeric variable whose bit to clear.
bitClear(x, n)
Parameters
x: the numeric variable whose bit to clear.
n: which bit to clear, starting at 0 for the least-significant (rightmost) bit.
Returns
x: the value of the numeric variable after the bit at position n is cleared.
Example Code
Prints the output of bitClear(x,n) on two given integers. The binary representation of 6 is 0110, so when n=1, the second bit from the right is set to 0. After this we are left with 0100 in binary, so 4 is returned.
void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  int x = 6;
  int n = 1;
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Bits and bytes
            > Bit
          
bit()
          [Bits and Bytes]
          
Description
Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.).
Syntax
bit(n)
Parameters
n: the bit whose value to compute
Returns
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Communication
            > Wire
          
Wire
          [Communication]
          
Description
> Wire
          
Wire
          [Communication]
          
Description
This library allows you to communicate with I2C/TWI devices. On the Arduino boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. The Arduino Due has two I2C/TWI interfaces SDA1 and SCL1 are near to the AREF pin and the additional one is on pins 20 and 21.
As a reference the table below shows where TWI pins are located on various Arduino boards.
Board
I2C/TWI pins
UNO, Ethernet
A4 (SDA), A5 (SCL)
Mega2560
20 (SDA), 21 (SCL)
Leonardo
20 (SDA), 21 (SCL), SDA1, SCL1
20 (SDA), 21 (SCL), SDA1, SCL1
As of Arduino 1.0, the library inherits from the Stream functions, making it consistent with other read/write libraries. Because of this, send() and receive() have been replaced with read() and write().
Recent versions of the Wire library can use timeouts to prevent a lockup in the face of certain problems on the bus, but this is not enabled by default (yet) in current versions. It is recommended to always enable these timeouts when using the Wire library. See the Wire.setWireTimeout function for more details.
Note: There are both 7 and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it’s being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8-bit address, you’ll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127. However the addresses from 0 to 7 are not used because are reserved so the first address that can be used is 8. Please note that a pull-up resistor is needed when connecting SDA/SCL pins. Please refer to the examples for more information. MEGA 2560 board has pull-up resistors on pins 20 and 21 onboard.
The Wire library implementation uses a 32 byte buffer, therefore any communication should be within this limit. Exceeding bytes in a single transmission will just be dropped.
To use this library:
#include <Wire.h>
Functions
begin()
end()
requestFrom()
beginTransmission()
endTransmission()
write()
available()
read()
setClock()
onReceive()
onRequest()
setWireTimeout()
clearWireTimeoutFlag()
getWireTimeoutFlag()
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Communication
            > Spi
          
SPI
          [Communication]
          
Description
This library allows you to communicate with SPI devices, with the Arduino as the controller device. This library is bundled with every Arduino platform (avr, megaavr, mbed, samd, sam, arc32), so you do not need to install the library separately.
To use this library
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Communication
            > Stream
          
Stream
          [Communication]
          
Description
Stream is the base class for character and binary based streams. It is not called directly, but invoked whenever you use a function that relies on it.
Stream defines the reading functions in Arduino. When using any core functionality that uses a read() or similar method, you can safely assume it calls on the Stream class. For functions like print(), Stream inherits from the Print class.
Some of the libraries that rely on Stream include :
Serial
Wire
Ethernet
SD
Functions
available()
read()
flush()
find()
findUntil()
peek()
readBytes()
readBytesUntil()
readString()
readStringUntil()
parseInt()
parseFloat()
setTimeout()
See also
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Communication
            > Serial
          
Serial
          [Communication]
          
Description
Used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port (also known as a UART or USART), and some have several.
Board
USB CDC name
Serial pins
Serial1 pins
Serial2 pins
Serial3 pins
USB CDC name
Serial pins
Serial1 pins
Serial2 pins
Serial3 pins
Uno, Nano, Mini
0(RX), 1(TX)
Mega
0(RX), 1(TX)
19(RX), 18(TX)
17(RX), 16(TX)
15(RX), 14(TX)
Leonardo, Micro, Yún
Serial
0(RX), 1(TX)
Uno WiFi Rev.2
Connected to USB
0(RX), 1(TX)
Connected to NINA
MKR boards
Serial
13(RX), 14(TX)
Zero
SerialUSB (Native USB Port only)
Connected to Programming Port
0(RX), 1(TX)
Due
SerialUSB (Native USB Port only)
0(RX), 1(TX)
19(RX), 18(TX)
0(RX), 1(TX)
19(RX), 18(TX)
17(RX), 16(TX)
15(RX), 14(TX)
101
Serial
0(RX), 1(TX)
On Uno, Nano, Mini, and Mega, pins 0 and 1 are used for communication with the computer. Connecting anything to these pins can interfere with that communication, including causing failed uploads to the board.
You can use the Arduino environment’s built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin().
Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board). Don’t connect these pins directly to an RS232 serial port; they operate at +/- 12V and can damage your Arduino board.
To use these extra serial ports to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega’s USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device’s RX pin, the RX to your device’s TX pin, and the ground of your Mega to your device’s ground.
Functions
if(Serial)
available()
availableForWrite()
begin()
end()
find()
findUntil()
flush()
parseFloat()
parseInt()
peek()
print()
println()
read()
readBytes()
readBytesUntil()
readString()
readStringUntil()
setTimeout()
write()
serialEvent()
See also
EXAMPLE ReadASCIIString
EXAMPLE ASCII TAble
EXAMPLE Dimmer
EXAMPLE Graph
EXAMPLE Physical Pixel
EXAMPLE Serial Call Response
EXAMPLE Serial Call Response ASCII
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Usb
            > Keyboard
          
Keyboard
          [USB]
          
Description
The keyboard functions enable 32u4 or SAMD micro based boards to send keystrokes to an attached computer through their micro’s native USB port.
Note: Not every possible ASCII character, particularly the non-printing ones, can be sent with the Keyboard library.
The library supports the use of modifier keys. Modifier keys change the behavior of another key when pressed simultaneously. See here for additional information on supported keys and their use.
Notes and Warnings
These core libraries allow the 32u4 and SAMD based boards (Leonardo, Esplora, Zero, Due and MKR Family) to appear as a native Mouse and/or Keyboard to a connected computer.
A word of caution on using the Mouse and Keyboard libraries: if the Mouse or Keyboard library is constantly running, it will be difficult to program your board. Functions such as Mouse.move() and Keyboard.print() will move your cursor or send keystrokes to a connected computer and should only be called when you are ready to handle them. It is recommended to use a control system to turn this functionality on, like a physical switch or only responding to specific input you can control. Refer to the Mouse and Keyboard examples for some ways to handle this.
When using the Mouse or Keyboard library, it may be best to test your output first using Serial.print(). This way, you can be sure you know what values are being reported.
Functions
Keyboard.begin()
Keyboard.end()
Keyboard.press()
Keyboard.print()
Keyboard.println()
Keyboard.release()
Keyboard.releaseAll()
Keyboard.write()
See also
EXAMPLE KeyboardAndMouseControl: Demonstrates the Mouse and Keyboard commands in one program.
EXAMPLE KeyboardMessage: Sends a text string when a button is pressed.
EXAMPLE KeyboardLogout: Logs out the current user with key commands
EXAMPLE KeyboardSerial: Reads a byte from the serial port, and sends back a keystroke.
EXAMPLE KeyboardReprogram: opens a new window in the Arduino IDE and reprograms the board with a simple blink program
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Usb
            > Mouse
          
Mouse
          [USB]
          
Description
The mouse functions enable 32u4 or SAMD micro based boards to control cursor movement on a connected computer through their micro’s native USB port. When updating the cursor position, it is always relative to the cursor’s previous location.
Notes and Warnings
Notes and Warnings
These core libraries allow the 32u4 and SAMD based boards (Leonardo, Esplora, Zero, Due and MKR Family) to appear as a native Mouse and/or Keyboard to a connected computer.
A word of caution on using the Mouse and Keyboard libraries: if the Mouse or Keyboard library is constantly running, it will be difficult to program your board. Functions such as Mouse.move() and Keyboard.print() will move your cursor or send keystrokes to a connected computer and should only be called when you are ready to handle them. It is recommended to use a control system to turn this functionality on, like a physical switch or only responding to specific input you can control. Refer to the Mouse and Keyboard examples for some ways to handle this.
When using the Mouse or Keyboard library, it may be best to test your output first using Serial.print(). This way, you can be sure you know what values are being reported.
Functions
Functions
Mouse.begin()
Mouse.click()
Mouse.end()
Mouse.move()
Mouse.press()
Mouse.release()
Mouse.isPressed()
See also
EXAMPLE KeyboardAndMouseControl: Demonstrates the Mouse and Keyboard commands in one program.
EXAMPLE ButtonMouseControl: Control cursor movement with 5 pushbuttons.
EXAMPLE JoystickMouseControl: Controls a computer’s cursor movement with a Joystick when a button is pressed.
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  External interrupts
            > Detachinterrupt
          
detachInterrupt()
          [External Interrupts]
          
Description
Turns off the given interrupt.
Syntax
detachInterrupt(digitalPinToInterrupt(pin)) (recommended)
detachInterrupt(interrupt) (not recommended)
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  External interrupts
            > Attachinterrupt
          
attachInterrupt()
          [External Interrupts]
          
Description
Digital Pins With Interrupts
[External Interrupts]
          
Description
Digital Pins With Interrupts
The first parameter to attachInterrupt() is an interrupt number. Normally you should use digitalPinToInterrupt(pin) to translate the actual digital pin to the specific interrupt number. For example, if you connect to pin 3, use digitalPinToInterrupt(3) as the first parameter to attachInterrupt().
Board
Digital Pins Usable For Interrupts
Uno, Nano, Mini, other 328-based
2, 3
Uno WiFi Rev.2, Nano Every
all digital pins
Mega, Mega2560, MegaADK
2, 3, 18, 19, 20, 21 (pins 20 & 21 are not available to use for interrupts while they are used for I2C communication)
Micro, Leonardo, other 32u4-based
0, 1, 2, 3, 7
Zero
0, 1, 2, 3, 7
Zero
all digital pins, except 4
MKR Family boards
0, 1, 4, 5, 6, 7, 8, 9, A1, A2
Nano 33 IoT
2, 3, 9, 10, 11, 13, A1, A5, A7
Nano 33 BLE, Nano 33 BLE Sense
all pins
Due
all digital pins
101
all digital pins (Only pins 2, 5, 7, 8, 10, 11, 12, 13 work with CHANGE)
Notes and Warnings
Note
Notes and Warnings
Note
Inside the attached function, delay() won’t work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function. See the section on ISRs below for more information.
Using Interrupts
Interrupts are useful for making things happen automatically in microcontroller programs and can help solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder, or monitoring user input.
If you wanted to ensure that a program always caught the pulses from a rotary encoder, so that it never misses a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor that is trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the input.
About Interrupt Service Routines
ISRs are special kinds of functions that have some unique limitations most other functions do not have. An ISR cannot have any parameters, and they shouldn’t return anything.
Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be executed after the current one finishes in an order that depends on the priority they have. millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if called inside an ISR. micros() works initially but will start behaving erratically after 1-2 ms. delayMicroseconds() does not use any counter, so it will work as normal.
Typically global variables are used to pass data between an ISR and the main program. To make sure variables shared between an ISR and the main program are updated correctly, declare them as volatile.
For more information on interrupts, see Nick Gammon’s notes.
Syntax
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) (recommended)
Syntax
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) (recommended)
attachInterrupt(interrupt, ISR, mode) (not recommended)
attachInterrupt(pin, ISR, mode) (Not recommended. Additionally, this syntax only works on Arduino SAMD Boards, Uno WiFi Rev2, Due, and 101.)
Parameters
interrupt: the number of the interrupt. Allowed data types: int.
pin: the Arduino pin number.
ISR: the ISR to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an interrupt service routine.
mode: defines when the interrupt should be triggered. Four constants are predefined as valid values:
LOW to trigger the interrupt whenever the pin is low,
CHANGE to trigger the interrupt whenever the pin changes value
RISING to trigger when the pin goes from low to high,
FALLING for when the pin goes from high to low.
FALLING for when the pin goes from high to low.
The Due, Zero and MKR1000 boards allow also:
HIGH to trigger the interrupt whenever the pin is high.
Returns
Nothing
Example Code
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}
void loop() {
  digitalWrite(ledPin, state);
}
void blink() {
  state = !state;
}
Interrupt Numbers
}
void blink() {
  state = !state;
}
Interrupt Numbers
Normally you should use digitalPinToInterrupt(pin), rather than place an interrupt number directly into your sketch. The specific pins with interrupts and their mapping to interrupt number varies for each type of board. Direct use of interrupt numbers may seem simple, but it can cause compatibility trouble when your sketch runs on a different board.
However, older sketches often have direct interrupt numbers. Often number 0 (for digital pin 2) or number 1 (for digital pin 3) were used. The table below shows the available interrupt pins on various boards.
Note that in the table below, the interrupt numbers refer to the number to be passed to attachInterrupt(). For historical reasons, this numbering does not always correspond directly to the interrupt numbering on the ATmega chip (e.g. int.0 corresponds to INT4 on the ATmega2560 chip).
Board
int.0
Board
int.0
int.1
int.2
int.3
int.4
int.5
Uno, Ethernet
2
3
Mega2560
2
3
21
20
19
18
32u4 based (e.g Leonardo, Micro)
3
2
0
1
7
For Uno WiFiRev.2, Due, Zero, MKR Family and 101 boards the interrupt number = pin number.
See also
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Analog io
            > Analogreference
          
analogReference()
          [Analog I/O]
          
Description
Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are:
Arduino AVR Boards (Uno, Mega, Leonardo, etc.)
Arduino AVR Boards (Uno, Mega, Leonardo, etc.)
DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
INTERNAL: a built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328P and 2.56 volts on the ATmega32U4 and ATmega8 (not available on the Arduino Mega)
INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
Arduino SAMD Boards (Zero, etc.)
AR_DEFAULT: the default analog reference of 3.3V
AR_INTERNAL: a built-in 2.23V reference
AR_INTERNAL: a built-in 2.23V reference
AR_INTERNAL1V0: a built-in 1.0V reference
AR_INTERNAL1V65: a built-in 1.65V reference
AR_INTERNAL2V23: a built-in 2.23V reference
AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference
Arduino megaAVR Boards (Uno WiFi Rev2)
DEFAULT: a built-in 0.55V reference
INTERNAL: a built-in 0.55V reference
VDD: Vdd of the ATmega4809. 5V on the Uno WiFi Rev2
INTERNAL0V55: a built-in 0.55V reference
INTERNAL1V1: a built-in 1.1V reference
INTERNAL1V5: a built-in 1.5V reference
INTERNAL2V5: a built-in 2.5V reference
INTERNAL2V5: a built-in 2.5V reference
INTERNAL4V3: a built-in 4.3V reference
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference
Arduino SAM Boards (Due)
AR_DEFAULT: the default analog reference of 3.3V. This is the only supported option for the Due.
Arduino Mbed OS Nano Boards (Nano 33 BLE), Arduino Mbed OS Edge Boards (Edge Control)
AR_VDD: the default 3.3 V reference
AR_INTERNAL: built-in 0.6 V reference
AR_INTERNAL1V2: 1.2 V reference (internal 0.6 V reference with 2x gain)
AR_INTERNAL2V4: 2.4 V reference (internal 0.6 V reference with 4x gain)
Syntax
analogReference(type)
Parameters
Syntax
analogReference(type)
Parameters
type: which type of reference to use (see list of options in the description).
Returns
Nothing
Notes and Warnings
After changing the analog reference, the first few readings from analogRead() may not be accurate.
Don’t use anything less than 0V or more than 5V for external reference voltage on the AREF pin! If you’re using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead(). Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board.
Alternatively, you can connect the external reference voltage to the AREF pin through a 5K resistor, allowing you to switch between external and internal reference voltages. Note that the resistor will alter the voltage that gets used as the reference because there is an internal 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield 2.5 * 32 / (32 + 5) = ~2.2V at the AREF pin.
See also
EXAMPLE Description of the analog input pins
Language
functions
variables
structure
Libraries
IoT Cloud API
Glossary
        The Arduino Reference text is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    
    Find anything that can be improved? Suggest corrections and new documentation via GitHub.
    Doubts on how to use Github? Learn everything you need to know in this tutorial.
    
Last Revision: Searching...
Last Build: 2023/06/30 
Edit This Page
Reference
            >  Language
            >  Functions
            >  Analog io
            > Analogwrite
          
analogWrite()
          [Analog I/O]
          
Description
analogWrite()
          [Analog I/O]
          
Description
Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady rectangular wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite()) on the same pin.
Board
PWM Pins
PWM Frequency
Uno, Nano, Mini
3, 5, 6, 9, 10, 11
490 Hz (pins 5 and 6: 980 Hz)
Mega
2 - 13, 44 - 46
490 Hz (pins 4 and 13: 980 Hz)
Leonardo, Micro, Yún
3, 5, 6, 9, 10, 11, 13