Arduino Programming Language: AnalogReadResolution

Name

analogReadResolution()

Description

analogReadResolution() is an extension of the Analog API for the Arduino Due and M0/M0 Pro and Primo. 
Sets the size (in bits) of the value returned by analogRead(). It defaults to 10 bits (returns values between 0-1023) but in Arduino Due/M0/M0 Pro can be set until 12 bits (possible returns values are between from 0 to 4095) instead in Arduino Primo can be set until 14 bits (possible returns values are between from 0 to 16384).

Syntax

analogReadResolution(bit)

Parameters

  • bit: resolution (in bits) of the value returned by analogRead()function. You can set this 1 and 32. You can set resolutions higher than 12 but values returned by analogRead() will suffer approximation.

Returns

none 

Usage

Application

Note

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. 
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.

Examples

int pinIN = 3;
int value = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
analogReadResolution(12);
value = analogRead(pinIN);
Serial.println(value);
}


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc