Coin Hurdle Rush

by Raxathor in Circuits > Microcontrollers

972 Views, 4 Favorites, 0 Comments

Coin Hurdle Rush

Coin Hurdle Rush P1
PXL_20210622_004136159.jpg

A Fun Little Arcade Game Where the Player Has to Successfully time a coin and pass it through the slot in the rotating wheel. Its all about how you drop the coin , your reaction time and a little luck to get those points. Let's Build it with Some Menu's to Select the Level of Difficulty ,a Points screen , a given Time Period , Some Lights and Sounds.

Supplies

1. Circular and Other Wood Pieces

2. NEMA 17 Stepper Motor

3. 1.3" oled I2C

4. Arduino Nano

5. Arduino Micro

6. DF player

7. Arduino Pro Mini

8. Rotary Encoder

9. Female and Male Header Pins

10. DRV8825 Motor Driver

11. Some Lithium Ion 18650 Batteries and Protection Board

12. Buck Converter

13. Carrom Striker Coin

The Construction

PXL_20210622_010955106.jpg

We'll Start By Building A Wooden Frame To Hold the Wheel, Build it Like the Above.

Rough Dimensions are Fine as This Wont eventually Impact the Working. Make Sure the Height is More than the Wheel.

Mount a NEMA 17 Holder as Well To Hold The Stepper Motor In Place.

The Wheel

PXL_20210622_011026543.jpg
PXL_20210622_011013636.jpg
PXL_20210622_011019763.jpg

Next Start by Taking Circular Pieces of Wood and Cut 4 Slots like The Above. A Thin Strip of Wood is Screwed In Place which has a Slot to Go into The Motor, Hence the Wheel Is Rotated By the Motor

You Could add Four Different Types of Colored Paper to Make it More Attractive. Since I Have Used Two Sheets of Wood With The Four Coin Slots which are Sandwiched together with a Little Spacing I can Add Led's In Them Later It Also Makes For a Surface Which the Coin Can Passthrough.

The Dimensions of My Wheel Were 20 cm Outer and 15 cm Inner Radius.

Drop the Coin

PXL_20210622_011130277.jpg
PXL_20210622_011153110.jpg
PXL_20210622_011201235.jpg
PXL_20210622_011227169.jpg

This Is the Part Where the Coin is Actually dropped, You Could Cut a Trapezoidal Piece of Wood With a Clean, Slant Cut Surface So That A Coin is Propelled Down With Speed To Eventually Pass through The Wheel.

Since The Coin would Tip Sideways in the Starting when Its Dropped Two Pieces of Wood On Either Side Can Help it Balance.

About the Components

PXL_20210622_012156695.jpg
PXL_20210622_021305476.MP.jpg

The Components Used are Basic & Self Explanatory you can also find a lot of documentation about them on the Internet.

The Proximity Sensor is Pulled Low if the Coin Passes and the Arduino Detects and Makes Changes in the Points Accordingly

The OLED screen displays fonts and menu's.

The rotary Encoder helps us select what's on the screen.

DRV8825 or the Motor Driver helps control the Signals that drive the NEMA17 STEPPER MOTOR

DF player Helps us Play Any Audio File which is on the SD card in 0000.mp3,0001.mp3 and so on Format.

You can Find Many References to the Above Components simply with a google search.

Placing the Components

PXL_20210622_021225930.jpg
PXL_20210622_021238073.jpg
PXL_20210622_021302752.jpg

Proximity Sensor 1 is Placed on The Trapezoidal Shaped Piece To Detect If a Coin is Passed And Subtracts -200 Points if it does not pass the Wheel.

Proximity Sensor 2 Is Placed behind the wheel which Detects coin passage if it does it adds another 1000 ppints.

OLED screen is mounted next to the NEMA17 Stepper Motor to Keep track of Points and Time Left.

Led's are Lined up or Placed in the Construction which holds the motor and Under the trapezoidal shaped piece of wood.

Rotary Encoder is placed on the Right Side to Select Level of Difficulty, Speed etc.

Circuit Diagram & Soldering

PXL_20210622_011837991.jpg
PXL_20210622_011850648.jpg
PXL_20210622_021305476.MP.jpg
Screenshot 2021-06-22 090223.jpg

