gavmac00/arduino-docs huggingface dataset:
3, 5, 6, 9, 10, 11, 13
490 Hz (pins 3 and 11: 980 Hz)
Uno WiFi Rev2, Nano Every
3, 5, 6, 9, 10
976 Hz
MKR boards *
0 - 8, 10, A3, A4
732 Hz
MKR1000 WiFi *
0 - 8, 10, 11, A3, A4
732 Hz
Zero *
3 - 13, A0, A1
732 Hz
Nano 33 IoT *
2, 3, 5, 6, 9 - 12, A2, A3, A5
732 Hz
Nano 33 BLE/BLE Sense
1 - 13, A0 - A7
500 Hz
Due **
2-13
1000 Hz
101
500 Hz
Due **
2-13
1000 Hz
101
3, 5, 6, 9
pins 3 and 9: 490 Hz, pins 5 and 6: 980 Hz
* In addition to PWM capabilities on the pins noted above, the MKR, Nano 33 IoT, and Zero boards have true analog output when using analogWrite() on the DAC0 (A0) pin.
** In addition to PWM capabilities on the pins noted above, the Due has true analog output when using analogWrite() on pins DAC0 and DAC1.
You do not need to call pinMode() to set the pin as an output before calling analogWrite().
The analogWrite function has nothing to do with the analog pins or the analogRead function.
Syntax
analogWrite(pin, value)
Parameters
pin: the Arduino pin to write to. Allowed data types: int.
Parameters
pin: the Arduino pin to write to. Allowed data types: int.
value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int.
Returns
Nothing
Example Code
Sets the output to the LED proportional to the value read from the potentiometer.
int ledPin = 9;      // LED connected to digital pin 9
int analogPin = 3;   // potentiometer connected to analog pin 3
int val = 0;         // variable to store the read value
void setup() {
  pinMode(ledPin, OUTPUT);  // sets the pin as output
}
void loop() {
  val = analogRead(analogPin);  // read the input pin
  analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}
Notes and Warnings
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g. 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.
See also
LANGUAGE analogWriteResolution()
DEFINITION PWM
EXAMPLE Blink
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
            > Analogread
          
analogRead()
          [Analog I/O]
          
Description
analogRead()
          [Analog I/O]
          
Description
Reads the value from the specified analog pin. Arduino boards contain a multichannel, 10-bit analog to digital converter. This means that it will map input voltages between 0 and the operating voltage(5V or 3.3V) into integer values between 0 and 1023. On an Arduino UNO, for example, this yields a resolution between readings of: 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit. See the table below for the usable pins, operating voltage and maximum resolution for some Arduino boards.
The input range can be changed using analogReference(), while the resolution can be changed (only for Zero, Due and MKR boards) using analogReadResolution().
On ATmega based boards (UNO, Nano, Mini, Mega), it takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.
Board
Operating voltage
Usable pins
Max resolution
Uno
5 Volts
A0 to A5
10 bits
Mini, Nano
5 Volts
A0 to A7
10 bits
Mega, Mega2560, MegaADK
5 Volts
A0 to A14
10 bits
Micro
5 Volts
A0 to A11*
10 bits
Leonardo
5 Volts
A0 to A11*
10 bits
Zero
3.3 Volts
A0 to A5
12 bits**
Due
3.3 Volts
A0 to A11
12 bits**
MKR Family boards
3.3 Volts
12 bits**
MKR Family boards
3.3 Volts
A0 to A6
12 bits**
*A0 through A5 are labelled on the board, A6 through A11 are respectively available on pins 4, 6, 8, 9, 10, and 12
**The default analogRead() resolution for these boards is 10 bits, for compatibility. You need to use analogReadResolution() to change it to 12 bits.
Syntax
analogRead(pin)
Parameters
pin: the name of the analog input pin to read from (A0 to A5 on most boards, A0 to A6 on MKR boards, A0 to A7 on the Mini and Nano, A0 to A15 on the Mega).
Returns
Returns
The analog reading on the pin. Although it is limited to the resolution of the analog to digital converter (0-1023 for 10 bits or 0-4095 for 12 bits). Data type: int.
Example Code
The code reads the voltage on analogPin and displays it.
int analogPin = A3; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read
void setup() {
  Serial.begin(9600);           //  setup serial
}
void loop() {
  val = analogRead(analogPin);  // read the input pin
  Serial.println(val);          // debug 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
            >  Advanced io
            > Tone
          
tone()
          [Advanced I/O]
          
Description
> Tone
          
tone()
          [Advanced I/O]
          
Description
Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to noTone(). The pin can be connected to a piezo buzzer or other speaker to play tones.
Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect. If the tone is playing on the same pin, the call will set its frequency.
Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega).
It is not possible to generate tones lower than 31Hz. For technical details, see Brett Hagman’s notes.
Syntax
tone(pin, frequency)
tone(pin, frequency, duration)
Parameters
Syntax
tone(pin, frequency)
tone(pin, frequency, duration)
Parameters
pin: the Arduino pin on which to generate the tone.
frequency: the frequency of the tone in hertz. Allowed data types: unsigned int.
duration: the duration of the tone in milliseconds (optional). Allowed data types: unsigned long.
Returns
Nothing
Notes and Warnings
If you want to play different pitches on multiple pins, you need to call noTone() on one pin before calling tone() on the next pin.
See also
LANGUAGE analogWrite()
EXAMPLE Tone Melody
EXAMPLE Pitch Follower
EXAMPLE Tone Keyboard
EXAMPLE Tone Multiple
EXAMPLE PWM
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
            >  Advanced io
            > Pulsein
          
