Introduction: Smart Playing Card Distributor

Greetings,

My name is Ruben. Right now I am a mechanical engineering student and for the class we have to make a smart object. The goal is basically making an existing object smart with the use of sensors. As someone that always liked playing card games or games in general. I thought why not make a smart playing card distributor.

Some requirements were:

  • At least use one sensor to measure something
  • Use at least one of the machine in the workplace

Step 1: Required Materials/tools

To make this playing card distributor the following materials were used:

  • Playing cards
  • Sixteen Arduino cables
  • Arduino UNO
    Breadboard
  • HC-SR04 ultrasonic sensor
  • GWS S03NF STD servomotor
  • 28BYJ-48 stepper motor
  • ULN2003A driver board
  • Nine pencils
  • Four pen refills
  • A thin wood plank

To construct the card distributor I used the following tools:

  • Glue gun
  • Laser cutter
  • Office tape
  • Scissors
  • Saw

Step 2: Documentation

First I was thinking about how one can make something that can turn at least 360 degrees and distribute cards. I realised I could make it turn around 360 degrees using a stepper motor. To distribute cards I needed something like an arm that basically can sweep the cards off. For this situation I found out that a servo motor could do this job. As for the sensor I thought it would be useful that the sensor would be able to measure a distance. If players are in a certain range the stepper motor would stop and then activate the servo to sweep the cards off. An ultrasonic sensor would do the job for this. Before proceeding on the components I made a drawing of the situation first.

To start the project has to stand on something. So I made a wooden circle with a diameter of 150 mm. This was made with a laser cutter. I recommend to make it a 200 mm diameter circle though, because I wasn't able to put all of the components inside the Arduino because it was a little bit too small. This wooden circle has eight holes in a circle pattern in it. So I used a saw to make eight pencils of around the same length. I made them around 60 mm high. I also recommend here making them a bit larger otherwise the wires of the ultrasonic sensor would get stuck on objects when it's rotating. Around 80-100 mm would easily do the trick. The pencils are attached to the wooden circle by using a glue gun. These pencils will eventually hold a circle platform with the playing cards, ultrasonic sensor and the servomotor.

I made the circle platform out of cardboard. The diameter of the cardboard circle is also 150 mm like the wooden circle. I also recommend changing this to 200 mm! This way it's light so the stepper motor doesn't need to rotate too much weight. To make the holder the cards are in I measured them first. The playing cards I used ( 54 playing cards )were 87 mm long, 57 mm width and 17 mm high. If you're gonna make this for yourself I recommend to measure the playing cards you will use, because the size of the playing cards can be different. I used the length and width as inside measurements. The height I changed to 20 mm to make sure none of the cards will fall out. After I made the holder for the cards I noticed a problem. If you want to remove a card, the cards under if will move with as well. Resulting that multiple cards fall down instead of one. This effect can be reduced by either making the inside measurements a little bit smaller or by making the card holder not horizontal. Like a small ramp. The ramp I used was five degrees.

Next I had to make a holder for the servo motor. My idea was that the servo would go down automatically after it removed a card by using gravity. First I thought I would make one out of cardboard, but after testing it would just get stuck on the way down and it wasn't too stable. So instead I used pen refills to hold the servo motor. This was an excellent idea because the servo I used for this has four open holes on the side of it. So there are two holes on each side of the servo. I cut the pen refills to an equal size with the use of scissors. I made them around 90 mm. Careful though, you don't want to have ink all over you. With the glue gun I sealed the exits of the pen refills to no ink can leak out after.

Now everyone component is made separately. To connect all these components together some holes have to be made in the cardboard platform. In the middle I made a 5 mm circle for the stepper motor. Two holes were also added for the ultrasonic sensor and the wires of the servo motor. When you make these holes parts of cardboard will be sticking out. I recommend using office tape to remove it and make a flat surface again. Otherwise the cardboard circle will not rotate properly, because it could get stuck on the pencils I used to hold it. But by using a 200 mm cardboard circle instead of 150 mm will allow for enough room for the ultrasonic sensor.

To attach the stepper motor to the cardboard circle I made a mould of glue for the stepper motor. To do this is really easy. First I put the stepper motor in the 5 mm hole I made earlier. After that cover it with glue from a glue gun. Don't keep it in too long though. When the glue gets too solid it will be hard to properly remove it. Note that this could take a couple of tries. If it fails you can reheat the glue by holding your glue gun next to hit so it becomes a bit soft again. This way you should be able to remove it and try it again. If it works you can attach and remove the cardboard circle easily from the stepper motor allowing to change things under the cardboard circle.

After testing the stepper motor I found a problem. The motor itself would move instead of the cardboard platform. This can be fixed by attaching the motor with an object ( I used a 45 mm pencil ) on the wooden circle by using a glue gun. This way it would hold the motor still and causes the cardboard circle to rotate.

