0
0
Embedded Cprogramming~5 mins

Converting ADC value to voltage in Embedded C

Choose your learning style9 modes available
Introduction

We convert ADC values to voltage to understand real-world signals like temperature or light in volts, which are easier to interpret.

Reading sensor data like temperature or light intensity from an ADC.
Displaying the measured voltage on a screen or sending it to another device.
Making decisions in a program based on voltage thresholds.
Calibrating sensors by comparing ADC readings to known voltages.
Syntax
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).

Examples
For a 10-bit ADC (max value 1023) with 3.3V reference.
Embedded C
float voltage = (adc_value * 3.3) / 1023;
For a 12-bit ADC (max value 4095) with 5V reference.
Embedded C
float voltage = (adc_value * 5.0) / 4095;
Sample Program

This program converts a 10-bit ADC value of 512 to voltage using a 3.3V reference and prints the result.

Embedded C
#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;
}
OutputSuccess
Important Notes

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.

Summary

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.