// Pin for analog input
const int analogPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
// Read the raw ADC value (10-bit resolution: 0 to 1023)
int adcValue = analogRead(analogPin);
// Convert the ADC value to voltage
// 5V reference, voltage = (adcValue * 5.0) / 1023
float voltage = adcValue * (5.0 / 1023.0);
// Print the ADC value and corresponding voltage
Serial.print("ADC Value: ");
Serial.print(adcValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.println(" V");
// Wait for a short time before taking another reading
delay(500); // 500ms delay
}
analogRead(analogPin)
: reads ADC value.float voltage = adcValue * (5.0 / 1023.0)
: converts ADC_value to voltage. Serial.print
: print ADC_value and Voltage.
The circuit connection is as follows
The output of the voltmeter readings is as follows