Skip to content

Arduino analogRead Returns 1023 Always

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about Arduino analogRead Returns 1023 Always. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

analogRead() always returns 1023 (max value) regardless of input voltage.

Quick Fix

Wrong

int val = analogRead(A0);  // A0 is floating
val == 1023 (floating pin reads HIGH).
int sensorPin = A0;
void setup() {
  Serial.begin(9600);
  // No pinMode needed โ€” analog pins default to input
}
void loop() {
  int val = analogRead(sensorPin);
  float voltage = val * (5.0 / 1023.0);
  Serial.print("ADC: ");
  Serial.print(val);
  Serial.print(" Voltage: ");
  Serial.println(voltage);
  delay(500);
}
ADC: 512 Voltage: 2.50  (varies with input).

Prevention

analogRead() returns 0-1023 (10-bit) on AVR. A floating analog pin reads random or max values. Always connect a signal source. The reference voltage is 5V by default (change with analogReference()). The ADC reading settles faster if the source impedance is under 10 kOhm.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What is the reference voltage?

5V on Uno/Mega (AREF pin connected to VCC by default). Use analogReference(INTERNAL) for 1.1V internal reference on AVR for better resolution on low-voltage signals.

How long does analogRead take?

About 100 ยตs on 16 MHz AVR (prescaler 128). This limits the max sampling rate to ~10,000 samples/second.

Can I read negative voltages?

No. The ADC only measures 0V to reference voltage. Use a voltage divider or op-amp level shifter for negative or higher voltages.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro