Chenqi ZhuAdvait VartakSiddhi Patil
Published © GPL3+

Card Shuffler

A card shuffler that automatically shuffles your cards!

IntermediateFull instructions provided502
Card Shuffler

Things used in this project

Hardware components

ESP32
Espressif ESP32
×1
DC motor (generic)
×2
DRV8833 DC/STEPPER MOTOR DRIVER
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Fusion
Autodesk Fusion

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Code

Shuffling Code

C/C++
#include <Arduino.h>

#define MOT_A1_PIN 19
#define MOT_A2_PIN 18

#define MOT_B1_PIN 23
#define MOT_B2_PIN 22

#define SERVO_PIN 13

void servoWrite(int angle) {
  int width = map(angle, 0, 180, 500, 2600);
  digitalWrite(SERVO_PIN, HIGH);
  delayMicroseconds(width);
  digitalWrite(SERVO_PIN, LOW);
  delayMicroseconds(20000 - width);
}


void setup(void)
{
  // Set motor A control pins to OUTPUT
  pinMode(MOT_A1_PIN, OUTPUT);
  pinMode(MOT_A2_PIN, OUTPUT);
  pinMode(MOT_B1_PIN, OUTPUT);
  pinMode(MOT_B2_PIN, OUTPUT);

  pinMode(SERVO_PIN, OUTPUT);

  // Turn off motor A and B initially
  digitalWrite(MOT_A1_PIN, LOW);
  digitalWrite(MOT_A2_PIN, LOW);
  digitalWrite(MOT_B1_PIN, LOW);
  digitalWrite(MOT_B2_PIN, LOW);

  digitalWrite(SERVO_PIN, LOW);

  for (int j = 0; j < 10; j++){
    servoWrite(95);
    delay(15);
  }
  Serial.begin(9600);

  Serial.println("===========SHUFFLE BOT===========");
  Serial.println("PRESS A TO START");
  Serial.println("PRESS S TO STOP");
}

void loop(void)
{
  char instr = Serial.read();

  if (instr == 'a') {  
    for (int j = 0; j < 10; j++){
      servoWrite(95);
      delay(15);
    }

    while(instr!= 's') {
      instr = Serial.read();
      digitalWrite(MOT_A1_PIN, LOW);
      digitalWrite(MOT_A2_PIN, LOW);
      digitalWrite(MOT_B1_PIN, LOW);
      digitalWrite(MOT_B2_PIN, LOW);
      // delay(10);
      int dir = random(2);  

      if (dir == 0) {
        digitalWrite(MOT_A1_PIN, LOW);
        digitalWrite(MOT_A2_PIN, HIGH);
      }
      else {
        digitalWrite(MOT_B1_PIN, HIGH);
        digitalWrite(MOT_B2_PIN, LOW);
      }

      delay(1000);
    }
    digitalWrite(MOT_A1_PIN, LOW);
    digitalWrite(MOT_A2_PIN, LOW);
    digitalWrite(MOT_B1_PIN, LOW);
    digitalWrite(MOT_B2_PIN, LOW);
    Serial.println("\nSHUFFLING FINISHED\n");
    Serial.println("PRESS A TO START");
    Serial.println("PRESS S TO STOP");

    for (int j = 0; j < 10; j++){
      servoWrite(0);
      delay(15);
    }
    delay(100);
  }

  delay(10);
}

Credits

Chenqi Zhu
1 project • 0 followers
Contact
Advait Vartak
1 project • 0 followers
Contact
Siddhi Patil
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.