None of the Analog Read Examples are working with 2560

retrolefty:

rgPaiva:

retrolefty:
Well the picture doesn't tell us if you correctly identified the pot's wiper terminal to wire to the analog input pin. You should take a multimeter voltage reading from ground to the input pin to see if the voltage does change from 0 to +5vdc as you move the pot's know through its range. Also 110K ohm pot is awful large value, analog input pins work best with 10k ohm or less of source impedance.

Lefty

I correctly identified the pot's outputs, because i tested it on the arduino uno today , and it worked perfectly, the same code, all works fine with uno but not with this mega 2560.

I can only tell you how I would approch troubleshooting this symptom. I would first take a meter and measure the actual voltage applied to the pin and see if it tracks with turning of the pot. That would give me a good indication to next look at wiring or the sketch code. If you don't own a meter you should get one soon, as anyone building even simple projects using an arduino should.

Lefty

While the pot was connected(it was connected right) to the arduino , i used a meter to measure the voltage in the pot, while i changed the resistance value, but the output of the pot was at 5 v all the time...

And when you disconnected the wiper from the input, and measured the voltage on the wiper..?
And when you tried a different input..?

rgPaiva:

retrolefty:

rgPaiva:

retrolefty:
Well the picture doesn't tell us if you correctly identified the pot's wiper terminal to wire to the analog input pin. You should take a multimeter voltage reading from ground to the input pin to see if the voltage does change from 0 to +5vdc as you move the pot's know through its range. Also 110K ohm pot is awful large value, analog input pins work best with 10k ohm or less of source impedance.

Lefty

I correctly identified the pot's outputs, because i tested it on the arduino uno today , and it worked perfectly, the same code, all works fine with uno but not with this mega 2560.

I can only tell you how I would approch troubleshooting this symptom. I would first take a meter and measure the actual voltage applied to the pin and see if it tracks with turning of the pot. That would give me a good indication to next look at wiring or the sketch code. If you don't own a meter you should get one soon, as anyone building even simple projects using an arduino should.

Lefty

While the pot was connected(it was connected right) to the arduino , i used a meter to measure the voltage in the pot, while i changed the resistance value, but the output of the pot was at 5 v all the time...

Sounds like the ground end of the pot isn't connected correctly to arduino ground, or bad wire connection, bad pot terminal, or something of that manner. If you measure only +5vdc on the pin then your software will only read values of 1023.

retrolefty:

rgPaiva:

retrolefty:

rgPaiva:

retrolefty:
Well the picture doesn't tell us if you correctly identified the pot's wiper terminal to wire to the analog input pin. You should take a multimeter voltage reading from ground to the input pin to see if the voltage does change from 0 to +5vdc as you move the pot's know through its range. Also 110K ohm pot is awful large value, analog input pins work best with 10k ohm or less of source impedance.

Lefty

I correctly identified the pot's outputs, because i tested it on the arduino uno today , and it worked perfectly, the same code, all works fine with uno but not with this mega 2560.

I can only tell you how I would approch troubleshooting this symptom. I would first take a meter and measure the actual voltage applied to the pin and see if it tracks with turning of the pot. That would give me a good indication to next look at wiring or the sketch code. If you don't own a meter you should get one soon, as anyone building even simple projects using an arduino should.

Lefty

While the pot was connected(it was connected right) to the arduino , i used a meter to measure the voltage in the pot, while i changed the resistance value, but the output of the pot was at 5 v all the time...

Sounds like the ground end of the pot isn't connected correctly to arduino ground, or bad wire connection, bad pot terminal, or something of that manner. If you measure only +5vdc on the pin then your software will only read values of 1023.

The pot is fine , i tested it on UNO, works perfectly. I connected the Pot terminals even at solder in the back of the board. NONE of the analog ports is working,but the DIGITAL are okay.

The pot is fine , i tested it on UNO, works perfectly. I connected the Pot terminals even at solder in the back of the board. NONE of the analog ports is working,but the DIGITAL are okay.

While the pot was connected(it was connected right) to the arduino , i used a meter to measure the voltage in the pot, while i changed the resistance value, but the output of the pot was at 5 v all the time...

