How to command 512 distincts outputs from an arduino uno?

Hi,

I'm starting a new project on which I need to command 512 leds (On/Off).

I want to be able to pass a decimal number (n) as a variable to the arduino Uno to command the (n)th led associated.

Eg:
int n = 512; => I would like to switch on the 512th led only.
int n = 114; => I would like to switch on the 114th led only.

I thought of converting the decimal number "n" as a 10 bits binary number, so at this point, I can command 10 leds :

Eg :

int n = 1;
// Converted as a 10 bits binary with a function :
int binary[] = {0,0,0,0,0,0,0,0,0,1}; // So only the right led will switch on

int n = 512;
int binary[ ] = {1,0,0,0,0,0,0,0,0,0};

I know this is possible using logical gates, but just for the matter of switching on the first led only when I have {0,0,0,0,0,0,0,0,0,1}, I needed 11 NPN transistors... (To build the AND and NOT gates).

Because obviously, I wanted the first bit to be switched on, and nothing else.

So for 512 leds, connected to their corresponding bits sequences I'm afraid I will need so much transistors, and also what a fastidious job to solder everything together...

So I would like to ask you if there is any electronical component (Or schema) that I could use to convert a 10 bits sequence to its corresponding output.

In summary : I pass 512 as an int to arduino, it converts to 1000000000, then the 512th output receive current and switches on the 512th led.

NB: I would like to apology because English is not my native language, and I'm also a noob in electronics if that question sounds dumb to you.

Anyway, thank you very much to anybody that could help me on this

That's a difficult and painful way to control 512 LEDs!

Have you considered using "neopixel" LEDs like ws2812 or apa106? You can then string 512 LEDs together and control them with a single Arduino digital output. You may think this type of LED is expensive compared to normal 5mm single colour LEDs, but consider the circuits you will need to design and build for your idea, and your time doing that.

If you must use normal single colour LEDs, I would suggest using 2x ht16k33 chips or 4x max7219 chips.

Hi Paul,

Thank you so much for your answer, it sounds like a great idea!

I don't think neopixel LEDs would fit to my project, because what I would like to end with, would be replacing the LEDs by electromagnets...

In fact, to be more precise about what I want to achieve :
I would like to make paths with electro magnets, and guide a piece of metal from A to B, or B to A or D to E... etc...
And that by switching on and off magnets one after the other, sending a the list of indexes corresponding to the magnets to switch on/off consecutively...

So I actually need just one magnet at a time to be switched on.

I will take a look on ht16k33/max7219 chips, hoping it will fit!

Other answers I'm starting to look for :

  • Would switching magnets consecutively make the piece of metal move ? (I don't have any constraint on the weight of the piece of metal, it could be as light as necessary)
  • The last but not the least, is there any cheap way to buy +500 electro magnets? The cheapest I could find was 0.68€ each, so +300€ in total...

Thanks again!

They won't. You asked about LEDs. Electromagnets are a whole different ball game.

Since only one will be on at a time, you may be able to arrange the wiring in a 16x32 matrix (even if they are not physically arranged as a matrix) with a diode in series with each coil.

I guess. If the electromagnets were embedded in the surface of a table and the metal object is a small ball-bearing, for example.

I think your first objective would be to buy or make a few electromagnets and choose your metal item. Then you will know the electrical requirements of the electromagnets you need to control: voltage & current. Knowing that, we can advise suitable circuits to drive the matrix.

Thank you very much for all that information! I will look forward to it and will come back if needed! Enjoy your day!

A much simpler scheme would be to group the magnets in groups of four and switch them together. It would draw more current but would much simpler to control.

The metal would not move unless it is on some sort of none magnetic bogey making it free to roll. Otherwise it would just stick to the base. It needs some rails to stop it falling off the bed.

Maybe you are thinking of a levetating bed like the bullet train in Japan
https://en.wikipedia.org/wiki/Shinkansen

But that requires none magnetic metal and an AC magnetic field.

Or levitation by using a paramagnetic material like bismuth, it is actually repelled by a magnetic field, so you could “push” it along.

I looked that up as I didn't know there was such a thing. Apparently it is diamagnetic materials that are repelled by magnetic fields: Diamagnetism and Paramagnetism | Introduction to Chemistry

So, like a linear stepper motor. You would get smoother movement by fading from one magnet to the next.

Is there only one continuous 'track' with no intersections? Would it be a problem if more than one magnet was on at a time as long as they were not near each other? You could wire every Nth. magnet together (series or parallel) and cycle through the N groups (forward or backward) to get motion. With high enough N you could safely have the track cross itself as long as the crossing wasn't near the same numbered magnet.

Thank you everybody for your answers, it helps a lot!

Actually I should have talked about that since the beginning, but my project consists in a making chess board where the pieces moves without touching them. (I'm thinking of, way way later on, maybe using a speech-to-text api to control the moves).

But first, I would like :

  • to input a move (just a variable first (Eg. "A1-H8")) to the arduino, then it would calculate the necessary magnets to make this move :
  • the piece on H8 (if there is 1) would need to be kicked out of the board
  • the piece on A1 would be moved to H8

Here is a schema of the chess board, with some html/css and a javascript animation representing the electromagnets switching on one after the other. Green circles are the electro magnets :

chessboard

They are placed on intersection lines so they don't interfer with other pieces in place.

So basically, I already programmed the generation of the lists of magnets that need to be switched on when you want to make a move...

And yes, as you can see, there are intersections/crosspaths and I need to switch on/off only one at a time (So other pieces don't move). The idea of fading the last one to get a smoother movement is possible though and that would be nice!

Well... You have thinking to put a gimmick on the back of the checker board, right?
If it wouldn't be better to have a Cartesian machine with a head with one electromagnet?
The movement path is free, it moves smoothly, and it is easy to control.

1 Like

Oh goshhhh why didn't I think of this!! This is absolutely perfect for what I want to achieve, and much much simpler and cheaper! I will go for the cartesian machine for sure!!

wow. :roll_eyes:

Well, I'm glad to found it helpful. :wink:

I am reminded of magnetic bubble memory which uses a single switchable
magnetic field and a set of shaped magnetic pieces to guide magnetic bubbles
around. The key insight is that by rotating the field you can pull things around
to follow a path:
http://www.tikalon.com/blog/blog.php?article=2015/droplet_computer

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