Arduino Gambing Machine
This circuit is an Arduino-based gambling game that uses LEDs, a 7-segment display, a servo motor, and a light-dependent resistor. When the button is pressed, six LEDs flash in a left-to-right pattern like a spinning wheel. The pattern then stops on a randomly chosen LED. The number of the selected LED is shown on a common-anode 7-segment display. The Arduino controls the display by turning segments on and off using digital signals. After the result is chosen, a servo motor slowly rotates to cover the LDR. Covering the LDR reduces the light reaching it, creating a dimming effect. Pressing the button again resets the circuit and restarts the game.
Supplies
- 1 large breadbord
- 1 small breadboard
- 1 Arduino Uno
- 3 Red LEDs(can be any color)
- 3 Green LEDs(can be any color)
- 1 servo
- 1 LDR
- 1 NPN transistor
- one 7-segment display
- 1 button
- thirteen 220 ohms resistors
LED Sequence
Take 6 of the resistors and all 6 of your LEDs.
Connect the resistors and LEDs in the order of the image.
Make sure that the LEDs are in an alternating pattern.
Connect each LED to arduino pins 1-6 in order of left to right.
LDR + Transistor
Connect the LDR in resonably distaned from the LED sequence
terminal 1 should be connected to power and pin A0
terminal 2 will be connected to the NPN collecter
The NPN base will be connected to the start of LED1
The emitter will be connected to ground
Add Button
Connect a button to the breadboard
a terminal should be connected to power and Pin 8 on the arduino
the opposing terminal should be connected to ground
Configure Servo Motor
servo motor will have 3 pins. Power, ground, and signal.
Power should be connected to arduino power.
Ground should be connected to arduino ground.
signal will be connected to pin 13 on the arduino.
7-segment Display
Use the small breadboard and connect the 7-segment display right in the middle.
connect a 220 ohms resistor to each segment
Segment a - pin 9
Segment b - pin 10
Segment c - pin 11
Segment d - pin 12
Segment e - A1
Segment f - A2
Segment g - A3
Both commons will go to arduino ground
Coding
The code that will be used:
#include <Servo.h>
int leds[6] = {1, 2, 3, 4, 5, 6};
// a, b, c, d, e, f, g
int segments[7] = {9, 10, 11, 12, A1, A2, A3};
int buttonPin = 8;
int ldrPin = A0;
int servoPin = 13;
Servo coverServo;
// COMMON ANODE segment patterns
// 0 = ON, 1 = OFF
byte numbers[7][7] = {
{1,1,1,1,1,1,1}, // unused
{0,0,0,1,1,1,1}, // 1
{0,0,1,0,0,1,0}, // 2
{0,0,0,0,1,1,0}, // 3
{1,0,0,1,1,0,0}, // 4
{0,1,0,0,1,0,0}, // 5
{0,1,0,0,0,0,0} // 6
};
void setup() {
for (int i = 0; i < 6; i++) {
pinMode(leds[i], OUTPUT);
}
for (int i = 0; i < 7; i++) {
pinMode(segments[i], OUTPUT);
digitalWrite(segments[i], HIGH); // OFF by default
}
pinMode(buttonPin, INPUT);
pinMode(ldrPin, INPUT);
coverServo.attach(servoPin);
coverServo.write(0);
randomSeed(analogRead(A5));
}
void loop() {
if (digitalRead(buttonPin) == HIGH) {
clearLEDs();
clearDisplay();
coverServo.write(0);
// LED flicker animation
for (int rounds = 0; rounds < 20; rounds++) {
for (int i = 0; i < 6; i++) {
clearLEDs();
digitalWrite(leds[i], HIGH);
delay(80);
}
}
// Random LED selection
int chosen = random(0, 6);
clearLEDs();
digitalWrite(leds[chosen], HIGH);
// Show LED number (1–6)
showNumber(chosen + 1);
// Slowly cover the LDR
for (int angle = 0; angle <= 90; angle++) {
coverServo.write(angle);
delay(30);
}
// Wait for reset button press
while (digitalRead(buttonPin) == LOW) {
delay(10);
}
}
}
void clearLEDs() {
for (int i = 0; i < 6; i++) {
digitalWrite(leds[i], LOW);
}
}
void clearDisplay() {
for (int i = 0; i < 7; i++) {
digitalWrite(segments[i], HIGH); // OFF
}
}
void showNumber(int num) {
for (int i = 0; i < 7; i++) {
digitalWrite(segments[i], numbers[num][i]);
}
}
Testing
Test each component and make sure current is flowing though each.