Electronic Dice With Arduino Nano
Introduction: Electronic Dice With Arduino Nano
The electronic dice presented here, built around a tiny Arduino Nano board, mimics the dice we play in different games like snake and ladders the most popular. Plastic and wooden dice are subject to wear and tear with time and might show biasing toward a specific number defying theory of randomness and the player as well. As this dice is completely electronic and programmed with zero bias this makes it an idle to rely on. It has a bright red light display and cheers sound when a player gets the highest number 6 of his best luck. So, let us play a new game today!
Step 1: Get Required Parts
We have used Arduino Nano if you are a professional or electronics enthusiast you will have it or else buy it online with a few little bucks. We are not using a 7-segment display as it requires lots of wires and resistors moreover it waste board pins that could be used connecting some other device. I have found out four-pin 7-segment display TM1637, it has four 7-segment displays and one colon. One Buzzer, a Tactile Switch, a Resistor, and few connecting wires would complete our bill of materials. Last but not least one laptop pc installed with Arduino IDE.
List of Components
* Arduino Nano
* TM1637 7-Seven Segment Display
* An active Buzzer
* A Micro-Switch
* 10K Ohm Resistor
* Connecting Wires
Step 2: TM1637 4-Digits 7-Segment Display
As already said a bare 7-segment display uses more wires and add-on resistors also. If we interface a 4-digit 7-segment display it would require 12 wire connections, plus resistors and transistors as well. This means tons of wiring and wastage of pins that could be used connecting any other device.
The TM1637 reduces pin connections just to four. 1014
Two pins are used for power connections, supply, and ground, and the other two for clock and data input-output. So, we are saving 8-pins!
At the heart of the module is an inexpensive serial LED driver from TitanMicroelectronics TM1637. Thus the display prefix this chip name and called TM1637 7-segment display.
The TM1637 supports many functions, like ON/OFF and brightness control of the LEDs as well as accessing each of the segments. You can also adjust the LED brightness at the software level.
The TM1637 module includes four 0.36 segment 7-segment displays to display data.
The TM1637 module operates on a supply voltage of 3.3 to 5 volts and communicates over a two-wire bus, so it only requires two data pins plus supply and ground, a total of four pins only.
Pinout
* CLK - clock input pin to the display - used for data input-output at the rising edge
* DIO - data input-output pin - used for serial data input and output
* VDD - positive power supply - connected to 3.3V to 5V
* GND - ground pin - connected to ground
.
Step 3: TM1637 Library Installation
To work TM1637 7-segment display with Arduino nano you need to install its library. In the "Manage Library" search box type "TM1637" and install "Grove 4-Digit Display" by seed studio, as you see can see in the image for help.
Step 4: Make Connections
I have used digital pins D2, D3 Display, D4 connected to the tactile switch, and D5 to the buzzer.
Here below are the connections :
1. D2->Display CLK
2. D3->Display DIO
3. D4->Switch
4. D5->Buzzer
5. GND->GND
6. VCC->VCC
Step 5: Programming
Understanding the Code
Include TM1637 library header file:
#include <TM1637.h>
Pins and variables declarations:
int CLK = 2;
int DIO = 3;
int DIC = 4;
int BUZ = 5;
int buttonState = 0;
int randNum = 0;
Define input and output pins:
pinMode(DIC, INPUT);
pinMode(BUZ, OUTPUT);
Initialize serial communication at 9600bps:
Serial.begin(9600);
Define state of pins low or high:
digitalWrite(DIC, LOW);
digitalWrite(BUZ, HIGH);
Initialize TM1637 display:
tm.init();
Set display brightness level:
tm.set(2);tm. 991