Hi everyone, today I am going to show you how I made a "Digital Roulette Wheel" by combining ESP32-C3 Super Mini Microcontroller with the classic CD4017 CMOS decade counters. When the button is pressed, the ESP32 sends "clock pulses" to the CD4017 IC, causing the LEDs to cycle. Releasing the button triggers a realistic slowing down effect until it stops on a random result and reports the final position using the Serial Monitor or via Wi-Fi.
Watch this video for detailed step by step instructions on how to build this LED Roulette circuit and all its components and to know how this circuit works. Trust me, there's a lot going on with this project hardware design, Arduino coding, PHP, databases, 3D design and printing, and more.
Video Elements -------------------------- 00:00 Introduction 01:18 Components Required 01:47 Circuit Diagram 02:26 Core Functionality 04:16 The Code 06:26 Breadboard Demo 07:18 3D Printing 08:21 Soldering 10:21 Final Demo
Thanks ------ Thanks again for checking my post. I hope it helps you. If you want to support me subscribe to my YouTube Channel: https://www.youtube.com/user/tarantula3
Hi everyone, today I'm going to show you guys how I made a digital roulette wheel
by combining the ESP32-C3 super mini microcontroller with the classic CD4017 CMOS ticket counter.
When the button is pressed, the ESP32 sends clock pulse to the CD4017 IC, causing the LEDs to cycle.
Releasing the button triggers a realistic slowing down effect until it stops on a random result
and reports the final position using serial monitor or via Wi-Fi.
Watch this video for detailed step-by-step instructions on how to build this circuit
and to know how the circuit works.
Trust me, there is a lot that is going on with this project.
Hardware design, Arduino coding, PHP, databases, 3D design and printing, and more.
This video is sponsored by PCBWay.
PCBWay specializes in manufacturing of very high-quality,
low-volume colored PCBs at a very budgetary price.
In addition to standard PCBs, you can also order advanced PCBs, aluminum PCBs, rigid flex PCBs.
They also provide PCB assembly and other related services,
which can meet your need to the greatest extent.
For this project we need
One ESP32-C3 super mini microcontroller
Two CD4017 CMOS ticket counters
Two 2N2222 NPN transistors
Three 220-ohm resistors
One 10-kilo-ohm resistor
One push-button switch
One SPDT switch
Eighteen 5mm red LEDs
Two 5mm green LEDs
One 3mm blue LED
One LiPo battery and charging module
And a 3D printer to print the enclosure.
The wiring of the project is really simple.
Connect pin number 8 of the ESP32 to the reset pin pin number 15 of IC number 1.
Connect pin number 9 of the ESP32 to the push-button switch with a pull-up resistor.
Connect pin number 10 of the ESP32 to the clock pin pin number 14 of the IC number 1.
Connect pin number 0 of the ESP32 to the Wi-Fi LED indicator with a current limiting resistor.
For the rest of the wiring, please check out the circuit diagram on screen.
To make things even easier, I have designed a custom PCB for you.
You can grab the Gerber file from the description below and get the board fabricated from PCBWAY.COM
I originally built the LED roulette project
using a 555 timer IC and couple of CD4017 CMOS decade counters.
The 555 timer functions as a clock oscillator,
generating a signal that drives the 4017 decade counters.
The output from pin number 3 of the 555 timer IC is fed into pin number 14 of the 4017 IC.
Each time the 4017 IC receives a pulse,
it increments the count and activates the next output pin,
Q0 to Q9, creating a shifting LED effect.
To know more about the IC, please check out my tutorial number 26,
555 pulse generator module, how it works. The link is in the description below.
The main drawback of the initial design is that I wanted a system where the numbers are added
automatically and the winner is determined by the system itself.
My goal isn't to build a gambling wheel,
but rather a simple roulette game that I can enjoy playing with my son.
To achieve that, ESP32-C3 Super Mini turned out to be the perfect choice.
It is compact and comes with built-in Wi-Fi.
So, instead of using the 555 timer IC,
I switched to the ESP32-C3 board to generate the clock pulse for one of the 4017 ICs.
When the button is pressed, the pulse becomes faster and faster.
The light races around the circle, creating the sensation of a spin.
When the button is released, the spin doesn't stop immediately.
Instead, it gradually increases the time between the pulses,
making the light slow down progressively, just like a real wheel coasting to a stop.
Once it slows down enough, it stops completely and reports the final LED position
via serial monitor or Wi-Fi.
The result is then saved into the MySQL database and is visualized using PHP.
Now, let's have a look at the logic that is powering the entire show.
As mentioned earlier, the system relies on a lot of components,
Arduino code, PHP, MySQL database, and more.
My GitHub repository contains two versions of the code,
one with a server and the other without.
If you don't need the results saved on a server,
you can simply upload the code, no Wi-Fi to your ESP board.
However, for this tutorial, I will demonstrate the full functionality of the setup.
Now, let's review the codes one by one.
In the Arduino code, you need to enter your network's SSID and password,
as well as the server's IP and URL to match the directory where your PHP files will reside.
No other part of the code needs to be modified
unless you want to add new features to the existing functionality.
When you power on the roulette, the ESP32 first attempts to connect to the server via Wi-Fi.
Once the connection is established, players can begin the game.
Pressing the button speeds up the LED sequence by reducing the delay.
While releasing the button slows it down by increasing the delay
until it passes a stop threshold.
This creates a natural freewheeling effect before the sequence comes to a complete stop.
Once the LED wheel stops, the ESP32-C3 sends the winning position to the remote server.
This process continues as long as the players keep playing.
In addition to the code, I have included a mysqldb.sql file
that needs to be imported into your MySQL server.
To do this, open phpMyAdmin, go to the Import tab, click Choose File button,
and select mysql-underscore-db.sql file.
Then click the Go button to import the tables.
To verify the import was successful,
click on the table names and check that the table structures appear correctly.
To set up the web server, we need to make some changes to the downloaded PHP files.
Open connection.php and update the hostname, username,
password, and the database name in the file.
Then drag and drop the files into a directory on your web server.
To verify that everything is working correctly,
open the player-underscore-results-underscore-display.php file
in a web browser and confirm that the leaderboard page appears correctly.
Now that the hardware logic is ready and the server is set up,
we can perform a quick test on a breadboard to verify the system's functionality.
Let's go ahead and press the button to see if the serial monitor registers the press.
As we can see, an HTTP 200 code is displayed on the serial monitor,
indicating successful communication with the server.
On the leaderboard page, we can confirm that the server has recorded the button press.
The webpage auto-refreshes every 5 seconds,
displaying the latest scores from both players in real-time.
The page includes side-by-side scorecards for player 1 and player 2,
showing live scores, wins, losses, ties, and total games played by each player.
When you click the New Game button, the page resets,
and the system updates the player's wins, losses, or tie count based on the current score.
Using Microsoft 3D Builder, I designed the 3D model of this project.
The design consists of three parts, the top section, which holds all the LEDs,
the bottom section, which contains all the electronic components,
and a small block, which houses a blue Wi-Fi indicator LED,
a battery charging module, an SPDT on-off switch,
plus holes for the antenna cable and the push-button switch.
I sliced the model in Bamboo Studio and printed it out using my new Bamboo A1 printer.
For those seeking ultra-fine, industrial-grade 3D printing,
I recommend having the STLs printed from PCBWay.com.
Finally, using acrylic colors, I painted the body of the project.
The gold finish really elevated the print's appearance.
After the paint dried, I installed all the LEDs into the top section
and soldered their negative legs together in pairs of 10.
Now, let's begin assembling all the electronic components.
First, let's take a moment to inspect the quality of the fabricated PCB.
I have been using PCBWay for nearly six years now,
and I absolutely love the final product they deliver.
Let's start by soldering all the resistances to the board,
followed by all the transistors.
Because I take extra care of my ICs and microcontrollers,
I never solder them directly to the board.
For ICs, I always use IC bases, and if a base is not available, I use female pin headers.
This avoids direct soldering and makes replacement easy.
To power the board, we need to integrate the charging module and some additional components.
I began 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 secured it using this small white block.
Finally, I superglued the charging indicator as per the on-screen circuit diagram.
The remaining two holes accommodate the antenna and the push-button switch.
Finally, once all the components were in place,
I glued the plastic block into the grove at the bottom of the base.
In my setup, I am powering everything with a 3.7V rechargeable battery.
However, if you prefer, you can solder either a 220V to 5V step-down converter or a USB cable.
So, this is how the board looks like after I finish soldering
all the wires that will connect to the LEDs.
For LEDs 1 through 10, use common ground 2.
For LEDs 11 through 20, use common ground 1.
When soldering the LEDs to the board, be sure to solder them in the correct order
to avoid mismatching the physical LED number with what the code sends to the server.
Follow the on-screen instructions for the correct order.
If you accidentally solder the LEDs incorrectly,
you can modify the array in the Arduino code to accommodate the change.
Once everything is in place, all that is left is to glue the bottom bit to the top bit.
That's it. As simple as that.
With the hardware ready, it's time to have some fun.
Power on the unit and wait for the blue LED to light up.
When it lights up, it confirms the Wi-Fi link to the server.
Press the push-button to begin the LED chase.
Your score can be viewed on any device, PC or mobile connected to the same network.
In short, this setup turns a simple button
and LED system into a realistic-feeling game by adding momentum to the movement.