Introduction: DIY 37 Leds Arduino Roulette Game
Roulette is a casino game named after the French word meaning little wheel.
Step 1: Description
In the game, players may choose to place bets on either a single number, various groupings of numbers, the colors red or black, whether the number is odd or even, or if the numbers are high (19–36) or low (1–18).
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
This project was sponsored by NextPCB:
-Free PCB Design Analysis Software-NextDFM:
https://www.nextpcb.com/nextdfm.html
-Come to win a $20000 coupon:
https://www.nextpcb.com/nextdfm.html
-Register for $10 coupon & Free PCB boards:
https://www.nextpcb.com/nextdfm.html
-15%OFF - PCB & 10 % SMT Orders:
https://www.nextpcb.com/nextdfm.html _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Most often you can find a project of a roulette game with 10 LEDs, so I decided to do with 37 LEDs as in the original whell.Following the principle of the original Roulette game, the movement of the LED simulates a ball whose speed gradually decreases until it stops at a randomly generated number. The construction is greatly simplified with the use of an Arduino microcontroller.
Step 2: Building
Device is relativly simple to build and consist few components:
- Arduino Nano microcontroller
- 74HC595 shift register 5 pisces
- 37 Leds
- NPN transistor
- 2 Resistors
- and Buzzer
This is the European-style layout and consist a single zero, and 36 other numbers. By pressing the button we actually throw the virtual ball, whereby the rotation is simulated by the subsequent illumination of the LEDs. The rotation of the LEDs is accompanied by an appropriate sound effect, which gives a realistic feel to the game. Rotation speed as well as time can be easily adjusted in the code.
Step 3: Schematic and Code
Finally, the device is placed in a suitable box made of PVC plastic and coated with colored wallpaper. Below you can download Arduino Code:
You can watch the video on: https://www.youtube.com/watch?v=H_85lFRJ9T8
3 Comments
5 months ago
Hello, I believe there may be something wrong with the code. After a button press it runs through each led, but only once then stops. The next issue is that there is about 10 seconds between each led. Can you verify that the code you updated is correct? Much appreciated.
Reply 3 months ago
Yes, his code doesn't quite work. Here is a version that should get you 99% there. Note the transistor/resistor/speaker is replaced with a simple piezo buzzer to make things simpler, and the Arduino "tone" function is used to make the sounds. It may take a little tweaking, but I've run a very similar version and it works fine. If it doesn't work, double check the pin assignments in the code against the circuit.
int SER_Pin = 8; // Arduino pin to provide SERIAL data to the 75HC595 Shift Register ICs
int RCLK_Pin = 9; // Pin to drive the RESET CLOCK IC pin
int SRCLK_Pin = 10; // Pin to drive the SERIAL CLOCK IC pin
int RESET_Pin = 7; // Pin to connect the reset button
int SPKR_Pin = 6; // Pin to connect piezo buzzer as + (other side of buzzer to ground)
int MaxDelay; // Maximum delay between LED on/off times for realism
int DelayValue = 5; // Start value for delay
int StopAt; // Holds the random number to stop spin
int FullSpins; // Number of full spins of 'wheel'
int LEDNumber; // Holds the LED number to turn on/off
constexpr int ShiftRegisters = 5; // Number of 75HC595 shift register ICs
constexpr int PinCount = ShiftRegisters * 8; // 8 pins per IC, to connect LEDs
boolean Registers[PinCount]; // Array to hold value to write to registers
void setup() {
pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
pinMode(RESET_Pin, INPUT_PULLUP);
// reset the registers
ClearRegisters();
WriteRegisters();
// Serial.begin is only needed for printing to debug serial monitor
//Serial.begin(115200);
randomSeed(analogRead(3)); // Initialize the random seed to 'random' noise on an unused analog pin
MaxDelay = random(200, 250); // Maximum delay for LED on/off period
}
// Set then enable display registers; This is SLOW, so call after values are set
void WriteRegisters() {
digitalWrite(RCLK_Pin, LOW);
for(int i = PinCount - 1; i >= 0; i--) {
digitalWrite(SRCLK_Pin, LOW);
int val = Registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}
// Clear all register pins by setting them LOW
void ClearRegisters() {
for(int i = PinCount - 1; i >= 0; i--){
Registers[i] = LOW;
}
}
// Set an individual pin HIGH or LOW (on or off)
void setRegisterPin(int index, int value) {
Registers[index] = value;
}
void loop() {
// Check if the RESET button was pressed
if(digitalRead(RESET_Pin) == LOW) {
ClearRegisters();
WriteRegisters();
FullSpins = random(2,5); // Pick a random number of full spins before stopping at the number (between firstnum and secondnum-1)
StopAt = random(PinCount); // Pick a random number to end the spin
int CountTo = FullSpins * PinCount + StopAt; // we'll count up to the number chosen
//Serial.print("Full Spins: "); Serial.print(FullSpins); Serial.print(" StopAt: "); Serial.println(StopAt); Serial.print(" CountTo: "); Serial.println(CountTo); // only for simulation to print to debug serial monitor
for (int x=0; x <= CountTo; x++) {
LEDNumber = x - ( PinCount * ( x / PinCount)); // do some modulo math
//Serial.print(x);Serial.print(" - ");;Serial.print(LEDNumber);Serial.print("-");
if (DelayValue <= MaxDelay) {
setRegisterPin(LEDNumber, HIGH);
WriteRegisters();
delay(DelayValue);
if (x < CountTo) { // Leave the LED on when the CountTo number is reached
setRegisterPin(LEDNumber, LOW);
WriteRegisters();
DelayValue++;
tone(SPKR_Pin, 1000, 5);
}
}
delay(70);
}
DelayValue=5; // Reset initial delay value at end of spin
}
}
1 year ago
Updated code and schematic