How many switch and led can be on Arduino 2560

Hello,

I’m a new dummy here and I’m sorry if my question is stupid :frowning:

I would like to know :

  • how many simple switch (just switch button pressed detection) could I’ve in the 2560.
    And, on same time
  • how many simple led.

My objective is to have a maximum groups of 2 led + 1 switch by set (around 60 sets)

I’ve read it could be added hardware to my Arduino card to have more leds and switch. Did you have information, link, advice please ?

In all case, thanks for your read (and help)
Cheers
Matthis

Without using a matrix keyboard or charleplexing every switch and led needs a separate pin. So for Arduino Mega with it 54 pins you can connect 54 switches and leds in total.
But using a 8x8 matrix you need only 16 pins to manage a 64 switches. And using an addresable leds you need ONLY ONE pin to control a hundreds leds

1 Like

If you run out of pins you can add pin expanders like the MCP23S17 (16 bits, SPI) or MCP33107 ( 16 bits, I2C). 2 or 3 pins to control up to 128 GPIO pins.

A single MAX7219 can control 64 LEDs using 3 pins.

There are also shift registers that can control or read many pins using 3 or 4 pins.

So the maximum number of pins for switches and LEDs is virtually unlimited using external parts.

2 Likes

Hello Brattain and b707,

Thanks for your reply !!!

But using a 8x8 matrix you need only 16 pins to manage a 64 switches.

I understood how to make that, perfect !!

And using an addresable leds you need ONLY ONE pin to control a hundreds leds

Did you have an exemple please, not so clear for my little knowledge :confused:

I’ve understood i need to add a board to my Arduino card. Could you advice me the card I can purchase on internet and I can simply connect to my Arduino ?
Remember, I’m à Newbit and really a Dummy in électronique :rofl::joy::crazy_face:

Thanks a lot,
Cheers
Stef

No hardware needed, you have a mega. What has been described could be done with a Nano(8 inputs, 8 outputs for keyboard, use the rest of the outputs for Neopixel strings).
On your mega, dedicate 2 8-pin sets for rows and columns of the 64 key matrix.
The LEDs can be all one string(128), but it will probably work out more usefully to have them in 8 strings of 16.
Read up on Neopixel, and key matrix scanning, here on the forum and in the examples, Tutorials, etc. and come up with a description of an initial system, and a first attempt at code for just the keyboard, then ask for advice here - keep adding to this topic, for continuity, please.

1 Like

Perfect, thank to all of you !!!!!!!!

Hello,

One other questions please :

  • is the switch consuming power ?
  • is my Arduino card could support 64 leds (leds are 20 power) ?

Could I use only usb to make that ?

Thanks a lot
Cheers
Stef

What the meaning of this "20 power" ? Do you mean that every led comsume 20 mA power ? Or that only 20 leds will be lit at the time?

@matthisfr You indicated this was solved, but the way I read your latest posting, you're thinking individual LEDs, not Neopixel. Either way, be aware that you should not power a significant number of LEDs, or Neopixels, from the 5V available on the Mega. Buy or find a decent 5VDC power supply with current output about 1.5x the expected worst case current of your LEDs. For example, if you have 30 LEDs at 20 mA, that's 600 mA, so locate a 5V, 1A supply to power them. When you do this, be sure to reference(connect) the (-) side of the 5V supply to the Arduino ground, and you'll be good to go.

1 Like

Switches do consume a small amount of power because of the internal pullup resistors. Use Ohm's law to calculate the amount. Internal pullup resistors in the Mega processor are 30K to 50K so current is (at 5V) 0.16mA to 0.1mA.

2 Likes

Thanks, perfectly clear !!!

What’s appends if my led get more énergie than my usb provide ?
Irreversible damage ?
Or
Simply no light ?

Cheers
Stef

In the case of most power supplies, including USB, almost always built-in self-protection circuits act to protect the source. Take note of the "most" and "almost" weasel words in that statement, because it's certainly possible for damage to occur, but most likely just erratic, or no operation at all.
The worst case is when your circuit and software work well while driving only a few LEDs, then your code has reason to energize more, and suddenly your device hiccups, or shuts down, and you spend hours trying to find the software bug when in fact you're chasing an intermittent overload. Better to avoid that through good design.
Also bear in mind, the simple regulation circuits used on the Nano/Uno/Mega do not have protection circuits, and it is quite feasible to draw too much current from them and damage the regulator in that case. So, again, use an external supply for significant loads, and let the onboard regulators loaf along taking care of just the Arduino's own needs.

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