Reads the value from the specified analog pin. The LaunchPad board typically contains 8 channel, 10-bit analog to digital converter. Check your LaunchPad for specific channel and resolution information. This means that it will map input voltages between 0 and ~3 volts (VCC) into integer values between 0 and 1023. This yields a resolution between readings of: 3 volts / 1024 units or, .0029 volts (2.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.






pin: the number of the analog input pin to read from.



int (0 to 1023)



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



int analogPin = A3;     // potentiometer on educational boosterpack connected to analog pin 5
                       // outside leads to ground and ~3V
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


See also


Reference Home