Robots Atlas>ROBOTS ATLAS

Arduino for Beginners · Analog Signals: ADC and PWM

ADC: how the 0–1023 values map to voltage, map() and constrain()

Analog Signals: ADC and PWM

Introduction

The raw number from analogRead() (0–1023) is just the start. In this lesson we convert it to voltage with v = value * (5.0 / 1023.0), defuse the integer-division trap (5/1023 = 0), and learn to rescale ranges with map() and clip them with constrain(). We cover typical conversions: 0–1023 to 0–255 for PWM, to 0–100 for percentages, and to 0–180 for a servo angle — together with the precision pitfalls and the lack of automatic range clamping in map().