Trouble with Mega Anolog in port.

The Arduino Mega has Anolog inputs number 0 to 15.
I am using Analog inputs 0 to 9.
I am able to read analog inputs 0 to 7 with no problems,

I am having difficulty reading Anolog inputs 8 and 9.
When I put a low (o volts ) on these pins, they still show values of 1024 or 1023 rather than 0 as expected. It as if they are not set up properly to inputs.

I use the following statement to read the Analog in pins 0 thru 9:

int samples[11]; // array to hold the analog values read
int i =0;
do {
samples = (analogRead(analog_in);

  • i++;*
  • } while (i <10);*
    What am I doing wrong here? .
    *Do I need to do anything to the Data Direction Regiesters related to Analog pins 8 and 9??? *

Well I have an Seeeduino Mega clone. I had tested all the digital I/O pins when I first got it, I just tested the first few analog input pins at that time.

Seeing your posting I tried testing all 16 analog input pins and I too seem to only be able to read analog pins 0-7. Analog pins 8-15 just seem to have random noise readings.

Using version 17 on a XP pro SP3

Anyone else with a Mega tried to do analog input readings from pins A8-A15?


Well I tried reading analog input pins 8 - 15 on version 16 and it seems to work. So perhaps this is just a Arduino version 17 bug?


Thanks Lefty. Following your suggestion , I tired version 16 and all my analog pins work fine. Guess Arduino 17 has a bug. I'm going back to Arduino 16 for now.

Sorry guys, this will be fixed in Arduino 0018. In the meantime, you can edit hardware/cores/arduino/wiring_analog.c and change:

ADMUX = (analog_reference << 6) | (pin & 0x0f);


ADMUX = (analog_reference << 6) | (pin & 0x07);

(The change should take effect automatically next time you compile or upload a sketch.)

Thanks, fix works fine.


Great. The fix worked like a charm. Much appreciated.


I’m currently working on a big project involving one arduino nano and one arduino mega in combination with a max/msp patch.
The electronic connected to the arduinos are just knobs, switches and leds and I have to use almost all digital i/o and all analog inputs.

I previously worked with the duemilanove and naively supposed the nano and mega would work without problems.

For the nano (v2.3 w/ ATmega168) I use the latest StandardFirmata (v2.1b3).
Everything works as expected except that analogRead just gives me noise on the analog input 6 and 7.

For the mega (ATmega1280) I thought StandardFirmata would work but it doesn’t
(just trying to switch a led on pin 13 requires calling a digitalWrite on pin 15 ???)
so that I’m trying to write my own eeprom firmware.
Everything is fine concerning the digital i/o.
But I can get anything out of the analog inputs.
I tried the previous fix with Arduino 0017, I also tried with Arduino 0016.
No results.

All I get is :

noise when the analog pin is not connected, that’s fine.
0 when the pin is connected to ground, that’s fine too.
1023 and only 1023 when the pin is connected to the knob
(220k, analog pin on the middle of the knob, +5v on one side of the knob ← this work perfectly with the nano and the duemilanove)

Has anyone any idea of what could be going on ?
I really need to fix this quickly.



Thanks for the fix. Nice to know the problem wasn't me for a change.