pulseIn()
          [Advanced I/O]
          
Description
pulseIn()
          [Advanced I/O]
          
Description
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go from LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or gives up and returns 0 if no complete pulse was received within the timeout.
The timing of this function has been determined empirically and will probably show errors in longer pulses. Works on pulses from 10 microseconds to 3 minutes in length.
Note
if the optional timeout is used code will execute faster.
Syntax
pulseIn(pin, value)
pulseIn(pin, value, timeout)
Parameters
pin: the number of the Arduino pin on which you want to read the pulse. Allowed data types: int.
value: type of pulse to read: either HIGH or LOW. Allowed data types: int.
timeout (optional): the number of microseconds to wait for the pulse to start; default is one second. Allowed data types: unsigned long.
Returns
The length of the pulse (in microseconds) or 0 if no pulse started before the timeout. Data type: unsigned long.
Example Code
The example prints the time duration of a pulse on pin 7.
int pin = 7;
unsigned long duration;
void setup() {
  Serial.begin(9600);
  pinMode(pin, INPUT);
}
void loop() {
  duration = pulseIn(pin, HIGH);
  Serial.println(duration);
}
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
            >  Advanced io
            > Shiftin
          
shiftIn()
          [Advanced I/O]
          
Description
shiftIn()
          [Advanced I/O]
          
Description
Shifts in a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. For each bit, the clock pin is pulled high, the next bit is read from the data line, and then the clock pin is taken low.
If you’re interfacing with a device that’s clocked by rising edges, you’ll need to make sure that the clock pin is low before the first call to shiftIn(), e.g. with a call to digitalWrite(clockPin, LOW).
Note: this is a software implementation; Arduino also provides an SPI library that uses the hardware implementation, which is faster but only works on specific pins.
Syntax
byte incoming = shiftIn(dataPin, clockPin, bitOrder)
Parameters
Syntax
byte incoming = shiftIn(dataPin, clockPin, bitOrder)
Parameters
dataPin: the pin on which to input each bit. Allowed data types: int.
clockPin: the pin to toggle to signal a read from dataPin.
bitOrder: which order to shift in the bits; either MSBFIRST or LSBFIRST. (Most Significant Bit First, or, Least Significant Bit First).
Returns
The value read. Data type: byte.
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
            >  Advanced io
            > Pulseinlong
          
pulseInLong()
          [Advanced I/O]
          
