Random interval Red/Green light for race start

I've been trying to google but I can't find anything like I'm trying to do. I think I need some guidance on what terms to search for and what exactly is possible to do.

  • I need 2 lights( leds), red and green.

  • When switched on, the red light is on, then once the person hits the button, it begins the "secret" countdown for the random timer.

  • When you press a button, it starts a random timer that you can set, before changing to green.

  • ie. 1-3 secs ; 1-4secs; 2-5secs; 1-10secs etc

  • when it finally turns green, i want a horn/buzz sound to go off at the same time.

  • Reset button to start it all over.

  • The red light can just stay on while waiting for the race to start. Random countdown begins after button press

  • *probably possible but not necessary, and way out of my league, is to snap a picture of the starting line to make sure no one is starting off the line early. This would snap as it turns green

The lights can fit into an enclosure of about 5'' x 10 x 5'', only needs to be seen/heard within 3 feet.

This is my first time working with anything like this, but I feel up for the challenge. Would appreciate terms to google for that would help me understand how to make this, and or code commands that I could look up to learn. also if this is even possible. Thanks!


First you need to understand how the random() function works. It's not actually random. It's pseudorandom. That means that it gives out a sequence of numbers that looks random but if you start your program again, you get exactly the same sequence every time.

Sometimes this is a good thing. If you are simulating some statistical process, then each time you run it, you have the same input. So you can try different things on the 'random' input and get consistent results.

Sometimes it's a bad thing. You will pretty quickly realize that this device will give one short interval, then two longs, then one medium then... whatever. Maybe this is what you want? Then you can stop reading here.

If you want the output to be actually random, then you can still use the pseudorandom random() function. You just have to seed it with a random starting value. But where does this actual piece of randomness come from? The Arduino has just switched on. It starts up in a totally consistent state. On a PC, you could use the last digit of the remaining space on the hard drive - the hard drive space will always change and always be different each time it starts up. Or you can use the current time - even though this is not actually random, at least it is different on each startup.

But your specification includes the user pressing a button to start. Even the most careful person can't press the button within the same millisecond each time the Arduino starts. You can use the millis() function to get the time since switch-on and use that as the seed for randomSeed(). Then the output from random() will truly be random and unpredictable.