Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

How To Make DIY Mechanical Dice using Arduino NANO & Servo Motor by WTC Zone

How To Make DIY Mechanical Dice using Arduino NANO & Servo Motor by WTC Zone


Here's the complete code and explanation for  digital dice project using a 7-segment display controlled by servos. The system will display random numbers between 1 and 6, transitioning quickly through random patterns before stopping at the final number when the button is pressed.


Circuit Setup

  1. Servo Connections:
    • Segment A → Servo 1 → Arduino Pin D2
    • Segment B → Servo 2 → Arduino Pin D3
    • Segment C → Servo 3 → Arduino Pin D4
    • Segment D → Servo 4 → Arduino Pin D5
    • Segment E → Servo 5 → Arduino Pin D6
    • Segment F → Servo 6 → Arduino Pin D7
    • Segment G → Servo 7 → Arduino Pin D8
  2. Push Button:
    • Button connected to Arduino Pin D9.
    • Use a pull-down resistor (10kΩ) for stability. Connect one leg of the button to 5V and the other to D9 with the resistor to GND.

Concept

A traditional 7-segment display uses LEDs to represent digits and characters. In your project, each segment will be represented by a servo motor. Each servo motor will move to 90 degrees (ON) or 0 degrees (OFF) based on whether a segment should be active or inactive for a particular digit or letter.


Parts Required

  1. Arduino NANO (1x)
    • Controls the servos and determines the digit/letter to display.
  2. Servo Motors (7x)
    • Acts as the mechanical segments of the display.
  3. Power Supply:
    • Use an external 5V power supply capable of handling all 7 servos simultaneously (e.g., 2A or higher).
  4. Jumper Wires
    • For connecting servos to the Arduino and power supply.
  5. Breadboard
    • For distributing power.
  6. Resistors (optional for pull-down circuits, if needed).
  7. Push Button
    1. For making shuffle in the dice

Circuit Connection

  1. Servo Connections:

    • Connect the signal pins of the 7 servo motors to Arduino digital pins (e.g., D2 to D8).
    • Connect the GND and VCC pins of all servos to the external power supply.
    • Connect the power supply GND to Arduino GND for a common ground.
  2. Power Supply:

    • Use an external 5V power supply to avoid overloading the Arduino’s regulator.
  3. Segments Mapping:

    • Map each servo motor to a segment of the 7-segment display:
      • Segment A → Servo 1 → Arduino Pin D2
      • Segment B → Servo 2 → Arduino Pin D3
      • Segment C → Servo 3 → Arduino Pin D4
      • Segment D → Servo 4 → Arduino Pin D5
      • Segment E → Servo 5 → Arduino Pin D6
      • Segment F → Servo 6 → Arduino Pin D7
      • Segment G → Servo 7 → Arduino Pin D8
  4. Push Button:
    1. Add a push button to your circuit:
      • Connect one leg of the push button to a digital pin (e.g., pin 9).
      • Connect the other leg of the button to ground.
      • Add a pull-up resistor (10kΩ) between the digital pin and VCC or use the Arduino's built-in pull-up resistor.

Working

  1. Initialization:
    • Each servo is initialized to the "OFF" position (0 degrees).
  2. Display Logic:
    • Based on the input digit or letter, the Arduino controls which segments are ON (90 degrees) or OFF (0 degrees).
  3. Servo Movement:
    • When a segment is turned ON, the corresponding servo rotates to 90 degrees.
    • When a segment is turned OFF, the servo rotates back to 0 degrees.
  4. Satisfying Humming Sound:
    • The servos will produce a gentle humming sound during their movement, creating a satisfying mechanical effect.

Circuit Diagram

Video Link: - Click Here For Video

How To Make DIY Mechanical Dice using Arduino NANO & Servo Motor by WTC Zone simple Circuit: -





How To Make DIY Mechanical Dice using Arduino NANO & Servo Motor by WTC Zone Arduino Programming: -

Arduino IDE Program

Code for DIY Mechanical Dice using Arduino NANO & Servo Motor by WTC Zone

#include <Servo.h>

// Define servo objects for each segment
Servo servos[7];

// Define pin connections for each servo
const int segmentPins[] = {2, 3, 4, 5, 6, 7, 8};
const int buttonPin = 9;  // Push button pin

// Define ON and OFF positions for the servos
const int ON_POSITION = 90;  // Servo ON position
const int OFF_POSITION = 0;  // Servo OFF position

