Electronic Project 38: A simple guide on how to create an electronically operated dice using a 6 led lights pattern and FSR as rolling element

in utopian-io •  7 years ago  (edited)

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.

image.png

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.

image.png

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.

image.png

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

image.png

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.

image.png

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.

image.png

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.

image.png

Now this is our final circuit diagram.

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

The figure below shows the electronic dice output of 5 led lights being activated.

image.png

Part II. Code

Now let us do programming of our Arduino uno.
Click on code to start.

image.png

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 

image.png

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

image.png

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
}

image.png

void show(int result) //display result pattern
{
for (int x = 0; x < 6; x++)
{
digitalWrite(resPins[x], edPatterns[result][x]); //output pattern display
}
}

image.png

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.

image.png

Arrange each component in the breadboard before connecting.

image.png

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

image.png

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

Tutorial 1

Tutorial 2

Tutorial 3

Tutorial 4

Tutorial 5

Tutorial 6

Tutorial 7

Tutorial 8

Tutorial 9

Tutorial 10

Tutorial 11

Tutorial 12

Tutorial 13

Tutorial 14

Tutorial 15

Tutorial 16

Tutorial 17

Tutorial 18

Tutorial 19

Tutorial 20

Tutorial 21

Tutorial 22

Tutorial 24

Tutorial 25

Tutorial 26

Tutorial 27

Tutorial 28

Tutorial 29

Tutorial 30

Tutorial 31

Tutorial 32

Tutorial 34

Tutorial 35

Tutorial 36

Tutorial 37



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

thanks @flauwy

Hey @rfece143 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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