AnalogRead on Mega not responding

Hi,

Is there something diffrent between UNO en MEGA on the AnalogPins?

While connecting an LDR on UNO (A0) the SerialPrint nicely returns lower values if LDR is in the dark.

When i try to connect the same wiring to the MEGA on pin A0 it just returns 1023.

Why is that? is There something wrong with the analogPins on my Mega?
Please help. Can't find anything online with simular problem.

When i unplug all pins and just read the A0 the value serial print returns is 1023.
If i plug the A0 directly to ground the value is 1023. (All other pins unplugged). This should be 0 (zero) right?

if i plug the A0 directly to VCC the value returns is 1023.

Simple code used on both boards:

  const int crashPin1 = A0;

void setup() {
    pinMode(A1, INPUT);
    Serial.begin(115200);
}

void loop() {
    Serial.println(analogRead(A0)); 
}

wiring like this:

tnx
N

There appears to be a mismatch between your pretty picture and the code. Which analog pin are you using ?

i have tried and used all of them one by one (in the code too)
Still same result. :confused:

I think you should plug it in to A1 to match your code.

You talk about using a Mega but your f*ing diagram shows an UNO.
Can you post a picture of your hardware?

It is a mega 2560.
With the picture i just tried to avoid questions about the wiring.

I have an UNO too. And with the uno analog pins and with same wiring/code analog pins work fine.

Could it be that something is damaged on the MEGA or is there a difference between the analogpins on the mega and the uno?

Is there an other way to analog-read LDR on the MEGA. Without using the analog pins?

You could add an external DAC but yeahhh.

And did you use the Mega before?
Can you try to connect it to GND and Vcc, what do you see then?

Be sure to match the program and the connection when you do :wink:

Kumalix:
When i unplug all pins and just read the A0 the value serial print returns is 1023.
If i plug the A0 directly to ground the value is 1023. (All other pins unplugged). This should be 0 (zero) right?

if i plug the A0 directly to VCC the value returns is 1023.

Show us a good image of your wiring.

There is a mismatch between what is set as an INPUT and what you are printing to the serial port.
I'm not sure if there is a difference in the default pinModes between the Uno and Mega, but that could also contribute to your problem.

const int crashPin1 = A0;

void setup() {
    pinMode(A0, INPUT);    // not A1 as in previously posted code 
    Serial.begin(115200);
}

void loop() {
    Serial.println(analogRead(A0)); 
}

pinMode() sets only the digital state and is useless in analog.

But are you 100% sure, after all the mixing, you use the same pin in hardware as you do in software?

I know guys i understand your point but i'm not that new to arduino :wink: .

I'm 100% sure i use the correct analog-pin in hardware as in software!

On the Uno there is no problem only on the mega.

I have check the correct hardware/ software pin 50 times by now.
Went one analog pin by one from A1 -> A15 (and corrected te code to mach the wired pin.
Don't know whats wrong. Maybe i just need a new Mega. even though this one is 1 month old.
:confused: :confused:

Toggle the pin(s) HIGH and LOW in a simple sketch and check with a voltmeter (or LED etc) for any activity.

Kumalix:
I know guys i understand your point but i'm not that new to arduino :wink: .

I'm 100% sure i use the correct analog-pin in hardware as in software!

On the Uno there is no problem only on the mega.

I have check the correct hardware/ software pin 50 times by now.
Went one analog pin by one from A1 -> A15 (and corrected te code to mach the wired pin.
Don't know whats wrong. Maybe i just need a new Mega. even though this one is 1 month old.
:confused: :confused:

Show us a good image of your wiring.

If you are still having problems:

  1. try reversing the black and red wires as shown in your OP to see if the analog read now yields a value of 0 instead of the 1023. If so, suspect that the resistor has an open circuit.

  2. replace the ldr with a resistor of the same value as the existing resistor (10K ? ) and see if the analog reading is now about 512.

  3. disconnect the red, black and yellow wires from the arduino and measure the resistance between the red and the black wires. The value of the resistance should change according to the ambient light.

i have tried using only a potentiometer and reading the pin.

Same result. On the UNO i can change the analog values with the potentiometer.
On the MEGA nothing... only 1023.

Don't understand except some kind of damage on the MEGA???
:confused: :confused:

If it looks like a duck, quacks like a duck, it is a …

Show us a good image of your wiring.
Oh, guess this was asked for already.

Kumalix:
If i plug the A0 directly to ground the value is 1023. (All other pins unplugged). This should be 0 (zero) right?

Yes, unless the wire is broken, or you route it over some breadboard with bad pins or interrupted power rails.
We need to see a REAL picture of the setup, and very simple/short code that you use with it.
99.99% of problems here is user error.
Leo..

septillion:
And did you use the Mega before?

And in extend to that, did you (possibly) messed up the connection before?

And as a final check to see if the ADC is dead you can try to read back Vref or GND selected via software. MUX bit pastern 011110 and 011111.

Try using 0 instead of A0...