You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Language/Functions/Analog IO/analogRead.adoc
+25-12Lines changed: 25 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,37 @@ categories: [ "Functions" ]
4
4
subCategories: [ "Analog I/O" ]
5
5
---
6
6
7
-
8
-
9
-
10
7
= analogRead()
11
8
12
-
13
9
// OVERVIEW SECTION STARTS
14
10
[#overview]
15
11
--
16
12
17
13
[float]
18
14
=== 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.
20
16
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.
*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]
24
38
25
39
[float]
26
40
=== Syntax
@@ -29,18 +43,17 @@ It takes about 100 microseconds (0.0001 s) to read an analog input, so the maxim
29
43
30
44
[float]
31
45
=== 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).
33
47
34
48
[float]
35
49
=== 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).
37
52
38
53
--
39
54
// OVERVIEW SECTION ENDS
40
55
41
56
42
-
43
-
44
57
// HOW TO USE SECTION STARTS
45
58
[#howtouse]
46
59
--
@@ -52,7 +65,7 @@ The code reads the voltage on analogPin and displays it.
52
65
53
66
[source,arduino]
54
67
----
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
0 commit comments