Hello everyone, today I'm going to show you how to make a "digital roulette" by combining the ESP32-C3 super-mini microcontroller with the classic CD4017 CMOS decade counter.
When the button is pressed, the ESP32 sends a "clock pulse" to the CD4017 IC, causing the LEDs to cycle. Releasing the button triggers a realistic deceleration effect until it stops at a random result, and the final position is reported using a serial monitor or via Wi-Fi.
Believe me, this project involves a lot of hardware design, Arduino coding, PHP, databases, 3D design and printing, and so on.
Video:
https:// youtu.be/5jVFR7KSNmgFull blog post:
https:// diyfactory007.blogspot.com/2026/05/Roulette.html
Component requirements
For this project, we need:
🔗1 x ESP32-C3 Super Mini Plus microcontroller:
https://s.click.aliexpress.com/e/_ c2zUTvyj
🔗2 CD4017 CMOS decimal counters:
https://s.click.aliexpress.com/e/_ c33qzzRt🔗2 NPN transistors of type 2N2222:
https://s.click.aliexpress.com/e/_ c4OwNvnZ🔗3x220 Ω resistors:https://s.click.aliexpress.com/e/_ c41SucJd
🔗1 x 10kΩ resistor:https:// s.click.aliexpress.com/e/_c41SucJd
🔗1 x button switch:
https://s.click.aliexpress.com/e/_ c3cfuN6J🔗1 x SPDT switch:
https://s.click.aliexpress.com/e/_ c4FRHRaX 🔗18 x 5 mm red LED:https://s.click.aliexpress.com/e/_ c2RpNzh9
🔗2 x 5 mm green LEDs:https:// s.click.aliexpress.com/e/_c2RpNzh9
🔗1 x 3 mm blue LED:
https://s.click.aliexpress.com/e/_ c306Pzbh🔗1 x 10mfd capacitor (optional)
🔗https://s.click.aliexpress.com/e/_ c4okFfef:1 x LiPo battery
🔗1 x battery charging module (optional):
https://s.click.aliexpress.com/e/_ c3EJLcZh🔗1 x battery power indicator:
https://s.click.aliexpress.com/e/_ c4KGEDh5Print the shell with a 3D printer
Circuit diagram
The wiring for this project is really simple!
* Connect pin 8 of the ESP32 to the reset pin (pin 15) of IC #1.
* Connect pin 10 of the ESP32 to the clock pin (pin 14) of IC #1.
* Connect pin 9 of the ESP32 to the button switch with a pull-up resistor.
* Connect pin 0 of the ESP32 to the Wi-Fi indicator LED with a current-limiting resistor.
For the rest of the wiring, please refer to the circuit diagram on the screen.
To make things easier, I've designed a custom PCB for you.
Core functions
I initially built this LED roulette project using a 555 timer IC and several CD4017 CMOS decade counters. The 555 timer is used as a clock oscillator, generating a signal to drive the 4017 decade counter. The output of pin 3 of the IC555 is fed to pin 14 of the IC4017. Each time the IC4017 receives a pulse, it increments the count and activates the next output pin (Q0 to Q9), resulting in a shifting LED effect.
To learn more about ICs, please check out my tutorial number 26 titled "555 Pulse Generator Module and Its Working Principle". The link is provided in the description below.
The main drawback of this initial design is that I have to handle the counting manually. I want a system that automatically adds numbers, and the winner should be determined by the system itself. My goal is not to create a gambling wheel, but a simple roulette game that I can play with my son.
To achieve this goal, the ESP32-C3 Super Mini is the perfect choice. It is compact and comes with built-in Wi-Fi functionality.
Here's what happened. I didn't use the 555 timer IC, but instead switched to the ESP32-C3 board to generate "clock pulses" for one of the CD4017 ICs. When the button is pressed, the pulses become faster and faster. The light runs around the circle, creating a sense of "rotation". When the button is released, the rotation doesn't stop immediately. Instead, it gradually increases the time between pulses, making the light slow down gradually - just like a real wheel sliding to a stop.
Code
Now let's take a look at the logic that drives the entire program.
As mentioned earlier, the system relies on many components, including Arduino code, PHP, MySQL databases, etc. My GitHub repository contains two versions of the code: one with a server, and one without. If you don't need to store the results on a server, you can simply upload the "Code_No_wi-fi" to your ESP32 board.
However, in this tutorial, I will demonstrate all the features of the setup.
Now, let's review the code one by one.
In the Arduino code, you need to enter the SSID and password of the network, and set the server IP and URL to match the directory where the PHP file is located.
There's no need to modify other parts of the code, unless you want to add new features to the existing ones.
When you open the roulette, the ESP32 first attempts to connect to the server via Wi-Fi. Once the connection is established, players can start the game. Pressing the button accelerates the LED sequence by reducing the delay, while releasing the button slows it down by increasing the delay - until it exceeds the stop threshold. This creates a natural trailing effect before the sequence stops completely.
Once the LED wheel stops, the ESP32-C3 will send the winning position to the remote server. As long as the player continues to play, this process will continue.
In addition to the code, I also included a "MySQL_DB.sql" file, which needs to be imported into the MySQL server.
To perform this operation, open phpMyAdmin, go to the "Import" tab, click the "Select File" button, and then select the "MySQL_DB.sql" file. Then click the "Go" button to import the table. To verify that the import was successful, click on the table name and check if the table structure is displayed correctly.
To set up the web server, we need to make some changes to the PHP files downloaded from my GitHub repository. Open "Connection.php" and update the hostname, username, password, and database name in the file. Then, drag and drop the file into the directory on the web server.
To verify that everything is working properly, please open the "Player_Results_Display.php" file in your web browser and confirm that the leaderboard is displayed correctly.
Breadboard demonstration
Now that the hardware logic is ready and the server has been set up, we can perform a quick test on the breadboard to verify the system's functionality.
Let's continue to press the button and see if the serial monitor has recorded the press. As we can see, the HTTP 200 code is displayed on the serial monitor, indicating that the communication with the server was successful. On the leaderboard page, we can confirm that the server has recorded the button press. The webpage automatically refreshes every 5 seconds, displaying the latest scores of the two players in real time.
The page includes side-by-side scorecards for "Player 1" and "Player 2", showing each player's real-time score, wins, losses, draws, and total games played.
When you click the "New Game" button, the page will be reset, and the system will update the player's win, loss, or draw count based on the current score.
3D printing
Using Microsoft 3D Builder, I designed the 3D model of this project.
The design consists of three parts:
- The top part, which is used to accommodate all the LEDs. - The bottom part, which contains all the electronic components and
- A small piece, which includes a blue Wi-Fi indicator LED, a battery charging module, an SPDT on/off switch, and holes for the antenna cable and button switch.
I sliced the model in Bambu Studio and printed it out using my new Bambu A1 3D printer.
Finally, I used acrylic paint to draw the main body of the project. The golden finish really enhances the appearance of the print. After the paint dried, I installed all the LEDs on the top and welded their negative legs together in pairs of ten.
Welding
Now, let's start assembling all the electronic components. First, take a moment to check the quality of the manufactured PCB. I've been using PCBWay for nearly six years, and I absolutely love the end products they provide.
Let's first weld all the resistors to the board, and then weld all the transistors.
Because I pay special attention to my ICs and microcontrollers, I never solder them directly to the board. For ICs, I always use IC sockets. If there are no sockets, I use female pin headers. This avoids direct soldering and makes replacement easy. I solder all components to the PCB one by one.
To power the circuit board, we need to integrate a charging module and some additional components. I started by installing the SPDT switch, followed by the blue Wi-Fi indicator LED. Then, I superglued the world's smallest battery charging module to the block and used this small white block to secure it. Finally, I glued the charging indicator lights together according to the circuit diagram on the screen.
The remaining two holes accommodate the antenna and the button switch. Finally, once all the components are in place, I will glue the plastic blocks into the grooves at the bottom of the base.
This is the appearance of the circuit board after I finished welding all the wires that will be connected to the LEDs. For LEDs 1 to 10, I used common GND2; for LEDs 11 to 20, I used common GND1.
When soldering LEDs to the board, make sure to do it in the correct order to avoid a mismatch between the physical LED numbering and the code sent to the server. Follow the instructions on the screen to ensure the correct order. If you accidentally solder the LEDs incorrectly, you can modify the array in the Arduino code to accommodate the changes.In my settings
I'm using a 3.7V rechargeable battery to power everything. However, if you'd like, you can solder a 220V to 5V step-down converter or a USB cable to the +5V and -VE ports on the board.
Once everything is ready, all that remains is to glue the bottom to the top.
Final demonstration
The hardware is ready, it's time to have some fun! Turn on the device and wait for the blue LED to light up. When it does, it confirms the Wi-Fi connection to the server. Press the button to start LED tracking. Your scores can be viewed on any device connected to the same network (PC or mobile device).
Thank you
Thank you again for checking my post. I hope it can be of help to you.
Full blog post: https:// diyfactory007.blogspot.com/2026/05/Roulette.html
Tags
Source du modèle



















