Skip to content

Commit 9122466

Browse files
authored
Merge PR #463 Updated analogRead() to use An style pin names from robsoncouto/master
Updated analogRead() to use An style pin names. Fixes #447
2 parents be0447b + 58f8047 commit 9122466

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

Language/Functions/Analog IO/analogRead.adoc

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,37 @@ categories: [ "Functions" ]
44
subCategories: [ "Analog I/O" ]
55
---
66

7-
8-
9-
107
= analogRead()
118

12-
139
// OVERVIEW SECTION STARTS
1410
[#overview]
1511
--
1612

1713
[float]
1814
=== Description
19-
Reads the value from the specified analog pin. The Arduino board contains a 6 channel (7 channels on MKR boards, 8 on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. The input range and resolution can be changed using link:../analogreference[analogReference()].
15+
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.
2016

21-
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.
22-
[%hardbreaks]
17+
The input range can be changed using link:../analogreference[analogReference()], while the resolution can be changed (only for Zero, Due and MKR boards) using link:../../zero-due-mkr-family/analogreadresolution[analogReadResolution()].
18+
19+
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.
2320

21+
[options="header"]
22+
|===================================================
23+
|Board |Operating voltage |Usable pins |Max resolution
24+
|Uno |5 Volts |A0 to A5 |10 bits
25+
|Mini, Nano |5 Volts |A0 to A7 |10 bits
26+
|Mega, Mega2560, MegaADK |5 Volts |A0 to A14 |10 bits
27+
|Micro |5 Volts |A0 to A11* |10 bits
28+
|Leonardo |5 Volts |A0 to A11* |10 bits
29+
|Zero |3.3 Volts |A0 to A5 |12 bits**
30+
|Due |3.3 Volts |A0 to A11 |12 bits**
31+
|MKR Family boards |3.3 Volts |A0 to A6 |12 bits**
32+
|===================================================
33+
34+
*A0 through A5 are labelled on the board, A6 through A11 are respectively available on pins 4, 6, 8, 9, 10, and 12 +
35+
**The default analogRead() resolution for these boards is 10 bits, for compatibility. You need to use link:../../zero-due-mkr-family/analogreadresolution[analogReadResolution()] to change it to 12 bits.
36+
37+
[%hardbreaks]
2438

2539
[float]
2640
=== Syntax
@@ -29,18 +43,17 @@ It takes about 100 microseconds (0.0001 s) to read an analog input, so the maxim
2943

3044
[float]
3145
=== Parameters
32-
`pin`: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 6 on MKR boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)
46+
`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).
3347

3448
[float]
3549
=== Returns
36-
int(0 to 1023)
50+
51+
The analog reading on the pin (int). Although it is limited to the resolution of the analog to digital converter (0-1023 for 10 bits or 0-4095 for 12 bits).
3752

3853
--
3954
// OVERVIEW SECTION ENDS
4055

4156

42-
43-
4457
// HOW TO USE SECTION STARTS
4558
[#howtouse]
4659
--
@@ -52,7 +65,7 @@ The code reads the voltage on analogPin and displays it.
5265

5366
[source,arduino]
5467
----
55-
int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3
68+
int analogPin = A3; // potentiometer wiper (middle terminal) connected to analog pin 3
5669
// outside leads to ground and +5V
5770
int val = 0; // variable to store the value read
5871

0 commit comments

Comments
 (0)