Well you are going to have to figure out why you only measure +5vdc at the pot's wiper pin output wired to the analog input pin, even when you turn the knob through it's range. The fact that you only see +5vdc applied to the analog input pin needs to be fixed before you can expect the 2560 board to read the pots value.

Lefty

Have you tried replacing

  int sensorValue = analogRead(A0);

with

  int sensorValue = analogRead(0);

I don't have a Mega to hand to test what A0 compiles to (its definitely done different in Arduino 1.0 from earlier Arduino softwares - I can't find the definitions in 1.0). Perhaps its broken for Megas? Sounds a bit unlikely though.

It sounds like your pot is hooked up wrong or something electrical is wrong with the Mega since you said the Uno works.

Did you try running the A0 pin straight to ground? Just to see if the Mega will report back 0? If that works take the wire out of A0 completely and see what the results are. 'Normally' you get fluctuating values. If it comes back as 1023 there is a problem.

Denbo:
It sounds like your pot is hooked up wrong or something electrical is wrong with the Mega since you said the Uno works.

Did you try running the A0 pin straight to ground? Just to see if the Mega will report back 0? If that works take the wire out of A0 completely and see what the results are. 'Normally' you get fluctuating values. If it comes back as 1023 there is a problem.

I already did it, but it only shows 1023...

Even grounded?
Sounds like a short somewhere, but if you ground it, I'd expect that to short the supply.
Can you post your actual code, not the stuff you posted in reply #2.

AWOL:
Even grounded?
Sounds like a short somewhere, but if you ground it, I'd expect that to short the supply.
Can you post your actual code, not the stuff you posted in reply #2.

But i am using only the examples that come with arduino ide, the only thing that i change is the port....

The only way to guarantee reproducing a problem is to run the exact same sketch on the exact same hardware - otherwise you could chase red-herrings for hours.

rgPaiva:
I already did it, but it only shows 1023...

So you are saying that even running a wire from A0 to ground you are getting 1023? Are you connecting a wire from A0 to the GND port on the Mega directly?

If so something is wrong. Even if there is a short running it directly to ground should bring it down.
Is your Mega sitting on top of a metal table or something? There are no shields installed right?

Denbo:

rgPaiva:
I already did it, but it only shows 1023...

So you are saying that even running a wire from A0 to ground you are getting 1023? Are you connecting a wire from A0 to the GND port on the Mega directly?

If so something is wrong. Even if there is a short running it directly to ground should bring it down.
Is your Mega sitting on top of a metal table or something? There are no shields installed right?

Yes i connected a wire from A0 to GND directly too, and tried the ReadAnalogVoltage program, but it shows only 5v. And i havent tried the 54 digital pins , only the pwn outputs, but i think the problem is with the ATMega2560 ;/. And it doesn't have any shield on it, and i am using it on wood table.

rgPaiva:
Yes i connected a wire from A0 to GND directly too, and tried the ReadAnalogVoltage program, but it shows only 5v. And i havent tried the 54 digital pins , only the pwn outputs, but i think the problem is with the ATMega2560 ;/. And it doesn't have any shield on it, and i am using it on wood table.

What about the other analog pins? Did you try A1-A5?

And i havent tried the 54 digital pins , only the pwn outputs

This phrase worries me.
What have the PWM outputs got to do with the problem here?

AWOL:

And i havent tried the 54 digital pins , only the pwn outputs

This phrase worries me.
What have the PWM outputs got to do with the problem here?

Sorry it was the digital 9 next to the pwm. I used the digital pin 9 to the example AnalogInOutSerial, but the led got the 5v all the time.

Sorry it was the digital 9 next to the pwm. I used the digital pin 9 to the example AnalogInOutSerial, but the led got the 5v all the time.

You're on the wrong side of the board. The PWM pins are output only. Reading an analog value is done on the analog pins. The ones on the other side of the board.

PaulS:

Sorry it was the digital 9 next to the pwm. I used the digital pin 9 to the example AnalogInOutSerial, but the led got the 5v all the time.

You're on the wrong side of the board. The PWM pins are output only. Reading an analog value is done on the analog pins. The ones on the other side of the board.

Yes... and thats why i used the AnalogInOutSerial example that come with arduino 1.0 ide. Using the led at port 9...

Using the led at port 9...

What does that have to do with the failure to read proper data from an analog pin that you hadn't connected the pot to?