I wanted to create a digital dice that mimics the action of the cubic dice. Also, I want to keep it simple, however functional, so I used only one input, the on/off switch, and one output, the seven segments. The seven segments will show only from 1 to 6 like the actual dice.
Also, when I google searched I found similar ideas, however, they were more complicated than just a basic digital dice. In addition, I am new to coding and Arduino, so it was challenging to decipher the code easily and understand the process behind each project.
Photos source: https://benjweinberg.com/2022/02/06/a-roll-of-the-dice/
Software: Tinker CAD
Tools:
> Components:
- Inputs: ON/OFF switch, Battery (9V)
- Outputs: Seven segment
- Breadboard
- Jumper wires
- Crocodile wires
- Resistors
- Rosetta
Tinker CAD: to build and simulate the circuit
Arduino IDE: to install the codeblocks on the breadboard
Arduino UNO
(Brain+Power management)
Breadboard
Seven segment (output)
On/Off switch (Input)
jumpers
Crocodiles
Adaptor (Power source)
Rosetta
I started by dragging and dropping the components. The components were the Arduino, and the 7 segment (output component, an on/off switch (input component), resistor, and jumpers.
I started connecting the Arduino to the 7 segment (common cathode) and my reference for the connections was a previous task that we did in a mid-week session for the 7 segment.
Then connected a resistor to the 7 segment; connected the -ve pole to the breadboard -ve rail and the +ve to the breadboard where I attached a wire from the resistor to the ground of the 3-segment
As for the connection type, the jumper wires are connected from the 7 segments (common cathode) to the Arduino in parallel.
For the series connection, the resistor is connected in Series with the 7-Segment Display LEDs to limit the current flowing into each LED segment.
Afterward, I connected the on/off switch to the breadboard, with the +ve end connected to the breadboard's +ve rail and the -ve end connected to the breadboard's -ve rail.
Also, I connected the Arduino 5V pin to the +ve rail of the breadboard, while the ground to the negative.
The 5V and the Ground of the Arduino are connected to the breadboard in parallel.
The switch is connected to the Arduino to pin no. 2
> Also after creating the actual circuit, I realized that I switched the negative and the ground of the on/off switch.
Here's the final circuit on tinker cad
It's a digital dice, so the main feature is to code the 7 segment to show random figures only from 1 to 6 like the actual cubic dice. Using code block with challenging at first, but I started researching for online references.
I sat pin 2 to (high) which is the on/off switch acting as an input
Then, I started by creating an Infinite Loop to run the code consciously. Inside the infinite loop started building the code block, I added a variable function to choose a random number from 1-6 (the dice function).
Then, I added if conditions that check the value of the number and execute a specific block of code based on that value. Each (if block) has the 7 segment pins adjusted to show from 1 to 6.
Please find the Circuit link attached to the link above
After many trial and errors and simulation on tinkercad. I started implementing the circuit by using actual components.
I started by copying the same wiring and connections as the tinker cad circuit
As for on/off switch connections, I +ve end of the switch is connected to the +ve rail of the breadboard (the red jumper and crocodile). While the -ve end is connected to pin no. 2 on the Arduino. The middle end of the switch is connected to the
-ve rail of the breadboard
By far, this is the most assignment I have struggled with, for the feedback part I consulted my instructors on slack and after the Saturday sessions to troubleshoot the challenges.
I had some challenges concerning the circuit itself and also while building the code blocks. As for the code blocks, I believe that the code did not start forward and it required a lot of thought to build. What made it more challenging was that I was not so sure of my circuit connection after many simulations that the circuit was not working and I did not figure out what is the root cause of the problem at once. I had some wrong connections in the circuit in the wiring and the cathode and anode connections. In addition to the trial and error in building the coding and how to ensure a random function for the dice to run.
I believe that tinkering is a savior when it comes to experiencing and simulation. So definitely I will be using tinkering for the trial and error phase before using the actual material.