click to enlarge |
If you have ever used a multimeter to check voltage across an electronics circuit, you can think of this experiment as a simulator of the same.
I have created a trimmed version of the same program, it will help you to quickly understand the programming. After that it will be easier to understand the program in the example.
Here in the setup() function we initiate a serial communication with 9600 baud rate. In the loop() function the input on the analog pin A0 is read by the function analogRead()
The voltage read at the pin A0 will vary between 0 and 5 volts. The ADC Analog to Digital converter will map this value between 0 to 1023. We will store this value in the integer variable x.
Now we will convert this value back into voltage so as it display on the screen. Thus we get the value of the voltage in the float variable v and print it in the Serial monitor or the plotter.
click to enlarge |