The cards in the holder have to be at least 50 mm higher than the cardboard circle. This does depend on what kind of servo you are using. The servo I am using is at least 45 mm high with the arm to sweep the cards. The servo moves downwards when you remove a card because of the gravity. So you at least need to be higher than the servo otherwise the servo will hit the cardboard circle and won't go down anymore. Resulting that not all cards can removed. I used two cardboard pieces with the height of 50 mm placed under the card holder to fix this problem. They were attached by using a glue gun.

Now the card holder is attached on the cardboard circle it's time to attach the pen refills on the cardboard circle. These will be placed next to the card holder. Otherwise the arm of the servo won't be able to reach the cards. The simplest way to attach them would be place the servo next to the card holder first. Then draw on the cardboard circle where the open holes of the servo would be. Remove the servo and attach the pen refills on the cardboard by using a glue gun. I recommend holding them till the glue is solid. Otherwise they will fall over. After the pen refills are properly attached you can put the servo on the pen refills. After all wiring is done you can close these open holes of the servo to prevent it from falling of the pen refills.

As last the ultrasonic sensor has to be attached on the cardboard circle. I did this by putting the ultrasonic sensor in the hole I made earlier and then glue it on the platform with a glue gun.


Step 3: Layout of the Setup

In this step I will be explaining how the motors, sensor and ULN2003 driver board are connected to the Arduino UNO and breadboard. I used a program called Fritzing to make the picture above.

ULN2003 driver board:

  • + to 5V on the breadboard
  • - to the ground on the breadboard
  • IN1 to pin 4 on the Arduino UNO
  • IN2 to pin 5 on the Arduino UNO
  • IN3 to pin 6 on the Arduino UNO
  • IN4 to pin 7 on the Arduino UNO

Stepper motor:

  • Connect it to the ULN2003 driver board

Servomotor ( Could be multiple colours depending what servo you are using ):

  • Black/brown wire to the ground on the breadboard
  • Red wire to the 5V on the breadboard
  • Orange, white, blue or yellow wire to pin 13 on the Arduino UNO

Ultrasonic sensor:

  • Vcc to 5V on the breadboard
  • Trig to pin 9 on the Arduino UNO
  • Echo to pin 10 on the Arduino UNO
  • Gnd to the ground on the breadboard

Arduino UNO:

  • A ground port on the Arduino to the ground on the breadboard
  • A 5V port on the Arduino to the ground on the breadboard

It is recommended to use a glue to make sure the wires won't go out of the pins. As they can easily go loose! It can be useful to attach non rotating wires on the wooden circle to prevent the rotating wires to get stuck on them.

Step 4: Code

// Note: Don't let the stepper motor rotate more than a circle, otherwise the wires will get stuck. This is because the wires rotate with the cardboard circle and will circle around with it.

#include <Servo.h>
Servo myservo; //This will active the servo
int Pin0 = 4;
int Pin1 = 5;
int Pin2 = 6;
int Pin3 = 7;
int trigPin = 9;
int echoPin = 10;
long i=0;
long o=0;
long p=0;
int actie=0;
long value =0;
int place = 0;
void setup()  //defining all pins to either output or input
{
pinMode(Pin0, OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(13); // attaches the servo on pin 13
myservo.write(180); // sets the servo to the starting position
delay(20);
Serial.begin(9600);
}
void loop() 
{
for (i=0; i<570; i++) // this for loop will cause to rotate the cardboard circle to the right
{
digitalWrite(trigPin, LOW); 
delay(5);
digitalWrite(trigPin, HIGH);
delay(5);
digitalWrite(trigPin, LOW);
value = pulseIn(echoPin, HIGH);
Serial.print("Value: ");
Serial.println(value);
for(p=0;p<7;p++)
  {
    myservo.write(120);              
    delay(300);                       
    myservo.write(180);              
    delay(300); 
  }<servo.h>
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, HIGH);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
delay(1);
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
delay(1);
}
}                
for(o=0; o<570; o++) //This part of the code will rotate the cardboard circle left
{
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, HIGH);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
delay(1);
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
delay(1);
}
}

Step 5: Result and Edits.

If you have any questions I will try to do my best to answer those! This prototype is far from perfect like the cards not always falling on their back or drawing multiple cards at once instead of one, but I had fun building this card distributor and it does the basic things you would expect for a card distributor. I hope you will enjoy making it like I did and even upgrade it with your own variations!

Edits:

Edit 1:

  • Added pictures
  • Changed documentation
  • Changed intro and result
  • Changed code and added some explanations
  • Added where the wires should be put in.
  • A small video will be added soon ( hopefully )!

Edit 2:

  • More pictures
  • A small video
  • Removed/changed some typos