I have provided a rough sketch/schematic of the design more details about the pin numbers can be found from the code.

Solder it onto a perf board with the help of male and female connectors to make it easier and wire free and neat

Adding Some Led's

PXL_20210622_004136159.jpg
PXL_20210622_011019763.jpg
PXL_20210622_011153110.jpg

Adding Led's Makes Everything Prettier.

I've Used some WS2812B Led's which can be programmed to give any colors or patterns.

The White Led's in the wheel are placed in series with a lithuim ion battery a TP4056 Charge controller and Boost Converter to boost the voltage from 3.7v to 27v since the Led's are in series.

Code

#include <Arduino.h>
#include <U8g2lib.h>
#include <AccelStepper.h>

#include<FastLED.h>
#define NUM_LEDS 42
#define LED_PIN 10
CRGB leds[NUM_LEDS];

#ifdef U8X8_HAVE_HW_I2C
#endif
#include <Wire.h>
int t=101;
int points= 0;
unsigned long startTime_TIMER = 0;
unsigned long interval_TIMER = 1000;
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(1, 0); // RX, TX
DFRobotDFPlayerMini myDFPlayer;


int sensor1=2;
int sensor2=3;
unsigned long int startpoint_TIMER=0;
unsigned long int startpoint_TIMER1=0;
unsigned long int intervalpoint_TIMER=200;
unsigned long int intervalpoint_TIMER1=200;

volatile int ledstate=1;

#define speed3 7
#define speed2 8
#define speed1 9

int encoder0PinA = 5;
int encoder0PinB = 6;
int encoder0Pos = 0;
int button=4;
int encoder0PinALast = LOW;
int n = LOW;
int counter1=0;
unsigned long buttondelay=0;
unsigned long buttoninterval=250;

void setup() {
   u8g2.begin();
   u8g2.setDisplayRotation(U8G2_R2);
   //stepper.setMaxSpeed(500);
   //stepper.setAcceleration(100.0);
   FastLED.addLeds<WS2812B, LED_PIN,GRB>(leds,NUM_LEDS);
   FastLED.setBrightness(255);
   pinMode (encoder0PinA, INPUT);
   pinMode (encoder0PinB, INPUT);
   pinMode (button, INPUT);
   pinMode (speed1, OUTPUT);
   pinMode (speed2, OUTPUT);
   pinMode (speed3, OUTPUT);
   pinMode(sensor1,INPUT_PULLUP);
   pinMode(sensor2,INPUT_PULLUP);
   attachInterrupt(digitalPinToInterrupt(sensor1),subtract,FALLING);
   attachInterrupt(digitalPinToInterrupt(sensor2),addition,FALLING);
   mySoftwareSerial.begin(9600);
   if (!myDFPlayer.begin(mySoftwareSerial, true, false)) {  
    while(true){
      delay(0); 
    }
   }
  myDFPlayer.volume(28); 
  
}

void(* resetFunc) (void) = 0;

void loop() 
{ 
   n = digitalRead(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) 
   {
    encoder0Pos=encoder0Pos+1;
   }
  encoder0PinALast = n;
  unsigned currentTime= millis();
  if (digitalRead(button) == LOW) 
    {
      if(currentTime-buttondelay >= buttoninterval)
    {
    buttondelay = currentTime;
    counter1++;
    }}
  
  if (counter1==0)
  startscreen();
  
  if (counter1==1)
  difficulty(); 
  
  if (counter1==2)
  pointsandtime(); 

  if(counter1==3)
   gameover();
 }
  
void startscreen()
{ for(int v=0;v<1;v++){
  fill_rainbow(leds,NUM_LEDS,0,255/NUM_LEDS); 
  FastLED.show();
  }
  myDFPlayer.next();
  digitalWrite(speed1, HIGH);
  digitalWrite(speed2, HIGH);
  digitalWrite(speed3, HIGH);
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_profont22_tf);
    u8g2.setCursor(35,20);
    u8g2.print(F("Press"));
    u8g2.setCursor(35,50);
    u8g2.print(F("Start"));
    } while ( u8g2.nextPage() );
}

