Reading an ADC
What do digital data actually look like in the microcontroller? They are numerical values stored in registers (memory) that can be loaded and processed by the processor. On the Arduino, an example library contains the function
int sensorValue = analogRead(A0);
The command “analogRead(A0)” digitises an analogue input voltage applied to the input pin A0 (i.e. connected to that pin of the IC). The voltage is digitised only once, not continuously, when this program line is called. The result of the conversion is written to the variable “sensorValue”. The variable is of type “int”, i.e. it is an integer. You can then carry out arithmetic operations with the variable.
If you execute this line of code several times in succession and write the data to different variables, you can convert the input voltage continuously. In computer science, arrays or pointers are usually used for this. In an array of size 16, the continuously converted voltage signal could look like this, for example:
![Sampled sine with the numerical values in the array sensorValue[16] = {3,6,7,6,4,1,0,1,3,6,7,6,4,1,0,1}](../../bilder/de/mt_auslesen-eines-adcs/14_Messtechnik-ADC-auslesen-1024x691.png)
For this, you need the following code:
int sensorValue[16];
for (int i = 0; i <= 15; i++)
{
sensorValue[i]= analogRead(A0);
}
You can also output the result of the conversion as a continuous data stream on a console on the PC. With that, you would already have built a simple, complete measurement system in which the entire measurement chain is implemented. You can find more details in the example code of the Arduino software.