Introduction: Two Dice Roll Demonstration for Physics and Probability

About: A Maker since childhood with all the classic symptoms, a robot builder, and an Internet software CTO/Tech Product Manager.

Probability is an important concept in Physics since many physical interactions can have multiple outcomes. This project is a hands-on exhibit to allow students to see the results of dice rolls to get a better intuitive feel for probability and the difference between single events and many events averaged together.

One description can be found at this site at Georgia State University: http://hyperphysics.phy-astr.gsu.edu/hbase/Math/d...

This project uses a 16x16 array of WS2812b LEDs ("Neopixels") and an ESP8266 CPU (a Wemos D1 Mini). A single pushbutton switch is used to roll the dice. The display shows the dice roll as dice pips for the two dice. The total of the dice is shown as a number, and the display also plots how many times each total was rolled. Once any total reaches 16 times, the run stops.

A second mode rolls the dice 1000 times for each press of the pushbutton. The resulting plot of the times each total is seen (divided by 1000) shows a much more typical chart of the odds of each total.

Step 1: Parts

16x16 Sheet of WS2812b ("Neopixel") LEDs. This is a sheet of 256 LEDs on a flexible circuit board. They are arranged as a line of LEDs, so have a single data line for all 256 LEDs. There is also an extra connector for power injection, but this project does not use many LEDs, and they are used dimly, so that is not needed here.

Wemos D1 Mini ESP8266 module. I programmed this with the Arduino, so it felt just like an Arduino. I did not use the WiFi part for this project. It has more memory than an Arduino Uno/Nano, so it is better for the large LED array with the Adafruit Neopixel library. The D1 Mini board does not have a lot of the I/O pins available, but since we need only one for the LEDs, and one for the switch, it is nice and small - perfect for this project.

330 ohm resistor - this is for the data line to the LEDs. It's always a good idea to add a resistor to limit flickering from electronic ringing in that data line.

3 conductor JST SM male plug - this is to connect to the LED array since it has a plug on it. You could cut the wires instead. These nicely match the color code on the LEDs. Red = +5, White = Gnd, Green = Data. The male plug has the pins sticking out with a shroud around them.

2 Conductor Connector. This is for the push button switch so you can mount it through the front panel.

Push Button Switch. The system is controlled from a single push button switch - it should be one that is easy to press a lot of times. These switches were nice and big, but they had a more debouncing issues.

Project Box. The project box could be made many ways. I opted for a t-slot frame.

20mm T Slot extrusion. I used black since it came in the lengths I was looking for. I like the silver finish too.

T Slot corner braces and M5 hardware.

Perforated plastic backing. I like using this with the T-slot since it matches up well with the hardware and spacing.

Polycarbonate front plate. Polycarbonate is much less likely than acrylic to crack when drilling etc.

26 gauge silicone wire. I love silicone wire since it's flexible and the jacket does not melt when soldering. Any hookup wire will do.

Heat shrink tubing. 3MM is the most useful. Clear lets you see the resistor later.

5.5mm x 2.1mm CCTV female connector. This is easy to connect to the power injection wires on the LED panel.

5.5mm x 2.1mm extension cord. To get the power out of the box. You could also use a 2.1mm panel jack, but I was not sure if it would be best in front (ugly), in back (hits the wall), or bottom (hits the t- slot). There are a lot of way to do this, but since a wire is coming out the bottom anyway, I opted for this approach. There are lots of lengths on these available.

5V power supply. This is a very small 2A one since I am not using many of the LEDs. If you had all of them on full white, theoretically, they could draw 15 Amps. With my limited LED use in this project, a cell phone battery will power it! You can use this kind of wire for that setup.

Step 2: Wiring

See the attached wiring diagram for details.

Note that the 5V jack is connected to the power injection wire in the middle of the LED string, and the JST connector to the D1 mini is used to supply power to the D1 mini. All three wires from the LED panel have the power and ground connected together, so you can supply (or draw) power from any of them. With more LEDs full on, you might need to supply power at all three connectors, but in this project, we are not using the LEDs that much.

For the power jack, a screwdriver can be used to connect the 5.5mm x 2.1mm CCTV jack.

For the switch, solder and heat shrink one of the two conductor connectors.

For the D1 Mini:

Solder the 330 ohm resistor to D6 on the D1 Mini, then solder the other side to the green wire on the JST connector. Use heat shrink to cover that up.

Solder the red wire from the JST connector to the 5V pin on the D1 Mini.

Solder both the white wire from the JST connector and one of the pushbutton connector wires to the D1 Mini Gnd pin. You can solder one through and tack the other on the other side or make a Y connector or something if both wires do not fit in the hole.

Solder the other wire from the pushbutton connector to pin D3 on the D1 Mini.

The pushbutton does not have any particular polarity. The D1 Mini is configured in the code to use an internal pullup resistor on the GPIO pin, so it is active low and no external resistor is needed.

Step 3: Building the Frame

There are many ways this project could be housed. I tried a thin file box, which was OK, but the translucent cover was not great for the printed instructions. So, something with a transparent cover is best. Another idea is to use square dowels and screws with plastic covers.

I have used T Slot extrusions for robot bases, and decided that would allow the most flexibility for changes at the installed location (a college Physics department hallway). For my layout, I cut two 7 11/16" pieces, and two 15 3/16" pieces.

For the front, I used Polycarbonate sheets - these machine much better than Acrylic - less cracking with hole drilling etc. For the back, I decided to use perforated plastic. I have used this before for robot bases, and the holes fit M5, #8, and #10 hardware nicely. It's the same hole spacing as Vex and Erector. I think that will allow the maximum flexibility for mounting, and also allow heat to dissipate. For my layout, I cut the plastic to 9 3/16" x 15 1/8".

For the layout, Landscape mode allowed a more compact layout. The size is set by the hole spacing on the back - need to cut between the holes. I chose a 9" x 15" size.

To make the frame, I cut the plastic sheets to the 9x15 size. For the backing, I cut between the holes. For the front, I cut it just a bit wider so it does not extend past the t slot. This is easy to measure after the frame is put together with the corner brackets. The backing does not need any holes to be drilled. The front does, and again, this is easier once the frame is assembled - you can mark the holes right on the frame.

I had some 20mm thick shipping foam, so I cut that out as a backing for the printed description and LED array to hold them against the front panel.

Step 4: Code

Most of the code is for the UI since I chose to use a singe push button for the interactions. There are two modes: The first rolls the dice once per button press. The second rolls the dice 1000 times per press. There is some scrolling text to describe the upcoming mode. You can hold the button down to roll many times in a row - there is a 200ms delay for that so you don't accidentally do that on a single button press.