Bird
Raised Fist0
Arduinoprogramming~10 mins

ADC resolution (10-bit, 0-1023 range) in Arduino - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - ADC resolution (10-bit, 0-1023 range)
Start ADC Conversion
ADC reads analog voltage
Convert voltage to digital number
Output digital value 0-1023
Use value in program
The ADC reads an analog voltage and converts it into a digital number between 0 and 1023 using 10-bit resolution.
Execution Sample
Arduino
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
Reads analog voltage on pin A0 and prints the 10-bit digital value (0-1023).
Execution Table
StepActionAnalog Voltage (V)Digital Value (0-1023)Explanation
1Start ADC conversionN/AN/AADC begins reading voltage on pin A0
2Measure voltage2.5N/AAnalog voltage measured (example 2.5V)
3Convert voltage2.5512Voltage converted to digital value: 2.5V ≈ 512
4Store valueN/A512Digital value stored in sensorValue variable
5Print valueN/A512Value 512 printed to serial monitor
6EndN/AN/AProgram waits for next reading
💡 ADC conversion completes and value is ready for use; range is 0-1023 for 0-5V input.
Variable Tracker
VariableStartAfter analogReadFinal
sensorValueundefined512512
Key Moments - 3 Insights
Why does the digital value go up to 1023 and not 1000?
Because 10-bit resolution means 2^10 = 1024 levels, counting from 0 to 1023, as shown in execution_table step 3.
What happens if the analog voltage is 0V or 5V?
At 0V, digital value is 0; at 5V, digital value is 1023, the max range of the ADC, as explained in the concept_flow.
Why do we store the ADC value in an integer variable?
Because the ADC output is a whole number between 0 and 1023, which fits perfectly in an int, as seen in variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what digital value corresponds to 2.5V?
A512
B1023
C256
D0
💡 Hint
Check the 'Digital Value (0-1023)' column at step 3 in execution_table.
At which step does the ADC finish converting the analog voltage to a digital number?
AStep 1
BStep 3
CStep 5
DStep 6
💡 Hint
Look for the step where 'Convert voltage' action happens in execution_table.
If the analog voltage was 0V, what would sensorValue be after analogRead?
A512
B1023
C0
D5
💡 Hint
Recall ADC range is 0 for 0V input as explained in key_moments and concept_flow.
Concept Snapshot
ADC resolution means converting analog voltage to a digital number.
10-bit ADC gives values from 0 to 1023.
0 corresponds to 0V, 1023 to 5V (default Arduino range).
Use analogRead(pin) to get this value.
Store result in int variable.
Useful for reading sensors like potentiometers.
Full Transcript
This visual execution shows how Arduino's 10-bit ADC converts an analog voltage into a digital number between 0 and 1023. The process starts with the ADC reading the voltage on pin A0. For example, if the voltage is 2.5 volts, the ADC converts it to about 512, which is halfway in the 0-1023 range. This value is stored in the variable sensorValue and printed to the serial monitor. The ADC resolution is 10 bits, meaning it can represent 1024 levels from 0 to 1023. Zero volts corresponds to 0, and 5 volts corresponds to 1023. This is why the digital value goes up to 1023 and not 1000. The variable sensorValue is an integer because the ADC output is a whole number. This process repeats as the program runs, allowing continuous reading of analog sensors.

Practice

(1/5)
1. What is the maximum value returned by analogRead() on a 10-bit ADC in Arduino?
easy
A. 1023
B. 255
C. 512
D. 4095

Solution

  1. Step 1: Understand ADC bit resolution

    A 10-bit ADC means it can represent values from 0 to 2^10 - 1.
  2. Step 2: Calculate maximum value

    2^10 - 1 = 1024 - 1 = 1023.
  3. Final Answer:

    1023 -> Option A
  4. Quick Check:

    10-bit ADC max = 1023 [OK]
Hint: 10-bit ADC max value is 2^10 minus 1 = 1023 [OK]
Common Mistakes:
  • Confusing 10-bit with 8-bit max value (255)
  • Using 512 which is half range
  • Using 4095 which is 12-bit max
