7 min read
How to Read an Analog Sensor on Arduino
An analog input measures voltage, not resistance or light directly. Once you know what number analogRead returns and what it refers to, any divider-based sensor follows the same pattern.

At a glance
- 6 sections
- 4 answered questions
- 3 linked pages
- No installation needed
What analogRead returns
On a classic 10-bit converter, analogRead gives an integer from 0 to 1023. Zero means the input is near ground, and 1023 means it is near the reference voltage. The number is a ratio, not a voltage by itself, so it changes when the reference changes.
The ADC in the microcontroller is shared by all analog inputs. A single converter is switched between pins internally, which is why very fast switching can need a short settling time.
The voltage reference matters
By default the reference is the board’s operating voltage, commonly 5 V or 3.3 V. A reading of 512 on a 5 V board corresponds to roughly 2.5 V, while the same reading on a 3.3 V board corresponds to roughly 1.65 V. Writing the reference voltage into a named constant avoids silent errors when a sketch moves between boards.
If the supply drifts, the reference drifts with it and so does every measurement. A stable external reference is used when accuracy matters more than convenience.
A potentiometer is the simplest sensor
A potentiometer has three legs. Connect one outer leg to the supply and the other to ground; the middle leg then carries a voltage that depends on the knob position. Read the middle leg on an analog input and the number moves smoothly across most of the range.
Swap the two outer legs and the direction reverses. This is a useful check: if the value moves the wrong way for your interface, the wiring is the reason, not the code.
A photoresistor needs a fixed partner
A photoresistor changes resistance with light but cannot produce a voltage on its own. Put it in series with a fixed resistor across the supply and read the junction. As light changes the photoresistor’s resistance, the junction voltage moves.
Choose the fixed resistor to be roughly the photoresistor’s resistance at the light level you care about. That gives the largest voltage swing where the sensor is most useful.
Convert the number into volts
Multiply the raw reading by the reference voltage and divide by 1024. Print both the raw value and the converted voltage while you set up the circuit; the raw number is best for thresholds, and volts are easier to compare with a datasheet.
If you later change the reference in code, the conversion constant must change too. Keep both in one place so they cannot drift apart.
Smooth a noisy reading
Averaging several samples, or keeping a running average of the last few readings, removes small jitter without making the response feel slow. Take samples a few milliseconds apart so you are not simply reading the same moment repeatedly.
Average only what you need. Heavy smoothing makes a fast sensor feel sluggish, so choose the window to match how quickly the real quantity changes.
Frequently asked questions
What values does analogRead return?
On a 10-bit ADC, 0 to 1023, where 1023 corresponds to the reference voltage.
Why did my reading change after moving to a 3.3 V board?
The same raw number now represents a smaller voltage because the default reference follows the supply.
Why does a photoresistor need a fixed resistor?
It changes resistance, not voltage. The second resistor forms a divider whose junction voltage can be measured.
How do I reduce flicker in the readings?
Average a small number of samples taken a few milliseconds apart, and keep wiring short.
Related pages
Keep learning
Continue with a hands-on project, a browser simulator or a free account.
- → Analog reading project
- → Why is my LED dim?
- → Circuit simulator
- → Topic tracking — save progress across lessons