Complete the code to read an analog value from pin A0.
int sensorValue = analogRead([1]);The analogRead function reads the voltage on the specified analog pin. Pin A0 is the first analog input pin on Arduino.
Complete the code to convert the analog reading to a voltage (0-5V).
float voltage = sensorValue * ([1] / 1023.0);
The Arduino analog reference voltage is usually 5.0 volts. We multiply the reading by 5.0 and divide by 1023 to get the voltage.
Fix the error in the code to print the voltage with two decimal places.
Serial.println([1], 2);
To print the voltage with two decimal places, we use the variable 'voltage' which holds the converted value.
Fill both blanks to loop over analog pins A0-A5 and print readings greater than 500.
for(int [1] = 0; [1] < 6; [1]++) { int value = analogRead([2]); if (value > 500) { Serial.print("Pin A"); Serial.print([1]); Serial.print(": "); Serial.println(value); } }
We use 'i' as the loop variable and 'A0 + i' to read analog pins A0 to A5.
Fill all three blanks to calculate and print the percentage of the maximum ADC value.
int maxValue = [1]; int reading = analogRead(A0); float percentage = (reading * 100.0) / [2]; Serial.print([3]); Serial.println("%");
The maximum ADC value for 10-bit resolution is 1023. We use it to calculate the percentage and print the 'percentage' variable.
