Arduino Uno as LED Coin Counter with JAMMA Interface

Hi everyone,

I'm new to Arduino so would really appreciate some guidance on this project which is almost complete!

I am in the process of designing an arcade cabinet styled after a Neo Geo MVS and I wanted to include LED coin counters. Arduino seemed like a great way to do it so I have been using Tinkercad to simulate my design. There will be an 'insert coin' button on the outside of the cabinet that will be connected to the Arduino between Digital 13 and 5V. On the picture below I'm just using a push button to represent that external switch.

The circuit uses 2 x 7-segment Common Cathode displays and the hardware selection is limited to this as it's all I can source locally. It is coded to count up to 99 and then loop back to 1. If you hold the button for >1 second it resets the counter back to zero.

So far so good... the last thing I would like to do is somehow interface this with the JAMMA connector inside the cabinet. The goal is that when the 'insert coin' button is pressed, it increments the LED coin counter and simultaneously adds a coin in the game itself. This requries that pin 16 from the JAMMA harness to be connected to ground when the 'insert coin' button is pressed. I assume I need to use a relay but would really appreciate some guidance on what specific type (part number?) of relay and exactly how to wire it in.

One other thing I'd like to verify, does the push button wiring setup with the 1kOhm resistor look okay as well or is there a better way to do that?

I can post the code if it's useful but this is more of a hardware/wiring question. Thanks in advance.

John

The best way to wire your push button is one side to ground, the other to your input pin. Then, in your code, you declare the pin as INPUT_PULLUP which enables the pull-up resistor inside the arduino. No external resistor required.

Another handy tip is that if you are using a 4 pin pushbutton like your image shows, use the 2 pins in the diagonal corners (either pair). This way, it does not matter if you rotate your button 90 degrees

1 Like

Thanks for the tip regarding the pin 13 wiring configuration. I've amended the design as per your suggestion and updated the code to match as well so that's working. In this case the push button is just representing an external switch but good to know that recommendation for future projects!

Regarding the relay, I think I have some idea how to wire it now. With Tinkercad I'm limited to using an SPDT (6 pin) type relay but I think a smaller and simpler SPNO (4 pin) would suffice as per the below wiring.

Would this TE Connectivity OJ-SH-105LM,000 relay wired as above give the desired effect? So when the 'insert coin' button is pressed JAMMA Pin 16 is grounded and the coin counter will increment?

Thanks,
John

What is this JAMMA pin 16? You say it goes to ground when a coin is inserted. What voltage level is it at when no coin is present? 5V? 12V? I don't see why you need a relay in this design. Does the pin just float and is pulled to ground?

1 Like

Thanks again for taking the time to look at the project.

The JAMMA inputs need to be connected to ground to trigger a button press signal. Normally a push button is connected between ground and each pin. When you push the button the pin is connected to ground. There is no voltage there as I understand so I suppose they are just floating.

I didn't want to connect it directly to the circuit with Pin 13 as I didn't want this 5V from the Arduino to go to the JAMMA pin. If I didn't use a relay how else can I pull this JAMMA pin to ground when the button is pressed?

Do I have this straight?

You have an "insert coin" button that is wired to your arduino.
The user presses this button which does 2 things

  • increment the coin counter
  • sends a signal on the JAMMA pin by pulling it LOW

If all that is true, you don't need the relay, just connect one of the arduino pins directly to this JAMMA pin. Define the pin as INPUT when you are not doing anything. When the button is pressed, change the pin to OUTPUT and drive it LOW. Wait a small amount of time and then change it back to an INPUT.

If you want to be extra careful, you can put a resistor between the arduino pin and the JAMMA connection to limit the amount of current the arduino will have to sink when it pulls the line low.

1 Like

Yep, you have it absolutely right.

I thought that pulling LOW on an Arduino pin will still have some resistance rather than ˜0 Ohm so it might not register the button press on the JAMMA. The current will be so small I don't think the resistor is needed, my concern was more pulling it to 'true' ground I suppose.

I simulated it on Tinkercad using a multimeter just to see the effect of connecting the pin to ground and it shows a minimum of 50 Ohm resistance. I am aware that this is most likely just a limit in my knowledge of the Arduino and most probably it is pulling the pin to ground just fine :slightly_smiling_face: the real wiring would just be JAMMA pin 16 to Arduino pin A5.

Thanks!

I posted the code below for reference. It has a lot of Serial.print there just for my learning and understanding.

// Designate Pin Assignments
const int pinA1 = 2;
const int pinB1 = 3;
const int pinC1 = 4;
const int pinD1 = 5;
const int pinE1 = 6;
const int pinF1 = 7;
const int pinG1 = 8;
const int pinA2 = 9;
const int pinB2 = 10;
const int pinC2 = 11;
const int pinD2 = 12;
//const int pinE2 = A0; Analog pins not integers so written manually
//const int pinF2 = A1; Analog pins not integers so written manually
//const int pinG2 = A2; Analog pins not integers so written manually
//const int jamma = A5; Analog pins not integers so written manually
const int button = 13;

