Playing a board game that requires a dice? No fear, you can make your own in less than 15 minutes! You just need some very common parts, a bit of patience and a 35-line Arduino code!
All used parts are from Kuman's Arduino UNO Starter Kit.
Step 1: Parts Needed
- 16 Jumper Wires
- A button
- An Arduino board
- A breadboard
- A USB cable
- 6 led's (color doesn't matter)
- 6 220 ohm resistors
- A 10k ohm resistor
Allchips is an electronics components online service platform, you can buy all the components from them.
Step 2: Connecting the Button
Firstly, lets start with the button. On every press, "the dice is being rolled" (generating a random number and lighting up the corresponding number of leds). Grab the button and insert it into the breadboard and choose one of it's sides. You will see 2 pins. The one on the left (you can swap them as well) connects to ground of the Arduino (through the breadboard) with the 10k resistor. Connect the same row to digital pin 13 of the Arduino (defined in the code, can be changed). The pin on the right side of the button connects to 5V. You can use the above picture for reference.
Step 3: Connecting the Led's
This is the trickiest part because of the mess that you are left with afterwards so bare with me and continue. I assume you've already inserted the led's into the breadboard. If not, now it's the perfect time ;)
I don't know how you will position them but basicly, follow the general rule - all of the 6 cathodes should be connected together and then to ground (GND). See the pictures above if you are having problems!
Now, we need to connect the anodes. Let me explain you: you need to connect the other lead of each led to the corresponding digital pin of the Arduino, each using a 220 ohm resistor! I'm redirecting the other ends of the resistors to some empty rows of the breadboard which then get connected to the pins using jumper wires.
I started connecting them from the bottom left led to pin 2, next - to pin 4, right one - to pin 6 and on the above row, starting from right to left.
Step 4: Finishing Touches
Connect the power rails of the breadboard to your Arduino. Then, plug in the board and upload the code that I've written, which can be found here. Bare in mind, nothing in the world we live in is random! Even the "random" numbers. So getting the same numbers in a row is a total possibility! I've tried fixing this in the code, but it can't be perfect!