How do I convert Arduino Uno analogRead() to voltage in C++?
Multiply raw reading (0-1023) by 5.0 and divide by 1023.0: float volts = analogRead(A0) * (5.0 / 1023.0);
Quickly translate analogRead() sensor counts into real volts and convert target PWM percentages into exact analogWrite() or ESP32 ledcWrite() register values.
// Arduino Uno / Nano (5.0V, 10-bit ADC, 8-bit PWM)
int raw = analogRead(A0); // 512 -> 2.50V (50.0%)
float volts = raw * (5.0f / 1023.0f);
analogWrite(9, 128); // 50.0% duty (~2.51V avg)Multiply raw reading (0-1023) by 5.0 and divide by 1023.0: float volts = analogRead(A0) * (5.0 / 1023.0);
Arduino Uno has a 10-bit ADC (2^10 = 1024 steps: 0-1023), while ESP32 has a 12-bit ADC (2^12 = 4096 steps: 0-4095) across 0-3.3V.
Chrome USB WebSerial + 300 Free Credits
Open Gokino in Chrome, let AI generate interactive /wiring circuit diagrams, fix C++ bugs in 1 click, and upload directly to Arduino, ESP32, or STM32 with zero installation.