Question

So my problem is as title says: Arduino UNO analogRead always returns 1023.

But when I burn the same sketch in Arduino Mega 2650 everything works like a charm.

I have tried to change Atmel chips on the UNO, have tried like 3 of them (ATMEGA328P-PU) and nothing changes.

I'm trying to count signals from a hall effect sensor and display the count on a 7 segment display.

Here is the code:

#include "SevSeg.h"

SevSeg sevseg;
volatile int rpmcount;

void setup() {
  Serial.begin(9600);
  pinMode(2,INPUT_PULLUP);
  rpmcount = 0;
  sevseg.Begin(1,3,4,5,6,7,8,9,10,11,12,13);
}
int border=15;

void loop() {
  int tmp=0;
  tmp = analogRead(0);
  if(!digitalRead(2))rpmcount=0;
  Serial.println(tmp,DEC);
  if(tmp<=border && res >border){   
    rpmcount++;
    if(rpmcount>9999)rpmcount=0;
  } 

  res=tmp;
  sevseg.NewNum(rpmcount,(byte) 0);
  sevseg.PrintOutput();
}

Any help would be much appreciated

Was it helpful?

Solution

This sounds to me as if you had the internal pullup resistor on the ADC pin enabled.

generic checklist:

  • ACD bit in ACSR is 0 (comparator enable)
  • MUX bits in ADMUX set properly
  • correct AREF selected
  • ADC pin set as input
  • internal pull up resistors are deselected
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top