Description
pulseInLong() is an alternative to pulseIn() which is better at handling long pulse and interrupt affected scenarios.
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseInLong() waits for the pin to go from LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or gives up and returns 0 if no complete pulse was received within the timeout.
The timing of this function has been determined empirically and will probably show errors in shorter pulses. Works on pulses from 10 microseconds to 3 minutes in length. This routine can be used only if interrupts are activated. Furthermore the highest resolution is obtained with large intervals.
Syntax
pulseInLong(pin, value)
pulseInLong(pin, value, timeout)
Parameters
pin: the number of the Arduino pin on which you want to read the pulse. Allowed data types: int.
value: type of pulse to read: either HIGH or LOW. Allowed data types: int.
value: type of pulse to read: either HIGH or LOW. Allowed data types: int.
timeout (optional): the number of microseconds to wait for the pulse to start; default is one second. Allowed data types: unsigned long.
Returns
The length of the pulse (in microseconds) or 0 if no pulse started before the timeout. Data type: unsigned long.
Example Code
The example prints the time duration of a pulse on pin 7.
int pin = 7;
unsigned long duration;
void setup() {
  Serial.begin(9600);
  pinMode(pin, INPUT);
}
void loop() {
  duration = pulseInLong(pin, HIGH);
  Serial.println(duration);
}
Notes and Warnings
This function relies on micros() so cannot be used in noInterrupts() context.
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
            >  Advanced io
            > Shiftout
          
shiftOut()
          [Advanced I/O]
          
Description
shiftOut()
          [Advanced I/O]
          
Description
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a data pin, after which a clock pin is pulsed (taken high, then low) to indicate that the bit is available.
Note- if you’re interfacing with a device that’s clocked by rising edges, you’ll need to make sure that the clock pin is low before the call to shiftOut(), e.g. with a call to digitalWrite(clockPin, LOW).
This is a software implementation; see also the SPI library, which provides a hardware implementation that is faster but works only on specific pins.
Syntax
shiftOut(dataPin, clockPin, bitOrder, value)
Parameters
Syntax
shiftOut(dataPin, clockPin, bitOrder, value)
Parameters
dataPin: the pin on which to output each bit. Allowed data types: int.
clockPin: the pin to toggle once the dataPin has been set to the correct value. Allowed data types: int.
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST. (Most Significant Bit First, or, Least Significant Bit First).
value: the data to shift out. Allowed data types: byte.
Returns
Nothing
Example Code
For accompanying circuit, see the tutorial on controlling a 74HC595 shift register.
//**************************************************************//
//  Name    : shiftOutCode, Hello World                         //
//  Author  : Carlyn Maw,Tom Igoe                               //
//  Date    : 25 Oct, 2006                                      //
//  Version : 1.0                                               //
//  Version : 1.0                                               //
//  Notes   : Code for using a 74HC595 Shift Register           //
//          : to count from 0 to 255                            //
//****************************************************************
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}
void loop() {
  //count up routine
  for (int j = 0; j < 256; j++) {
    //ground latchPin and hold low for as long as you are transmitting
//ground latchPin and hold low for as long as you are transmitting
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, j);
    //return the latch pin high to signal chip that it
    //no longer needs to listen for information
    digitalWrite(latchPin, HIGH);
    delay(1000);
  }
}
Notes and Warnings
The dataPin and clockPin must already be configured as outputs by a call to pinMode().
shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255.
// Do this for MSBFIRST serial
int data = 500;
// shift out highbyte
shiftOut(dataPin, clock, MSBFIRST, (data >> 8));
// shift out lowbyte
shiftOut(dataPin, clock, MSBFIRST, data);
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
            >  Advanced io
            > Notone
          
noTone()
          [Advanced I/O]
          
Description
Stops the generation of a square wave triggered by tone(). Has no effect if no tone is being generated.
Syntax
noTone(pin)
Parameters
pin: the Arduino pin on which to stop generating the tone
Returns
Nothing
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
            >  Random numbers
            > Randomseed
          
randomSeed()
          [Random Numbers]
          
