Description
Reads the value from the specified analog pin. the Arduino board contains a 6 channel (8 channels 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 V/1024 units or ,. 0049 Volts (4.9 mV) per unit. the input range and resolution can be changed using analogreference ().
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.
Read the value from the specified analog pin. The Arduino motherboard has 6 channels (8 mini and nano, 16 mega), and 10-bit AD (Analog-to-analog) converters. This means that the input voltage 0-5 V corresponds to an integer 0. This means that the read precision is 5 V/1024 units, which is about 0.049 V (4.9 mV) for each unit ). The input range and progress can be modified through analogreference.
The read duration of a simulated input is 100 microseconds (0.0001 seconds), so the maximum read speed is 10,000 times per second.
Syntax
Analogread (PIN)
Parameters
Pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the mini and nano, 0 to 15 on the mega)
Pin: Read analog input pin number (most motherboard numbers are 0-5, Mini and nano are 0-7, mega is 0-15)
Returns Return Value
INT (0 to 1023)
Integer int (0 to 1023)
Note
If the analog input pin is not connected to anything, the value returned by analogread () will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc .).
If the analog input pin is not connected to any place, the returned value of analogread () also fluctuates due to some factors (for example, other analog input, your hands are too close to the motherboard)
Example
int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3 // outside leads to ground and +5Vint val = 0; // variable to store the value readvoid setup(){ Serial.begin(9600); // setup serial}void loop(){ val = analogRead(analogPin); // read the input pin Serial.println(val); // debug value}