// Segment activation patterns for dice numbers (1-6)
const int dicePatterns[6][7] = {
  {0, 1, 1, 0, 0, 0, 0}, // 1
  {1, 1, 0, 1, 1, 0, 1}, // 2
  {1, 1, 1, 1, 0, 0, 1}, // 3
  {0, 1, 1, 0, 0, 1, 1}, // 4
  {1, 0, 1, 1, 0, 1, 1}, // 5
  {1, 0, 1, 1, 1, 1, 1}, // 6
};

void setup() {
  // Attach servos to pins and set initial position
  for (int i = 0; i < 7; i++) {
    servos[i].attach(segmentPins[i]);
    servos[i].write(OFF_POSITION); // Set all segments to OFF
  }

  // Initialize button pin
  pinMode(buttonPin, INPUT_PULLUP);  // Enable internal pull-up resistor

  // Seed random generator
  randomSeed(analogRead(A0));
}

void loop() {
  // Wait for button press
  if (digitalRead(buttonPin) == LOW) {
    rollDice();
    delay(300);  // Debounce delay
  }
}

// Function to simulate dice roll
void rollDice() {
  // Simulate random transitions
  for (int i = 0; i < 10; i++) {  // Quick random transitions
    int randomIndex = random(0, 6);  // Random number (0-5 for dicePatterns)
    displayNumber(randomIndex + 1);
    delay(100);  // Short delay between transitions
  }

  // Display final number
  int finalNumber = random(1, 7);  // Random number between 1 and 6
  displayNumber(finalNumber);
}

// Function to display a number on the 7-segment display
void displayNumber(int number) {
  for (int i = 0; i < 7; i++) {
    if (dicePatterns[number - 1][i] == 1) {
      servos[i].write(ON_POSITION);  // Turn segment ON
    } else {
      servos[i].write(OFF_POSITION); // Turn segment OFF
    }
  }
}


----------------------------------------------------------------------------------------------------------------------------

Working of the Project

  1. Hardware Setup:

    • Connect each servo to its respective segment pin (as per the segmentPins array).
    • Use external power if needed to handle the power requirements of the 7 servos.
  2. Execution:

    • The program initializes all servos to the OFF position (0°).
    • In the loop(), it cycles through numbers (0-9) and letters (A-F), activating the required segments (servos) for each character.
    • The servo angles change smoothly, and you can hear the "humming" sound as they move.
  3. Satisfying Display:

    • The sequential motion of servos simulates a mechanical 7-segment display.
    • The dynamic movement adds a creative and unique twist compared to traditional LED-based displays.

Circuit Connection

  1. Components:

    • Arduino NANO
    • 7 x Servo Motors
    • Connecting Wires
    • External Power Supply (if needed, as Arduino's 5V pin may not provide sufficient current for all servos).
  2. Connections:

    • Connect servo signal wires to pins 2-8 (as defined in segmentPins).
    • Power the servos with the Arduino's 5V and GND (or an external power source with shared GND).
    • Ensure the potentiometer can handle the servo's current requirements if external power is used.

Key Features

  1. Quick Transitions:

    • Before the final dice roll, the code simulates quick random transitions by cycling through random patterns.
  2. Button Debouncing:

    • A delay(300) is used to ensure the button press is not detected multiple times unintentionally.
  3. Random Dice Roll:

    • Uses random() to generate a number between 1 and 6.
  4. Smooth Display:

    • Displays numbers reliably by transitioning servos to the appropriate positions.

Assembly Notes

  1. Servo Power:

    • Ensure a stable power source for the servos. If using multiple servos, consider an external 5V power supply.
  2. Push Button Wiring:

    • Connect one leg of the button to 5V.
    • Connect the other leg to D9 and GND through a 10kΩ pull-down resistor.
  3. Servo Calibration:

    • Test the ON_POSITION (90°) and OFF_POSITION (0°). Adjust these values if the display segments do not align correctly.

Demonstration

  • Once powered, the servos will move to form the shapes of numbers (0-9) and letters (A-F) sequentially.
  • The transition of servo angles (90° for ON, 0° for OFF) creates a pleasing mechanical effect.

Let me know if you need further help refining or customizing the project! 😊


This setup and code will create a fun and responsive digital dice using your 7-segment servo display. Let me know if you encounter any issue.

Share, Support, and Subscribe!!! 1. PRO KAM EXPLAINED 2. Knowledge KAM 3. PRO KAM Follow us on 1. Facebook 2. Instagram 3. Pinterest 4. Blogspot 5 Twitter If you have any other ideas to make me design, you can describe them in the comment section and if I can, I will make a designing video on it. So I am waiting #prokam #wtc #Arduino #ideas #projects #diy #how #to #ArduinoProjects #UltrasonicSensor #HeightMeasurement #TechDIY #WeTechCreators #wtczone

Post a Comment

0 Comments

Ad Code

Responsive Advertisement