// Initialize Button & Counter States
int counter1 = 0; // Initial value of Digit 1
int counter2 = 0; // Initial value of Digit 2
int buttonState = 0; // Current Button State
int lastButtonState = 0; // Previous Button State
int buttonPressed = 0; // Start of Button Press
int buttonReleased = 0; // End of Button Press
int pressedTime = 0; // Duration of Button Press
int releasedTime = 0; // Duration of Released Button
int long_press = 1000; // Long Press duration
int short_press = 50; // Short Press duration       

void setup()
{
  Serial.begin(9600); 
// Designate Pin Modes
  pinMode(pinA1, OUTPUT);
  pinMode(pinB1, OUTPUT);
  pinMode(pinC1, OUTPUT);
  pinMode(pinD1, OUTPUT);
  pinMode(pinE1, OUTPUT);
  pinMode(pinF1, OUTPUT);
  pinMode(pinG1, OUTPUT);
  pinMode(pinA2, OUTPUT);
  pinMode(pinB2, OUTPUT);
  pinMode(pinC2, OUTPUT);
  pinMode(pinD2, OUTPUT);
  pinMode(A0, OUTPUT); //pinE2
  pinMode(A1, OUTPUT); //pinF2
  pinMode(A2, OUTPUT); //pinG2
  pinMode(button, INPUT_PULLUP);
  pinMode(A5, INPUT); //JAMMA pin
// Initially Display 00
  digitalWrite(pinA1, HIGH);
  digitalWrite(pinB1, HIGH);
  digitalWrite(pinC1, HIGH);
  digitalWrite(pinD1, HIGH);
  digitalWrite(pinE1, HIGH);
  digitalWrite(pinF1, HIGH);
  digitalWrite(pinG1, LOW);
  digitalWrite(pinA2, HIGH);
  digitalWrite(pinB2, HIGH);
  digitalWrite(pinC2, HIGH);
  digitalWrite(pinD2, HIGH);
  digitalWrite(A0, HIGH); //pinE2
  digitalWrite(A1, HIGH); //pinF2
  digitalWrite(A2, LOW);  //pinG2
} 

// Updated Counter Code with Reset Function - In Progress    
void loop() 
{
  buttonState = digitalRead(button); //Read Initial Button State
  if (buttonState != lastButtonState) // Button State has changed
  {
    //Runs after Button Pressed
    if (buttonState == LOW)
    {
      buttonPressed = millis();
      releasedTime = buttonPressed - buttonReleased;
      Serial.println("Button Pressed");
    }
    //Runs after Button Released
    if (buttonState == HIGH)
    {
      buttonReleased = millis();
      pressedTime = buttonReleased - buttonPressed;
      Serial.println("Button Released");
      Serial.print("Press Duration ");
      Serial.print(pressedTime);
      Serial.println("ms");
      if (pressedTime > long_press)
      // Reset counter to 00
      {
        counter1 = 0;
        counter2 = 0;
        changeNumber1(counter1);
        changeNumber2(counter2);
        Serial.print("Counter Reset to ");
        Serial.print(counter2);
        Serial.println(counter1);
        //Delaying by 100 ms
        //delay(100);
      }
      if ((pressedTime > short_press) && (pressedTime <long_press))
        // Start Counting
      {
        //Restart Counting after 99
        if((counter2 == 9) && (counter1 == 9)) 
        {
          counter2 = 0;
          counter1 = 0;
        }
        //Increase the counter 2nd digit
        if(counter1 == 9)
        {
          counter1 = -1;
          counter2++;
        }  
        //Increase the counter 1st digit
        counter1++;
        //Display The Current Number
        changeNumber1(counter1);
        changeNumber2(counter2);
        Serial.print("Counter Incremented to ");
        Serial.print(counter2);
        Serial.println(counter1);
        pinMode(A5, OUTPUT); //JAMMA pin set to output temporarily
        Serial.println("Set JAMMA pin to Output");
        digitalWrite(A5, LOW); //Pull JAMMA pin to ground
        Serial.println("JAMMA pin LOW");
        delay(50); //Duration pin is pulled to ground
        pinMode(A5, INPUT);
        Serial.println("Reset JAMMA pin to Input");
      }
      //Delay to avoid button bouncing
      //delay(100);
    }
  lastButtonState = buttonState; // Update Button State for the next loop
  }    
}

//Basic Counter Code without Reset Function - Legacy Code
//void loop() 
//{
//  if (buttonState != lastButtonState) 
//  {
//    if (buttonState == HIGH)
//    {
//      //Restart Counting
//      	if((counter2 == 9) && (counter1 == 9)) 
//      	{
//        	counter2 = 0;
//       	counter1 = 0;
//      	}
//      	if(counter1 == 9)
//      	{
//        	counter1 = -1;
//        	counter2++;
//      	}  
//      	//Increase the counter by 1
//      	counter1++;
//      	//Display The Current Number
//      	Serial.println(counter1);       
//      	changeNumber1(counter1);    
//      	Serial.println(counter2);
//      	changeNumber2(counter2);
//      	//Delaying by 100 ms
//      	delay(100);
//      }
//    else
//   	{
//      Serial.println("OFF"); 
//    }
//    //Delay to avoid button bouncing
//    delay(100);
//    lastButtonState = buttonState;
//  }
//}