void difficulty()
{ for(int w=0;w<1;w++){
    for(int i=0;i<17;i++){
    leds[i]=CRGB::Red;}
    for(int i=16;i<43;i++){
    leds[i]=CRGB::Gold;
    FastLED.show();}
    } 
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_profont22_tf);
    u8g2.setCursor(35,20);
    u8g2.print(F("Level"));
    u8g2.setCursor(50,50);
    u8g2.print(encoder0Pos);
    } while ( u8g2.nextPage());
}

void pointsandtime()
{ if(ledstate==1)
  ledfunction();
    myDFPlayer.enableLoop();
    unsigned currentTime= millis();
    if(encoder0Pos == 1)
    digitalWrite(speed1, LOW);
    if(t==0) 
    digitalWrite(speed1,HIGH);
    
    if(encoder0Pos == 2)
    digitalWrite(speed2, LOW);
    if(t==0) 
    digitalWrite(speed2, HIGH);
    
    if(encoder0Pos == 3)
    digitalWrite(speed3, LOW);
    if(t==0) 
    digitalWrite(speed3, HIGH);
    
    if(t==0)
    counter1++;
    
    if(currentTime-startTime_TIMER >= interval_TIMER)
    {    
    startTime_TIMER = currentTime;
    if (t!=0) t--;
    u8g2.firstPage();
    do {
    u8g2.setFont(u8g2_font_profont22_tf);
    u8g2.setCursor(0,54);
    u8g2.print(F("Points"));
    u8g2.setCursor(80,54);
    u8g2.print(F("Time"));
    u8g2.setCursor(10,25);
    u8g2.print(points);
    u8g2.setCursor(86,25);
    u8g2.print(t); 
    } while ( u8g2.nextPage() );
    }
  }


 void gameover()
 {  u8g2.firstPage();
    do {
    u8g2.setFont(u8g2_font_profont22_tf);
    u8g2.setCursor(10,20);
    u8g2.print(F("Game Over"));
    u8g2.setCursor(50,50);
    u8g2.print(points);
    } while ( u8g2.nextPage() );
    delay(2000);
    myDFPlayer.disableLoopAll();
    resetFunc(); 
    }

 void subtract()
{ unsigned currentTime= millis();
  if(currentTime-startpoint_TIMER >= intervalpoint_TIMER)
  {startpoint_TIMER = currentTime;
  points=points-200;
}
}

void addition()
{ unsigned currentTime= millis();
  if(currentTime-startpoint_TIMER1 >= intervalpoint_TIMER1)
  {startpoint_TIMER1 = currentTime;
  points=points+1200;
}
}

void ledfunction(){
  for(int i=0;i<14;i++){
    leds[i]=CRGB::White;}
  for(int i=14;i<28;i++){
    leds[i]=CRGB::Blue;}
  for(int i=28;i<43;i++){
    leds[i]=CRGB::DarkRed;
    FastLED.show();}
    ledstate=0;
}




Code for Arduino Pro Mini

#include <AccelStepper.h>
#define dirPin 8
#define stepPin 9
#define motorInterfaceType 1
#define speed1 5
#define speed2 6
#define speed3 7
#define off 4


AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);  // Create a new instance of the AccelStepper class:
void setup() {
  // Set the maximum speed in steps per second:  stepper.enable();
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(100.0);
  pinMode(speed1 ,INPUT_PULLUP);
  pinMode(speed2 ,INPUT_PULLUP);
  pinMode(speed3 ,INPUT_PULLUP);
  pinMode(off, OUTPUT);
}

void loop() 
 {
  do{
  if(digitalRead(speed1)== LOW){
  stepper.setSpeed(800);
  stepper.run();}
  if(digitalRead(speed2)== LOW){
  stepper.setSpeed(1800);
  stepper.run();}
  if(digitalRead(speed3)== LOW){
  stepper.setSpeed(2800);
  stepper.run();}
  
  if(digitalRead(speed1)== HIGH && digitalRead(speed2)== HIGH && digitalRead(speed3)== HIGH)
  digitalWrite(off ,HIGH);
 }while (digitalRead(speed1)== HIGH && digitalRead(speed2)== HIGH && digitalRead(speed3)== HIGH);
  digitalWrite(off,LOW);

 }<br>

A Behind the Box & Let's Get Those Coins Hurdling

Coin Hurdle Rush P3