2. Which of the following is the correct syntax to read an analog value from pin A0 in Arduino?
easy
A. readAnalog(A0);
B. digitalRead(A0);
C. analogReadPin(A0);
D. analogRead(A0);

Solution

  1. Step 1: Recall Arduino analog read syntax

    The function to read analog input is analogRead(pin).
  2. Step 2: Identify correct pin notation

    Pin A0 is correctly passed as A0, not using digitalRead or other variants.
  3. Final Answer:

    analogRead(A0); -> Option D
  4. Quick Check:

    Correct function and pin name used [OK]
Hint: Use analogRead() with A0 for analog pin 0 [OK]
Common Mistakes:
  • Using digitalRead(A0) which reads digital value (0 or 1)
  • Using non-existent functions like analogReadPin()
  • Using readAnalog() which is not Arduino syntax
3. Given the code:
int sensorValue = analogRead(A1);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);

If analogRead(A1) returns 512, what will be printed?
medium
A. 1.0
B. 5.0
C. 2.5
D. 0.5

Solution

  1. Step 1: Substitute sensorValue with 512

    voltage = 512 * (5.0 / 1023.0)
  2. Step 2: Calculate voltage value

    5.0 / 1023.0 ≈ 0.004887585, so voltage ≈ 512 * 0.004887585 ≈ 2.5
  3. Final Answer:

    2.5 -> Option C
  4. Quick Check:

    Half of 5V ≈ 2.5V for 512 reading [OK]
Hint: Multiply reading by 5/1023 to get voltage [OK]
Common Mistakes:
  • Using 1024 instead of 1023 in division
  • Confusing sensorValue with voltage directly
  • Rounding errors ignoring decimal precision
4. What is wrong with this Arduino code snippet?
int sensorValue = analogRead(A2);
float voltage = sensorValue * (5 / 1023);
Serial.println(voltage);
medium
A. Division uses integer math, causing voltage to be zero
B. analogRead() cannot read from A2
C. Serial.println() cannot print float values
D. sensorValue should be float, not int

Solution

  1. Step 1: Analyze division in voltage calculation

    5 / 1023 uses integer division, which results in 0.
  2. Step 2: Effect on voltage value

    Multiplying sensorValue by 0 gives voltage = 0 always.
  3. Final Answer:

    Division uses integer math, causing voltage to be zero -> Option A
  4. Quick Check:

    Use float division 5.0/1023.0 to fix [OK]
Hint: Use decimal points for float division (5.0/1023.0) [OK]
Common Mistakes:
  • Ignoring integer division effect
  • Thinking analogRead can't read A2
  • Believing Serial.println can't print floats
5. You want to measure a sensor voltage that ranges from 0 to 3.3V using Arduino's 10-bit ADC with 5V reference. Which formula correctly converts the ADC reading to the sensor voltage?
hard
A. voltage = reading * (3.3 / 1023.0);
B. voltage = reading * (5.0 / 1023.0);
C. voltage = reading * (3.3 / 1024.0);
D. voltage = reading * (5.0 / 1024.0);

Solution

  1. Step 1: Understand ADC reference voltage

    The ADC measures voltage from 0 to 5V (reference voltage).
  2. Step 2: Calculate voltage from ADC reading

    Since ADC max is 1023, voltage = reading * (5.0 / 1023.0).
  3. Step 3: Sensor voltage range consideration

    The sensor outputs 0-3.3V, but Arduino reads 0-5V range, so conversion uses 5V scale.
  4. Final Answer:

    voltage = reading * (5.0 / 1023.0); -> Option B
  5. Quick Check:

    Use ADC reference voltage (5V) for conversion [OK]
Hint: Always scale by ADC reference voltage, not sensor max voltage [OK]
Common Mistakes:
  • Using sensor max voltage instead of ADC reference
  • Using 1024 instead of 1023 in denominator
  • Confusing sensor output range with ADC range