We convert ADC values to voltage to understand real-world signals like temperature or light in volts, which are easier to interpret.
Converting ADC value to voltage in Embedded C
float voltage = (adc_value * reference_voltage) / max_adc_value;adc_value is the number read from the ADC (usually an integer).
reference_voltage is the maximum voltage the ADC can measure (like 3.3V or 5V).
max_adc_value is the maximum ADC value (e.g., 1023 for 10-bit ADC).
float voltage = (adc_value * 3.3) / 1023;
float voltage = (adc_value * 5.0) / 4095;
This program converts a 10-bit ADC value of 512 to voltage using a 3.3V reference and prints the result.
#include <stdio.h> int main() { int adc_value = 512; // Example ADC reading float reference_voltage = 3.3; // ADC reference voltage in volts int max_adc_value = 1023; // For 10-bit ADC float voltage = (adc_value * reference_voltage) / max_adc_value; printf("ADC Value: %d\n", adc_value); printf("Voltage: %.2f V\n", voltage); return 0; }
Make sure to use floating point numbers for accurate voltage calculation.
The max ADC value depends on the ADC resolution: for 10-bit it's 1023, for 12-bit it's 4095, etc.
Reference voltage must match the voltage used by your ADC hardware.
ADC values are numbers from 0 to max ADC value representing voltage levels.
Convert ADC value to voltage by multiplying by reference voltage and dividing by max ADC value.
This helps to understand sensor readings in real voltage units.