Sensor value jumps about, or stays at 0 or 1023

  • LDR
  • Soil sensor
  • Gas sensor
  • Potentiometer
  • LM35

Why it happens

  • The wire is on another analog pin, or loose.
  • An LDR has no second resistor to make a divider.
  • The sensor isn't powered, or VCC and GND are swapped.

How to fix it

  1. Check the pin: A0 in the code, A0 on the board.
  2. LDR: one leg to 5V, the other to A0 and to a 10 kΩ resistor to GND.
  3. Print the value with Serial.println(analogRead(A0)); and change only the sensor.
  4. Average ten readings if it only flickers a little.

It worked if: Cover, wet or turn the sensor: the number moves smoothly one way.

From how the part works. Explained from how the part works; not tried on a real circuit for this page.

Didn't help? Search another error or ask us.