What Will I Learn?
At the end of this tutorial:
♦ The readers will be able to create an electronic dice with same functionality as the real dice with led lights as the displayed dice patterns.
♦ The readers will be able to know how the circuit works.
♦ Learn to apply the circuit in the future electronic projects
Introduction
In this tutorial, we will create an electronic an electronic dice using the arduino uno as the microcontroller, 6 led lights to display the different dice patterns and a force sensitive resistor as the rolling element of the dice. Once a force is applied to the force sensitive resistor, it means that you have started rolling the dice or the electronic dice. The microcontroller will then randomly display the LED lights pattern of the dice.
It will display the dice pattern of 1 LED , 2 LED ,3 LED, 4 LED, 5 LED and 6 LED.
Requirements
Electronic Components
♦ Arduino Uno
♦ LED
♦ Force Sensitive Resistor
♦ Resistor
♦ Breadboard
♦ Connecting wires
Software
♦ Fritzing application
Difficulty
♦ Advance
Tutorial Contents
Using the fritzing software, we will create our circuit diagram, arduino codes and prototype using the breadboard
Part I. Schematic Diagram
So first let us construct our circuit diagram.
Select the electronic components needed for the circuit in the fritzing library. We need 1 arduino uno, 1 force sensitive resistor, 7 resistors and 6 LEDs.
Arrange the components before constructing the circuit.
In arranging the components, place all the components for the input side (left side) of the arduino and the components for the output side (right side).
At the input side of our circuit we have the force sensitive resistor that serves as the rolling element of our electronic dice. While at the output part of our circuit, we have the six led lights that will display the different dice output pattern after the rolling occurs
Now let us construct our circuit diagram.
The force sensitive resistor is connected the source voltage and to the analog input pin of our microcontroller. In this tutorial, I use pin A2 as the input pin.
At the output side of our circuit, we have the six output pins, which I use pin 2 –pin 7. This output will be connected to the six led lights as you can see in the figure below. This will serve as the output display of the electronic dice.
Before connecting the six led lights, I connect it first to the resistor so that the flow of current is limited and can avoid damaging the led.
Now this is our final circuit diagram.
In real world or in real dice that we commonly used, in order to have an output we should roll the dice and it will give 6 possible outcomes.
But here, we use a sensor as the rolling element of the electronic dice. Once you will touch on the force sensitive resistor, it is the equivalent of rolling the dice. After a few seconds, the electronic dice will give an output and this output is being display on led light pattern.
That is why we connect the sensor to the input of our microcontroller.
Our microcontroller is being programmed to give random outputs once the force sensitive resistor is activated. As you can see in the figure below, each led is connected to the microcontroller output pin that will give signal randomly.
The six led light can be arrange in the same manner of the real dice output pattern. But in my tutorial, I just arrange it in line with each other as shown in the figure below.
For example, if we touch on the sensor, then the microcontroller will give a random output, shall we say 3, so at the output side there is three led lights being activated as shown in the figure below.
The figure below shows the electronic dice output of 5 led lights being activated.
Part II. Code
Now let us do programming of our Arduino uno.
Click on code to start.
The input pin for our microcontroller from the output of the fsr sensor is the analog pin A2 and the output pins are 2, 3 , 4 ,5 ,6 ,7.
int fsrPin = A2; //potentiometer input pin
int resPin = D2; //output pin for our led pattern 1
int resPin = D3; //output pin for our led pattern 2
int resPin = D4; //output pin for our led pattern 3
int resPin = D5; //output pin for our led pattern 4
int resPin = D6; //output pin for our led pattern 5
int resPin = D7; //output pin for our led pattern 6
int fsrValue = 0; //initial value store in the fsr terminal
int edPatterns [6][6] = {
{1, 0, 0, 0, 0, 0}, //output display of 1
{1, 1, 0, 0, 0, 0},//output display of 2
{1, 1, 1, 0, 0, 0},//output display of 3
{1, 1, 1, 1, 0, 0},//output display of 4
{1, 1, 1, 1, 1, 0},//output display of 5
{1, 1, 1, 1, 1, 1}, };//output display of 6
void setup() {
for (int x = 0; x < 7; x++)
{
pinMode(resPins[x], OUTPUT); //give output signal to the randomly selected outputs
digitalWrite(resPins[x], LOW); //no output signal to the other pin
}
randomSeed(analogRead(2)); //from fsr sensor rolling
}
void loop()
{
if (digitalRead(fsrPin))
{
rollTheDice();
}
delay(100); //delayed output by 100 milli seconds
}
void show(int result) //display result pattern
{
for (int x = 0; x < 6; x++)
{
digitalWrite(resPins[x], edPatterns[result][x]); //output pattern display
}
}
Here are our arduino codes.
int fsrPin = A2; //potentiometer input pin
int resPin = D2; //output pin for our power amplifier circuit
int resPin = D3; //output pin for our power amplifier circuit
int resPin = D4; //output pin for our power amplifier circuit
int resPin = D5; //output pin for our power amplifier circuit
int resPin = D6; //output pin for our power amplifier circuit
int resPin = D7; //output pin for our power amplifier circuit
int fsrValue = 0; //initial value store in the fsr terminal
int edPatterns [6][6] = {
{1, 0, 0, 0, 0, 0}, //output display of 1
{1, 1, 0, 0, 0, 0}, //output display o{f 2
{1, 1, 1, 0, 0, 0}, //output display of 3
{1, 1, 1, 1, 0, 0}, //output display of 4
{1, 1, 1, 1, 1, 0}, //output display of 5
{1, 1, 1, 1, 1, 1}, }; //output display of 6
void setup() {
for (int x = 0; x < 7; x++)
{
pinMode(resPins[x], OUTPUT); //give output signal to the randomly selected outputs
digitalWrite(resPins[x], LOW); //no output signal to the other pin
}
randomSeed(analogRead(2)); //from fsr sensor rolling
}
void loop()
{
if (digitalRead(fsrPin))
{
rollTheDice();
}
delay(100); //delayed output by 100 milli seconds
}
void show(int result) //display result pattern
{
for (int x = 0; x < 6; x++)
{
digitalWrite(resPins[x], edPatterns[result][x]); //output pattern display
}
Part III. Breadboard
Click on the breadboard.
Arrange each component in the breadboard before connecting.
Now connect each component if you don’t know how to connect using breadboard just read my previous tutorial about how to construct a circuit in the breadboard
Application
The readers can create their own electronic dice like the example below.
link source
Curriculum
Here are my other tutorials for electronic projects.
ELECTRONIC PROJECTS
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thanks @flauwy
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @rfece143 I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit