Go Down

Topic: arduino mega: use analog pins as digital? (Read 5 times) previous topic - next topic


Hey is it possible to use the analog pins as digital pins, and if yes, what numbers are they addressable at?

And if not, got any suggestions for how to fake it?



Just out of interest....

What project are you wanting to use more than 54 digital pins on?

Everyone..... Steve's building a spaceship from an arduino!!! :P

But on a more serious note. I presume that like on the other arduino boards, you just number them following on from the last number of the digital pin. for example if the last digital output is numbered 54 then the analog pins would be 55 (analog 0) 56 (analog 1) 57, 58 and so on...

Please elaborate on what you are wanting to do with all of these pin s because I'm interested now!



May 29, 2009, 11:36 am Last Edit: May 29, 2009, 11:37 am by stevecooley Reason: 1
i wont go into too much detail, its way past my bedtime on a work day...


I would recommend shifting the 10 analog pins up 3 and putting the analog(digital) pins at numbers 0,1,2 and then I would have thought that if you number them to the 'next' theoretical digital pin number (is it 45 onwards?) then it should work like on the other arduino boards.

I would recommend trying it with something simple such as an LED blink on analog pin 0 (set as "int ledPin = 45" or similar).



I am also thinking of getting an arduino mega just to make some coding much simpler and avoid the use of any extra boards so it would be great if you can use those analog pins as digital pins.

btw... interesting project, I would recommend that you post it up when you have finished it - looks great!


You can also do direct port manipulation on these pins as well they map to the F and the K ports. It is one of the few ports that you get a straight run at so if you need to interface any 8 bit wide devices you can do it with these ports.

Port         Pin     Function
PF 0       54       A0
PF 1       55       A1
PF 2       56       A2
PF 3       57       A3
PF 4       58       A4
PF 5       59       A5
PF 6       60       A6
PF 7       61       A7
PK 0       62       A8
PK 1       63       A9
PK 2       64       A10
PK 3       65       A11
PK 4       66       A12
PK 5       67       A13
PK 6       68       A14
PK 7       69       A15


Ok, so can I do something like hook V+ to one side of a pushbutton, and the other side to analog 11 on an arduino mega, and then run this type of code:

Code: [Select]

int pinValue;

void setup(){

pinMode(65, INPUT);

void loop(){

if(digitalRead(65) == HIGH)
pinValue = 1;
pinValue = 0;



Anyone? :) Is it possible to use analog pins on the arduino mega as digital pullup pins? I'm using the awesome hardware abstraction library for buttons for the rest of my project, and it would be super nice if it were possible to use analog pins as pullup digital pins, but so far it doesn't appear that arduino mega can do that, or I don't know how to do it.  I would Love some input... I do know which pin numbers to address them as, but is there some hardware limitation that prevents the analog pins from working as pullup digital?


The Mega analog pins (as digital pins 54-69) do have pull-up resistors. Did you actually try to use them as digitial inputs? You may want to say more about what you tried and the results of your tests


I did indeed try using them as pullup digital inputs, thank you for asking me to clarify, I will be happy to do so in pursuit of knowledge on how to do this correctly. Perhaps I need a wiring diagram to explain how I did what I did and what the results i was expecting, and then the results I got.

This is currently how my circuit is wired up:

and I'm only using the diagram as a loose translation of how it's wired.  I am actually paying attention to which pin is connected and which pin is addressed in my code. I do realize that the diagram appears to be pointing at analog 0, which would be digital 54.

I was expecting to be able to address the analog pin as a digital input and use it like I am successfully addressing 20 other tact inputs on my project using the digital pins. (16+4 as seen in above posts)

I was hoping to use the Button HAL http://www.arduino.cc/playground/Code/Button for this implementation, but if I can't no big deal, I'd love to understand how I can do this the regular way if the HAL can't do this for this hardware in this instance.

The results I got was that it doesn't appear to be sending current out to let the switch complete the circuit to ground.  Am I totally missing the point or misusing the terminology?  I'm one of the horde of untrained enthusiasts.  When I use the digital pins with the Button library, I have them connected to the digital pin and to ground, and then I address them as PULLUP and they work like a charm.


Try one of the simple button tutorials that directly set the pinMode and pull-ups (changing the pins numbers as needed). There may be something in that library that is not working with the Mega.


Don't forget to add series resistors when driving LEDs with digital output pins, otherwise pin damage will result.



Hey, so I know in theory I should be running resistors to my LEDs, but... in practice I'm just not seeing a short or medium term problem with skipping them.  What kind of timeframe do you think I can expect to start to see some kind of adverse reaction to running my LEDs like this?  I just haven't had problems doing it like this with the arduino.  This certainly simplifies the prototyping process to not have to worry about it... and I appreciate that quite a bit.  I can spend more time working on the parts of my project that actually are hard to figure out...

FYI, here's a couple of videos of my project at work:


Still early days... lots of room to complete the full feature set that I have envisioned, but it's usable today...  :)


do you think I can expect to start to see some kind of adverse reaction to running my LEDs like this?

Yes, very risky with a good chance of burning out the AVR chips output pin. The pin has a max current rating of 40ma and without a current limiting resistor to a LED you have no control of how much current will flow through the LED.

From the Arduino playground section:

Important Note!

While LEDs will not work when placed backwards, you don't have to worry about whether it will be damaged: as long as there is a series resistor of at least 100 ohms next to it, the LED will survive the experience!

However, using an LED without a series resistor is a sure-fire way to kill it! (You'll see a bright flash and it may turn dark)
Always use a resistor! A 1.0K ohm is a good place to start. We'll cover how to figure out the best resistor value later on.



Jun 12, 2009, 09:58 am Last Edit: Jun 12, 2009, 10:04 am by stevecooley Reason: 1
welp, that's what beatseqr version 2 is for, I guess. I'm glad all I need is 100 ohms, because the brightness on these LEDs is right at the edge of being too hard to see in bright ambient light. Fortunately, I do all of my best work in a cave-like environment, so no problems there.

Go Up