Minimalist MCU Project: Electronic Dice Driven by Only 4 IO Pins (Source Code Included)

Today, I want to share a small DIY project I made a long time ago: an electronic dice.

It looks like this—

Minimalist MCU Project: Electronic Dice Driven by Only 4 IO Pins (Source Code Included)

The gameplay is roughly as follows—

The required components are very simple and inexpensive:

  • 1 STC15W104 or STC8G1K08 MCU
  • 7 LEDs + 7 current-limiting resistors
  • 1 micro push button
  • 1 CR2032 battery holder + battery

By arranging the 7 LEDs in an “H shape,” you can display the dice patterns from 1 to 6. Does this mean it requires 7 IO pins from the MCU? Actually, no—only 4 IO pins are sufficient 😊.

The core idea is:

  • The middle LED: controlled by 1 independent IO
  • The surrounding 6 LEDs: controlled in pairs using 3 IOs

This way, you can easily display numbers from 1 to 6.

The firmware is available here: <span>https://github.com/qiwenmin/stc-dice</span>. The project uses PlatformIO, and after downloading, you can compile it by running <span>pio run</span>.

After compilation, the firmware size is approximately 800 bytes, with the random number generator occupying most of the space.

This circuit does not have a power switch; it starts working automatically when the button is pressed, which is very convenient. When idle, the MCU automatically enters sleep mode, consuming only microamps. I made this little gadget over four years ago, and recently I tried it out, and surprisingly, it still has power 👍.

Below are photos of the front and back:

Minimalist MCU Project: Electronic Dice Driven by Only 4 IO Pins (Source Code Included)Minimalist MCU Project: Electronic Dice Driven by Only 4 IO Pins (Source Code Included)

(End)

Leave a Comment