In this section, let us take a look at the commonly used in-built C functions that are used for analog I/O. To begin with we will learn how analog input is measured by the Arduino sketch. An Arduino sketch uses the following function to obtain an analog reading from its analog pins:
analogRead(<pin-number>)
For example, if we want to read the analog signal value from analog pin A5, we must use the following function call:
int value; // declare integer variable
value = analogRead(A5); // read analog value
The above function will return an integer value between 0 and 1023, depending upon the voltage value on the pin. The number 0 to 1023 will be proportional to the voltage range of the Arduino Uno board i.e. 0 to 5 volts.
Next we will look at techniques to write analog signals on both analog as well as digital pins. Digital pins...