Go Down

Topic: Multiple switch with multiple Leds (Read 270 times) previous topic - next topic

NimaRezaie

Hi
I've got a problem with my arduino project. I want to make a circuit with 10 switches and 10 Leds and when I press the first switch, I want the the third led to light up and when I press the first switch again, I want another led like the sixth one to light up and so on for the other witches and leds. I want to switch between all the leds for each of the switches.
Could you please tell me how to wire these on a breadboard and code them on arduino?

meltDown

#1
Aug 16, 2019, 02:07 pm Last Edit: Aug 16, 2019, 02:08 pm by meltDown
Leds wired as normal from a digital pin to ground with a series resistor, pinMode()-ed as output

Switches wired as normal from a digital pin to ground with a pullup, ie pinMode()-ed as input_pullup.

If you have a Uno, that will need all your pins, including 0 and 1 which are also needed to upload the code.

Before you get too involved in this, have a look at how pins can be managed with arrays, else this will rapidly become a pitfa.

Quote
I want to switch between all the leds for each of the switches.
Randomly or according to some defined sequence?



NimaRezaie


meltDown

If you're very new to Arduino you should work through the examples which ypu can also access in the IDE at File > Examples.




NimaRezaie

Actually I'm very new to Arduino. Thank you for your help!

meltDown

#5
Aug 16, 2019, 02:18 pm Last Edit: Aug 16, 2019, 02:18 pm by meltDown
Quote
I'm very new to Arduino.
My advice then: leave the project on the back-burner for a while, while you find your feet. Of course, if you keep the project in mind, as you work through the examples you will have a few Aha! moments, so mentally bookmark the things that look useful... but don't get into the actual project too early. YMMV.




NimaRezaie

Got it! Thank you so much for your help again!

NimaRezaie

Just another question. Can I do this with 26 Switches and 26 Leds? Will there be enough place to wire them onto?

meltDown

Quote
Can I do this with 26 Switches and 26 Leds?
Not on a Uno which has 20 pins, unless anyone suggests some kind of multi-plexing approach which is above my pay-grade.

Look at a Mega, which has something in the 50s, I forget the actual number.



NimaRezaie


septillion

Yes and no.

Yes you can do this.

No, you can't do this with just an Uno and straight connections to leds/switches

Yes, you could do this with something like port expanders. Would say that's a cleaner approach than a  Mega.

Yes, alternatively you could multiplex everything.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

NimaRezaie

Yeah. As meldown said I have to use a mega. Thanks for your help.

CrossRoads

Mega2560 has 70 IO pins that can be used for inputs & outputs.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

NimaRezaie


Paul__B

#14
Aug 17, 2019, 12:56 am Last Edit: Aug 17, 2019, 12:56 am by Paul__B
Yeah. As meldown said I have to use a mega. Thanks for your help.
No, you do not at all!

Megas are cumbersome things, and unnecessarily expensive.  In fact, UNOS are a poor form factor for projects such as you are formulating, Nanos a much more useful form or if the project will never require re-programming, a Pro Mini.

If indeed, this is only about switches and LEDs, the answer is to use matrix arrays and multiplexing.  Twelve pins can connect a 6 by 6 array of 36 LEDs or switches.  An extra six pins can allow you to have 36 LEDs and 36 switches which is still in the ATmega328 format.  There are some constraints; you must be able to wire the switches and LEDs into an array, if you want to press more than two buttons at a time (and know exactly which are pressed) then you need a diode for each button and if you want more than one LED lit at a time there might be brightness constraints but adding a cheap LED driver (MAX7219 module) would allow you to illuminate up to 64 LEDs brightly.

Yes, the coding gets more complex but that is why we are here.  :smiley-lol:

Now, please explain the essential purpose of your project and we can provide better advice.  :smiley-eek:

Go Up