Description
randomSeed() initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This sequence, while very long, and random, is always the same.
If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin.
Conversely, it can occasionally be useful to use pseudo-random sequences that repeat exactly. This can be accomplished by calling randomSeed() with a fixed number, before starting the random sequence.
Syntax
randomSeed(seed)
Parameters
seed: non-zero number to initialize the pseudo-random sequence. Allowed data types: unsigned long.
Returns
Nothing
Example Code
The code generates a pseudo-random number and sends the generated number to the serial port.
long randNumber;
void setup() {
  Serial.begin(9600);
  randomSeed(analogRead(0));
}
void loop() {
  randNumber = random(300);
  Serial.println(randNumber);
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
            >  Random numbers
            > Random
          
random()
          [Random Numbers]
          
Description
The random function generates pseudo-random numbers.
Syntax
random(max)
random(min, max)
Parameters
min: lower bound of the random value, inclusive (optional).
max: upper bound of the random value, exclusive.
Returns
max: upper bound of the random value, exclusive.
Returns
A random number between min and max-1. Data type: long.
Example Code
The code generates random numbers and displays them.
long randNumber;
void setup() {
  Serial.begin(9600);
  // if analog input pin 0 is unconnected, random analog
  // noise will cause the call to randomSeed() to generate
  // different seed numbers each time the sketch runs.
  // randomSeed() will then shuffle the random function.
  randomSeed(analogRead(0));
}
void loop() {
  // print a random number from 0 to 299
  randNumber = random(300);
  Serial.println(randNumber);
  // print a random number from 10 to 19
  randNumber = random(10, 20);
  Serial.println(randNumber);
  delay(50);
Serial.println(randNumber);
  delay(50);
}
Notes and Warnings
If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin.
Conversely, it can occasionally be useful to use pseudo-random sequences that repeat exactly. This can be accomplished by calling randomSeed() with a fixed number, before starting the random sequence.
The max parameter should be chosen according to the data type of the variable in which the value is stored. In any case, the absolute maximum is bound to the long nature of the value generated (32 bit - 2,147,483,647). Setting max to a higher value won’t generate an error during compilation, but during sketch execution the numbers generated will not be as expected.
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
            >  Characters
            > Ishexadecimaldigit
          
isHexadecimalDigit()
          [Characters]
          
Description
Analyse if a char is an hexadecimal digit (A-F, 0-9). Returns true if thisChar contains an hexadecimal digit.
Syntax
isHexadecimalDigit(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is an hexadecimal digit.
Example Code
if (isHexadecimalDigit(myChar)) { // tests if myChar is an hexadecimal digit
  Serial.println("The character is an hexadecimal digit");
}
else {
  Serial.println("The character is not an hexadecimal digit");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Islowercase
          
isLowerCase()
          [Characters]
          
Description
Analyse if a char is lower case (that is a letter in lower case). Returns true if thisChar contains a letter in lower case.
Syntax
isLowerCase(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is lower case.
Example Code
if (isLowerCase(myChar)) {  // tests if myChar is a lower case letter
  Serial.println("The character is lower case");
}
else {
  Serial.println("The character is not lower case");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Ispunct
          
isPunct()
          [Characters]
          
Description
Analyse if a char is punctuation (that is a comma, a semicolon, an exclamation mark and so on). Returns true if thisChar is punctuation.
Syntax
isPunct(thisChar)
Parameters
Syntax
isPunct(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is a punctuation.
Example Code
if (isPunct(myChar)) {  // tests if myChar is a punctuation character
  Serial.println("The character is a punctuation");
}
else {
  Serial.println("The character is not a punctuation");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Isuppercase
          
isUpperCase()
          [Characters]
          
Description
Analyse if a char is upper case (that is, a letter in upper case). Returns true if thisChar is upper case.
Syntax
isUpperCase(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is upper case.
Example Code
if (isUpperCase(myChar)) {  // tests if myChar is an upper case letter
  Serial.println("The character is upper case");
}
else {
  Serial.println("The character is not upper case");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Isspace
          
isSpace()
          [Characters]
          
Description
Analyse if a char is a white-space character. Returns true if the argument is a space, form feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), or vertical tab ('\v').
Syntax
isSpace(thisChar)
Parameters
Syntax
isSpace(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is a white-space character.
Example Code
if (isSpace(myChar)) {  // tests if myChar is a white-space character
  Serial.println("The character is white-space");
}
else {
  Serial.println("The character is not white-space");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Isalpha
          
isAlpha()
          [Characters]
          
Description
Analyse if a char is alpha (that is a letter). Returns true if thisChar contains a letter.
Syntax
isAlpha(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is alpha.
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
            >  Characters
            > Isprintable
          
isPrintable()
          [Characters]
          
Description
Analyse if a char is printable (that is any character that produces an output, even a blank space). Returns true if thisChar is printable.
Syntax
isPrintable(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is printable.
Example Code
if (isPrintable(myChar)) {  // tests if myChar is printable char
  Serial.println("The character is printable");
}
else {
  Serial.println("The character is not printable");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Iscontrol
          
isControl()
          [Characters]
          
Description
Analyse if a char is a control character. Returns true if thisChar is a control character.
Syntax
isControl(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is a control character.
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
            >  Characters
            > Isgraph
          
isGraph()
          [Characters]
          
Description
Analyse if a char is printable with some content (space is printable but has no content). Returns true if thisChar is printable.
Syntax
isGraph(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is printable.
Example Code
if (isGraph(myChar)) {  // tests if myChar is a printable character but not a blank space.
  Serial.println("The character is printable");
}
else {
  Serial.println("The character is not printable");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Iswhitespace
          
isWhitespace()
          [Characters]
          
Description
Analyse if a char is a space character. Returns true if the argument is a space or horizontal tab ('\t').
Syntax
isWhitespace(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is a space character.
Example Code
if (isWhitespace(myChar)) { // tests if myChar is a space character
  Serial.println("The character is a space or tab");
}
else {
  Serial.println("The character is not a space or tab");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Isascii
          
isAscii()
          [Characters]
          
Description
Analyse if a char is Ascii. Returns true if thisChar contains an Ascii character.
Syntax
isAscii(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is 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
            >  Characters
            > Isalphanumeric
          
isAlphaNumeric()
          [Characters]
          
Description
Analyse if a char is alphanumeric (that is a letter or a numbers). Returns true if thisChar contains either a number or a letter.
Syntax
isAlphaNumeric(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is alphanumeric.
Example Code
if (isAlphaNumeric(myChar)) { // tests if myChar isa letter or a number
  Serial.println("The character is alphanumeric");
}
else {
  Serial.println("The character is not alphanumeric");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Characters
            > Isdigit
          
isDigit()
          [Characters]
          
Description
Analyse if a char is a digit (that is a number). Returns true if thisChar is a number.
Syntax
isDigit(thisChar)
Parameters
thisChar: variable. Allowed data types: char.
Returns
Parameters
thisChar: variable. Allowed data types: char.
Returns
true: if thisChar is a number.
Example Code
if (isDigit(myChar)) {  // tests if myChar is a digit
  Serial.println("The character is a number");
}
else {
  Serial.println("The character is not a number");
}
See also
LANGUAGE char
LANGUAGE if (conditional operators)
LANGUAGE while (conditional operators)
LANGUAGE read()
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
            >  Zero due mkr family
            > Analogwriteresolution
          
analogWriteResolution()
          [Zero, Due & MKR Family]
          
Description
analogWriteResolution() is an extension of the Analog API for the Arduino Due.
Description
analogWriteResolution() is an extension of the Analog API for the Arduino Due.
analogWriteResolution() sets the resolution of the analogWrite() function. It defaults to 8 bits (values between 0-255) for backward compatibility with AVR based boards.
The Due has the following hardware capabilities:
12 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed to 12-bit resolution.
2 pins with 12-bit DAC (Digital-to-Analog Converter)
By setting the write resolution to 12, you can use analogWrite() with values between 0 and 4095 to exploit the full DAC resolution or to set the PWM signal without rolling over.
The Zero has the following hardware capabilities:
10 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed to 12-bit resolution.
1 pin with 10-bit DAC (Digital-to-Analog Converter).
By setting the write resolution to 10, you can use analogWrite() with values between 0 and 1023 to exploit the full DAC resolution
The MKR Family of boards has the following hardware capabilities:
4 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed from 8 (default) to 12-bit resolution.
1 pin with 10-bit DAC (Digital-to-Analog Converter)
By setting the write resolution to 12 bits, you can use analogWrite() with values between 0 and 4095 for PWM signals; set 10 bit on the DAC pin to exploit the full DAC resolution of 1024 values.
Syntax
analogWriteResolution(bits)
Parameters
Syntax
analogWriteResolution(bits)
Parameters
bits: determines the resolution (in bits) of the values used in the analogWrite() function. The value can range from 1 to 32. If you choose a resolution higher or lower than your board’s hardware capabilities, the value used in analogWrite() will be either truncated if it’s too high or padded with zeros if it’s too low. See the note below for details.
Returns
Nothing
Example Code
Explain Code
void setup() {
  // open a serial connection
  Serial.begin(9600);
  // make our digital pin an output
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}
void loop() {
  // read the input on A0 and map it to a PWM pin
  // with an attached LED
  int sensorVal = analogRead(A0);
// with an attached LED
  int sensorVal = analogRead(A0);
  Serial.print("Analog Read) : ");
  Serial.print(sensorVal);
  // the default PWM resolution
  analogWriteResolution(8);
  analogWrite(11, map(sensorVal, 0, 1023, 0, 255));
  Serial.print(" , 8-bit PWM value : ");
  Serial.print(map(sensorVal, 0, 1023, 0, 255));
  // change the PWM resolution to 12 bits
  // the full 12 bit resolution is only supported
  // on the Due
  analogWriteResolution(12);
  analogWrite(12, map(sensorVal, 0, 1023, 0, 4095));
  Serial.print(" , 12-bit PWM value : ");
Serial.print(" , 12-bit PWM value : ");
  Serial.print(map(sensorVal, 0, 1023, 0, 4095));
  // change the PWM resolution to 4 bits
  analogWriteResolution(4);
  analogWrite(13, map(sensorVal, 0, 1023, 0, 15));
  Serial.print(", 4-bit PWM value : ");
  Serial.println(map(sensorVal, 0, 1023, 0, 15));
  delay(5);
}
Notes and Warnings
If you set the analogWriteResolution() value to a value higher than your board’s capabilities, the Arduino will discard the extra bits. For example: using the Due with analogWriteResolution(16) on a 12-bit DAC pin, only the first 12 bits of the values passed to analogWrite() will be used and the last 4 bits will be discarded.
If you set the analogWriteResolution() value to a value lower than your board’s capabilities, the missing bits will be padded with zeros to fill the hardware required size. For example: using the Due with analogWriteResolution(8) on a 12-bit DAC pin, the Arduino will add 4 zero bits to the 8-bit value used in analogWrite() to obtain the 12 bits required.
See also
LANGUAGE analogWrite()
LANGUAGE analogRead()
LANGUAGE map()
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
            >  Zero due mkr family
            > Analogreadresolution
          
analogReadResolution()
          [Zero, Due & MKR Family]
          
Description
analogReadResolution() is an extension of the Analog API for the Zero, Due, MKR family, Nano 33 (BLE and IoT) and Portenta.
Sets the size (in bits) of the value returned by analogRead(). It defaults to 10 bits (returns values between 0-1023) for backward compatibility with AVR based boards.
The Zero, Due, MKR family and Nano 33 (BLE and IoT) boards have 12-bit ADC capabilities that can be accessed by changing the resolution to 12. This will return values from analogRead() between 0 and 4095.
The Portenta H7 has a 16 bit ADC, which will allow values between 0 and 65535.
Syntax
analogReadResolution(bits)
Parameters
bits: determines the resolution (in bits) of the value returned by the analogRead() function. You can set this between 1 and 32. You can set resolutions higher than the supported 12 or 16 bits, but values returned by analogRead() will suffer approximation. See the note below for details.
Returns
Nothing
Returns
Nothing
Example Code
The code shows how to use ADC with different resolutions.
void setup() {
  // open a serial connection
  Serial.begin(9600);
}
void loop() {
  // read the input on A0 at default resolution (10 bits)
  // and send it out the serial connection
  analogReadResolution(10);
  Serial.print("ADC 10-bit (default) : ");
  Serial.print(analogRead(A0));
  // change the resolution to 12 bits and read A0
  analogReadResolution(12);
  Serial.print(", 12-bit : ");
  Serial.print(analogRead(A0));
  // change the resolution to 16 bits and read A0
  analogReadResolution(16);
  Serial.print(", 16-bit : ");
  Serial.print(analogRead(A0));
Serial.print(", 16-bit : ");
  Serial.print(analogRead(A0));
  // change the resolution to 8 bits and read A0
  analogReadResolution(8);
  Serial.print(", 8-bit : ");
  Serial.println(analogRead(A0));
  // a little delay to not hog Serial Monitor
  delay(100);
}
Notes and Warnings
If you set the analogReadResolution() value to a value higher than your board’s capabilities, the Arduino will only report back at its highest resolution, padding the extra bits with zeros.
For example: using the Due with analogReadResolution(16) will give you an approximated 16-bit number with the first 12 bits containing the real ADC reading and the last 4 bits padded with zeros.
If you set the analogReadResolution() value to a value lower than your board’s capabilities, the extra least significant bits read from the ADC will be discarded.
Using a 16 bit resolution (or any resolution higher than actual hardware capabilities) allows you to write sketches that automatically handle devices with a higher resolution ADC when these become available on future boards without changing a line of code.
See also
EXAMPLE Description of the analog input pins
LANGUAGE analogRead()
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
            >  Time
            > Millis
          
millis()
          [Time]
          
Description
Returns the number of milliseconds passed since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.
Syntax
time = millis()
Parameters
None
Returns
Syntax
time = millis()
Parameters
None
Returns
Number of milliseconds passed since the program started. Data type: unsigned long.
Example Code
This example code prints on the serial port the number of milliseconds passed since the Arduino board started running the code itself.
unsigned long myTime;
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.print("Time: ");
  myTime = millis();
  Serial.println(myTime); // prints time since program started
  delay(1000);          // wait a second so as not to send massive amounts of data
}
Notes and Warnings
Please note that the return value for millis() is of type unsigned long, logic errors may occur if a programmer tries to do arithmetic with smaller data types such as int. Even signed long may encounter errors as its maximum value is half that of its unsigned counterpart.
Reconfiguration of the microcontroller’s timers may result in inaccurate millis() readings. The "Arduino AVR Boards" and "Arduino megaAVR Boards" cores use Timer0 to generate millis(). The "Arduino ARM (32-bits) Boards" and "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" cores use the SysTick timer.
See also
EXAMPLE Blink Without Delay
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
            >  Time
            > Delay
          
delay()
          [Time]
          
Description
Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000 milliseconds in a second.)
Syntax
delay(ms)
Parameters
ms: the number of milliseconds to pause. Allowed data types: unsigned long.
Returns
Nothing
Returns
Nothing
Example Code
The code pauses the program for one second before toggling the output pin.
int ledPin = 13;              // LED connected to digital pin 13
void setup() {
  pinMode(ledPin, OUTPUT);    // sets the digital pin as output
}
void loop() {
  digitalWrite(ledPin, HIGH); // sets the LED on
  delay(1000);                // waits for a second
  digitalWrite(ledPin, LOW);  // sets the LED off
  delay(1000);                // waits for a second
}
Notes and Warnings
delay(1000);                // waits for a second
}
Notes and Warnings
While it is easy to create a blinking LED with the delay() function and many sketches use short delays for such tasks as switch debouncing, the use of delay() in a sketch has significant drawbacks. No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt. For alternative approaches to controlling timing see the Blink Without Delay sketch, which loops, polling the millis() function until enough time has elapsed. More knowledgeable programmers usually avoid the use of delay() for timing of events longer than 10’s of milliseconds unless the Arduino sketch is very simple.