analogRead()
Reads the value from the specified analog pin. The Z-Uno board contains a 4 channel, 10-bit analog to digital converter. This means that it will map input voltages between 0 and Vcc (about 3 V) into integer values between 0 and 1023. Check Z-Uno pinout analogRead(pin) pin the number of the analog input pin to read from: A0, A1, A2, A3 or BATTERY int (0 to 1023) (depends on ADC resolution check analogReadResolution() for more details) 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.).
void setup() {
Serial.begin(); // setup serial
}
void loop() {
int val; // variable to store the value read
val = analogRead(A3); // read the input pin
Serial.println(val); // debug output
}
If you need an absolute measured value in Volts and not relative to Vcc, use BATTERY to re-scale the result according to the absolute Vcc voltage.
If BATTERY is used, the reported value is the position of 1.21V (internal reference voltage) between 0 and battery voltage (3V pin voltage). For 10-bits precision the battery voltage equals to 1.21 V * value / 1024
or for 8-bits to 1.21 V * value / 256 = 30976 / value
. The accurace of the internal reference voltage is about 10%. You might need to calibrate this calculation for your Z-Uno.
analogReadResolution()
analogReference()