How to create touchless dice using Arduino Uno
Below is the list of components that are required to make a touchless dice are:
- Arduino Uno
- Connecting wires
- Breadboard
- IR module
- 7 segment display
- Seven 220-ohm resistor
To create the touchless dice first we need to create the circuit and for that we have given the circuit schematic that is used in this project.
Hardware assembly for creating a touchless digital dice with Arduino Uno and 7-segment
To implement the circuit given above we have created a hardware assembly that is given in the figure below. From the image given below you can further get a clear idea of the connections of the components used in this project:
We have assembled components by first interfacing the 7-segment with Arduino Uno by connecting its pin to the Arduino in an alphabet order starting from a to g. To interface the display, we have used Arduino pins from 2 to 8 keeping in view the alphabetic order.
Further we have used 220 ohms resistors with each pin of the 7-segment and the upper pins are connected to Arduino using the green wire whereas to connect the lower pins we have used the brown color wires. Similarly, to connect the output of the IR module with Arduino we have used its pin 11 and in the image this connection is represented by cyan color wire.
We have used the 7-segment display having common Anode configuration, so we have connected the display with the supply using the breadboard pins that are connected to 5 volt and ground pin of Arduino. To connect the IR module with the supply we have used the similar row of pins of the breadboard that are connected with 5 volts and ground pins of the Arduino.
Arduino code for creating a touchless digital dice using IR module and 7-segment with Arduino Uno
we have programed the microcontroller to make contactless digital dice whose code is given below:
SevSeg sevseg;// initializing the variable for seven-segment
int state;/* variable for storing the state of the push button*/
int IR= 11;/* Arduino pin assigned to the push button*/
void setup()
{
pinMode(IR,INPUT);
byte sevenSegments = 1;/*defining the number of seven- segments here we are using only one seven-segment */
byte CommonPins[] = {};/* defining the common pins for the seven-segment*/
byte LEDsegmentPins[] = {2, 3, 4, 5, 6, 7, 8 };/* assigning the Arduino pins for each segment from a to g */
bool resistorsOnSegments = true; /*assigning Boolean type to the registers of the seven=segment*/
sevseg.begin(COMMON_ANODE, sevenSegments, CommonPins, LEDsegmentPins, resistorsOnSegments);/* initializing the configuration of the seven-segment */
sevseg.setBrightness(80);// giving the brightness to the seven-segment
randomSeed(analogRead(0));/* shuffling the sequence of dice number generation*/
}
void loop()
{
state=digitalRead(IR);
if (state== LOW){
for(int b = 0; b <=6; b++){
sevseg.setNumber(b);
sevseg.refreshDisplay();
delay(100);
}
int i=random(1,6);/* generating the random numbers for dice */
sevseg.setNumber(i); /*displaying the for loop values on seven-segment*/
sevseg.refreshDisplay(); /* refreshing the seven-segment display after every iteration */
delay(500); /* time after which the for loop will run again*/
}
}
To program the microcontroller to roll the dice without human interface we have first defined the library for the 7 segment and declared the variable used to perform functions of this library. To connect the output of the IR module with Arduino we have defined its pin. Next, we have declared the configuration of the 7-segment that includes the number of display Arduino pins assigned to the display and then using the sevseg.begin() function to initialize the 7-segment display.
To generate the values of the dice we have used a random() function that will generate numbers for 1 to 6 when the value of the IR module is LOW which means that an obstacle is detected. Similarly, to show that the dice is rolling we have used the for loop that rapidly generates the numbers from 1 to 6 and then displays the dice value.
To summarize the working of the Arduino program we can say that when we want the dice to roll we bring our hand near to the sensor and it detects our hand as an obstacle. In return it rolls the dice, and a value of the dice is shown on the 7-segment display.
Hardware implementation for creating a touchless digital dice using IR module and 7-segment with Arduino Uno
The image below shows the hardware implementation of the hardware assembly described above:
The demonstration given below illustrates the working of the Arduino program compiled to create a contactless digital dice using the IR module and 7-segment with Arduino Uno:
Conclusion
Dice is a cube having numbers engraved on its each side ranging from 1 to 6 and it is used to generate the random numbers manually. We have also created a dice that generates the random numbers, but it has two properties that a manual dice lacks: one is that it is digital and the second is that it can generate the number without human interface. So, we can name it as touchless digital dice and we have created it by using an IR module that will trigger the number generation and to display the values we have used in the 7-segment display. We have also provided the Arduino code and the animation that shows the working of the respective Arduino code.