Arduino Mega 2560 Reading 5 V DC on Analog input

I am doing a simple thing to check. Connected 5 V power from the Arduino board to the Arduino A0 pin. I am doing no conversion in my code. Just measure the input bits. I should be reading 1023 all the time. But I am wrong. Occassionally it reads 1023 and rest of the time toggles around 300. I am surprized. What could be wrong. I also measured the 5 V dc on a multimeter. It is correctly producing 5 V.

enter image description here

Can you share your sketch (using code tags)?

Post a schematic, too, please. Show how the 5V is connected to the input and the source of the 5V.

Without seeing code and a schematic I can only guess that the grounds are not connected.

Guess what. I just identified my mistake. It was due to wrong variables. I rectified it and I read 1023 continuously.

Thanks a lot for asking me share the code. While copying here, I identified the mistake. Anyhow I am copying the same here:

// LED pin

int ledPin = 13;

// Analog-input pin to receive Rain guage signal 

#define sig_rain A0

// Define a variable
float sig_Rain = 0; // Rain guage sensor variable

void setup ()

{

  Serial.begin(9600);   

  // Turn off onboard LED off

  // initialize the digital pin as an output.

  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, LOW);   // turn the LED on (HIGH is the voltage level) 

  Serial.println("Rain_guage_signal");

}

void loop ()

{
 // Read the data
  sig_Rain = analogRead(sig_rain);//*5.0/1024.0;

  // Print the raing guage 

  Serial.print(sig_Rain,4);Serial.print(",");

  //delay(1000);

  Serial.println();  

}

Also, the pic:

enter image description here

Nice.

(Pssst: NEVER show a non-Arduino brand board!)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.