27. Simple voltmeter using ADC

The goal is to read an analog voltage input using the microcontroller's ADC and convert it into a digital voltage value displayed over serial communication.

Understanding the Task

To implement a simple voltmeter, the microcontroller needs to:

  • Sample the analog voltage on a designated ADC channel.
  • Convert the ADC digital value to voltage units (Volts).
  • Send the voltage reading to a serial terminal for user observation.

Hardware Interfacing

Voltage Input Connection

  • Connect the voltage source's positive terminal to any ADC channel.
  • Connect the voltage source negative terminal to GND on the board.

Note: The input voltage must be within the microcontroller’s GPIO voltage range to avoid damaging the microcontroller ADC pin.

Here, we will use a potentiometer as a varying voltage source. 

Potentiometer Interfacing

We can use any of the potentiometers with values between 1kΩ and 10kΩ.

Potentiometer-pinout
  • Connection:
    • Connect the two outer fixed terminals of the potentiometer to VCC and GND, and connect the middle (wiper) terminal to one of the microcontroller’s ADC (Analog-to-Digital Converter) input pins.
  • Function:
    • Rotating the potentiometer varies the middle terminal voltage from 0V to VCC, which the microcontroller’s ADC reads as a digital value proportional to the knob position.

So, by selecting a potentiometer as a voltage source, we can implement the task.

Below are the solutions to the given task using different microcontrollers

  1. STM32
  2. Arduino UNO

Note: The current task requires a highly accurate ADC. However, the ESP32’s built-in ADC is non-linear and shows poor accuracy near the voltage edges (close to 0 V and Vref). Due to this limitation,  we are not implementing this task using ESP32.

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!