Random Pin Selection

Hi All,

Is it possible to get an Arduino to randomly select one pin after a button is pushed? I have seen videos out there where when a button is pushed, the pins all activate and then stop at a certain pin. That's not what I want. What I want is for none of the pins to activate when I press a button except for only 1 random pin.

Basically...

Push a button, then only 1 pin randomly will light an LED. I do not want all the pins to activate and then stop at a certain pin. I cannot have any pins activate except for the one random pin.

Kind of like a random number generator that is working behind the scenes until I push a button and it stops at whatever number was in the Arduino at that time.

What I want to do is to hook up an old 1954 jukebox for random play. I realize I will have to get a bunch of relay boards for this and hook them up in parallel with the song button wires. If you were confused, now maybe you understand what I mean in that I cannot have all pins activate and then stop at one random pin. That means the jukebox will get way too many selections at once.

Thanks!

sgreiner1011:
Push a button, then only 1 pin randomly will light an LED. I do not want all the pins to activate and then stop at a certain pin. I cannot have any pins activate except for the one random pin.

You want an array of pins to 'choose from' like:

#define NO_OF_PINS  6
int outputPins[NO_OF_PINS] = {2, 3, 4, 5, 6, 7};

then:
Turn off all pins
Wait for button to be pressed
Generate a random number
Use that number to get an output pin from the array like: thePin= outputPins[randomNumber]
Turn on that one pin
Set some timer to stop button from being pressed again too soon

Yours,
TonyWilk

This seems like a pretty inefficient way to use an arduino to control a jukebox. You'd only be able to have about a dozen records (you'll need a couple pins to read the controls.) If you use a Mega you could play 60 different records, but most juke boxes have hundreds of selections.

I would think about using the Arduino to control the carousel the records are mounted in. Perhaps a stepper motor or clock-style pallet and escape mechanism could turn the carousel to the selected number. That way you could have a very large selection.

Thanks Guys,

This seems like a pretty inefficient way to use an arduino to control a jukebox. You'd only be able to have about a dozen records (you'll need a couple pins to read the controls.) If you use a Mega you could play 60 different records, but most juke boxes have hundreds of selections.

I would think about using the Arduino to control the carousel the records are mounted in. Perhaps a stepper motor or clock-style pallet and escape mechanism could turn the carousel to the selected number. That way you could have a very large selection.

Its a 1954 AMI Model G80. It only holds 40 of the 45rpm records (80 songs). There isn't a carousel the records get held in. The whole turntable mechanism moves from side to side and picks records off of a stationary "bank". It would be a major project to alter the mechanics of this thing.

You want an array of pins to 'choose from' like:

Code: [Select]

#define NO_OF_PINS 6
int outputPins[NO_OF_PINS] = {2, 3, 4, 5, 6, 7};

then:
Turn off all pins
Wait for button to be pressed
Generate a random number
Use that number to get an output pin from the array like: thePin= outputPins[randomNumber]
Turn on that one pin
Set some timer to stop button from being pressed again too soon

Yours,
TonyWilk

I just realized that I am going to need, at least, 80 outputs for this to work. There is no such Arduino. I may have to use some Karnaugh Mapping to introduce several gates to get this to work.

Does anybody know how to code a random number generator that would show in binary code at the outputs of an UNO Arduino like I mention in my first post? I can't have any outputs turn on except the one that was randomly generated when pushing a button. I will be using only 7 outputs.

Or heck, Maybe I can just use a 555 timer and TTL random number generator. I dunno, have to do some more research.

You got one of these - neat!

sgreiner1011:
Its a 1954 AMI Model G80.

I just realized that I am going to need, at least, 80 outputs for this to work.

Not necessarily... you can use shift register outputs, see ShiftOut Tutorial.
There are boards like this one with just the chip and there are others available with relays and stuff.

Does anybody know how to code a random number generator

See: random() function

Yours,
TonyWilk

You got one of these - neat!

Yes, That's it!!! LOL!!!

Not necessarily... you can use shift register outputs, see ShiftOut Tutorial.
There are boards like this one with just the chip and there are others available with relays and stuff.

Great.. thanks for the info! I'm going to check that out!

Am I going to able to use a few shift registers in order to generate random numbers? I scoured the internet and cannot find anybody who has done such a thing. I am new to coding so I have to do research on what its all about. I am getting better though. I have a lot of experience in separate IC chip tech. Its been 30 years since college, and I cannot remember what a shift register is actually able to do beyond its advertised capability.

I may just build a circuit with a 555 timer and a random number generator IC chip with all the logic gates I mentioned earlier with the relay boards. I'll have to do more research (since I'm old school and such) lol.

A small arduino and a few shift registers eg 74HC595's would work fine.

Use eg random(40) to generate the number.

Suggest using randomSeed(millis()) when the button is pressed to get variation.

Just clock a '1' along the shift registers random() times to choose the record.

Clock 40 '0's in to clear the selection

Allan

sgreiner1011:
I may just build a circuit with a 555 timer and a random number generator IC chip snip

No need... as allanhurst points out above, you can use the random() function in the Arduino software to generate your random number.

Yours,
TonyWilk

P.S.

...since I'm old school and such...

you're not the only one :slight_smile:

No need to use a hardware RNG for this application, the built-in one is fine. Here is a simple software, pseudo-random number generator, that will produce a stream of number from 0 to 40:

void setup () {
  randomSeed(analogRead(A0));  // use any unconnected pin to get a seed value
  Serial.begin(115200);
}

void loop () {
  Serial.println(random(0,40));
}