void changeNumber1(int buttonPress)  
{
  switch(buttonPress)
  {
    case 0: 
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, HIGH);
    digitalWrite(pinE1, HIGH);
    digitalWrite(pinF1, HIGH);
    digitalWrite(pinG1, LOW);
    break;
    case 1: 
    digitalWrite(pinA1, LOW);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, LOW);
    digitalWrite(pinE1, LOW);
    digitalWrite(pinF1, LOW);
    digitalWrite(pinG1, LOW);
    break; 
    case 2:
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinC1, LOW);
    digitalWrite(pinD1, HIGH);
    digitalWrite(pinE1, HIGH);
    digitalWrite(pinF1, LOW);
    digitalWrite(pinG1, HIGH);
    break; 
    case 3:
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, HIGH);
    digitalWrite(pinE1, LOW);
    digitalWrite(pinF1, LOW);
    digitalWrite(pinG1, HIGH);
    break; 
    case 4:
    digitalWrite(pinA1, LOW);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, LOW);
    digitalWrite(pinE1, LOW);
    digitalWrite(pinF1, HIGH);
    digitalWrite(pinG1, HIGH);
    break; 
    case 5: 
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinB1, LOW);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, HIGH);
    digitalWrite(pinE1, LOW);
    digitalWrite(pinF1, HIGH);
    digitalWrite(pinG1, HIGH);
    break;
    case 6: 
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinB1, LOW);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, HIGH);
    digitalWrite(pinE1, HIGH);
    digitalWrite(pinF1, HIGH);
    digitalWrite(pinG1, HIGH);
    break; 
    case 7:
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, LOW);
    digitalWrite(pinE1, LOW);
    digitalWrite(pinF1, LOW);
    digitalWrite(pinG1, LOW);
    break; 
    case 8: 
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, HIGH);
    digitalWrite(pinE1, HIGH);
    digitalWrite(pinF1, HIGH);
    digitalWrite(pinG1, HIGH);
    break; 
    case 9: 
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinC1, HIGH);
    digitalWrite(pinD1, HIGH);
    digitalWrite(pinE1, LOW);
    digitalWrite(pinF1, HIGH);
    digitalWrite(pinG1, HIGH);
    break;
  }
}

void changeNumber2(int buttonPress)  
{
  switch(buttonPress)
  {
    case 0: 
    digitalWrite(pinA2, HIGH);
    digitalWrite(pinB2, HIGH);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, HIGH);
    digitalWrite(A0, HIGH);
    digitalWrite(A1, HIGH);
    digitalWrite(A2, LOW);
    break;
    case 1: 
    digitalWrite(pinA2, LOW);
    digitalWrite(pinB2, HIGH);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, LOW);
    digitalWrite(A0, LOW);
    digitalWrite(A1, LOW);
    digitalWrite(A2, LOW);
    break; 
    case 2:
    digitalWrite(pinA2, HIGH);
    digitalWrite(pinB2, HIGH);
    digitalWrite(pinC2, LOW);
    digitalWrite(pinD2, HIGH);
    digitalWrite(A0, HIGH);
    digitalWrite(A1, LOW);
    digitalWrite(A2, HIGH);
    break; 
    case 3:
    digitalWrite(pinA2, HIGH);
    digitalWrite(pinB2, HIGH);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, HIGH);
    digitalWrite(A0, LOW);
    digitalWrite(A1, LOW);
    digitalWrite(A2, HIGH);
    break; 
    case 4:
    digitalWrite(pinA2, LOW);
    digitalWrite(pinB2, HIGH);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, LOW);
    digitalWrite(A0, LOW);
    digitalWrite(A1, HIGH);
    digitalWrite(A2, HIGH);
    break; 
    case 5: 
    digitalWrite(pinA2, HIGH);
    digitalWrite(pinB2, LOW);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, HIGH);
    digitalWrite(A0, LOW);
    digitalWrite(A1, HIGH);
    digitalWrite(A2, HIGH);
    break;
    case 6: 
    digitalWrite(pinA2, HIGH);
    digitalWrite(pinB2, LOW);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, HIGH);
    digitalWrite(A0, HIGH);
    digitalWrite(A1, HIGH);
    digitalWrite(A2, HIGH);
    break; 
    case 7:
    digitalWrite(pinA2, HIGH);
    digitalWrite(pinB2, HIGH);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, LOW);
    digitalWrite(A0, LOW);
    digitalWrite(A1, LOW);
    digitalWrite(A2, LOW);
    break; 
    case 8: 
    digitalWrite(pinA2, HIGH);
    digitalWrite(pinB2, HIGH);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, HIGH);
    digitalWrite(A0, HIGH);
    digitalWrite(A1, HIGH);
    digitalWrite(A2, HIGH);
    break; 
    case 9: 
    digitalWrite(pinA2, HIGH);
    digitalWrite(pinB2, HIGH);
    digitalWrite(pinC2, HIGH);
    digitalWrite(pinD2, HIGH);
    digitalWrite(A0, LOW);
    digitalWrite(A1, HIGH);
    digitalWrite(A2, HIGH);
    break;
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.