Greetings All!
So I've got a fun project that I'm making good progress on that I want to share and ask for advice. As a bit of introduction, I've never used or coded with Arduino but knew a bit of visual basic and wrote a few AutoCAD lisp routines some years back. I'm a lifelong tinkerer and always enjoy taking on various projects.
So, I have an old single player pinball machine (Home Run (Gottlieb 1972)) and the score reels max out at 99,990. With my friends and I typically scoring well over 300k it is sometimes hard to remember how many times the score has "rolled over". On the backglass just above the score reels is 9 evenly spaced flags so I thought it would be cool to have a light turn on behind a flag whenever the score rolled over. Well, I just happen to have a bunch of pre-wired LED's and an Arduino Nano so here we go!
The area behind the backglass only needed to be slightly modified to make room for a 3D printed LED holder. I use AutoCAD every day so designing the holder was the easy part. I was able to add a leaf switch to the switch stack on the score reel itself that will stay closed while on the "9" digit. The switch then opens when the reel changes to the "0" digit. My plan was to have the Nano monitor the switch and when it goes from HIGH to LOW it will add to a counter. The Nano will then light the appropriate number of LEDs depending on the counter. I also want to reset the counter whenever a new game is started.
Additionally, I would like to use the pinball machine to power the Arduino. This machine transforms standard US 120VAC into 2 voltages (25VAC and 6VAC) that I can easily tap in to. Any advice on the best way to convert these voltages into something the Nano can use would be great.
So here is where I am on this project. I have the LEDs and score reel switch connected to the Nano and shown in the schematic. I am using a USB adapter for power...a 2A wall wart. This seems to work fine on the test bench but not in the pinball machine. The LEDs light in the correct order but not when I want them to light (they turn on early). I feel like this is a power issue (assuming the code is correct) and the Nano is going from HIGH to LOW too often. I completely took the switch out of the equation with a jumper wire and the results were the same. I have also tried various values for the switch resistor (R10) up to 20k.
My process is as follows:
With everything wired up and the Nano powered on I will manually hit a switch on the pinball playfield worth 5,000 points. I continue to hit the 5,000 point switch and the first LED will light well before the reel gets to the "9" digit. In fact, 5 or more of the LEDs will light up before turning over to "0". What's strange though is that this occurs even when I bypass the switch with a jumper wire. Remember, this is an older machine and there is a lot of vibration and noise when points are registered and a bell clangs each time I hit the 5,000 point switch. Could that have any effect on this since this behavior doesn't occur when idle?
My next step this evening after work was going to be using an old PC power supply to feed 5V to the D13 pin through the switch.
So here is what I am hoping to get some help guidance on:
-
How does my code look and will it achieve what I am aiming to do?
-
Does the circuit schematic look correct?
-
How can I utilize the readily available 25VAC or 6VAC power in the pinball machine?
I hope this is the correct forum for this post.
Thanks,
Robb
// constants won't change:
const int LEDpin1K = 2; // 100,000 LED
const int LEDpin2K = 3; // 200,000 LED
const int LEDpin3K = 4; // 300,000 LED
const int LEDpin4K = 5; // 400,000 LED
const int LEDpin5K = 6; // 500,000 LED
const int LEDpin6K = 7; // 600,000 LED
const int LEDpin7K = 8; // 700,000 LED
const int LEDpin8K = 9; // 800,000 LED
const int LEDpin9K = 10; // 900,000 LED
const int NEWgamepin = 12; // pin to reset count at start of new game
const int OVERpin = 13; // score roll-over pin
//Variables will change:
int OVERState; // variable for reading current state of OVERpin
int lastOVERState = HIGH; // variable to store previous state of OVERpin (initialized as HIGH)
int k = 0; // counting variable
int NEWgame = HIGH; //New game reset variable
unsigned long lastDebounceTime = 0; // will store last time LED was updated
const long interval = 500; // interval to wait before updating "k" count (milliseconds)
void setup() {
pinMode(LEDpin1K, OUTPUT); // set LED pins as OUTPUT
pinMode(LEDpin2K, OUTPUT);
pinMode(LEDpin3K, OUTPUT);
pinMode(LEDpin4K, OUTPUT);
pinMode(LEDpin5K, OUTPUT);
pinMode(LEDpin6K, OUTPUT);
pinMode(LEDpin7K, OUTPUT);
pinMode(LEDpin8K, OUTPUT);
pinMode(LEDpin9K, OUTPUT); // set LED pins as OUTPUT
pinMode(NEWgamepin, INPUT_PULLUP); // wire this pin to new game relay on pinball machine
pinMode(OVERpin, INPUT_PULLUP); // wire this pin to switch1 which triggers when score hits multiples of 100,000
}
void loop() {
OVERState = digitalRead(OVERpin); //check the state of OVERpin
unsigned long currentDebounceTime = millis();
if (currentDebounceTime - lastDebounceTime >= interval) {
lastDebounceTime = currentDebounceTime; // save the last time you lit an LED
// compare the OVERState to its previous state
if (OVERState != lastOVERState) {
lastOVERState = OVERState; // save the current state as the last state for next time through the loop
// if the state has changed check if OVERpin is HIGH
if (OVERState == HIGH) {
// if the current state is HIGH then switch1 went from closed to open, increment the counter
k++;
}
}
}
// NEWgame = digitalRead(NEWgamepin); //check state of NEWgamepin
// while (NEWgamepin == HIGH) {
// k = 0; //if NEWgamepin is triggered reset the "k" variable
// delay(5000); //stop reading for a bit to allow pinball machine to cycle through the start-up procedure
// }
// Light the correct LED's to indicate rollover score
if (k >= 10) k = 0; //start lights over after reaching 10x multiples of a million
if (k <= 0) { // No lights on
digitalWrite(LEDpin1K, LOW);
digitalWrite(LEDpin2K, LOW);
digitalWrite(LEDpin3K, LOW);
digitalWrite(LEDpin4K, LOW);
digitalWrite(LEDpin5K, LOW);
digitalWrite(LEDpin6K, LOW);
digitalWrite(LEDpin7K, LOW);
digitalWrite(LEDpin8K, LOW);
digitalWrite(LEDpin9K, LOW);
}
if (k == 1) { // 100,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, LOW);
digitalWrite(LEDpin3K, LOW);
digitalWrite(LEDpin4K, LOW);
digitalWrite(LEDpin5K, LOW);
digitalWrite(LEDpin6K, LOW);
digitalWrite(LEDpin7K, LOW);
digitalWrite(LEDpin8K, LOW);
digitalWrite(LEDpin9K, LOW);
}
if (k == 2) { // 200,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, HIGH);
digitalWrite(LEDpin3K, LOW);
digitalWrite(LEDpin4K, LOW);
digitalWrite(LEDpin5K, LOW);
digitalWrite(LEDpin6K, LOW);
digitalWrite(LEDpin7K, LOW);
digitalWrite(LEDpin8K, LOW);
digitalWrite(LEDpin9K, LOW);
}
if (k == 3) { // 300,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, HIGH);
digitalWrite(LEDpin3K, HIGH);
digitalWrite(LEDpin4K, LOW);
digitalWrite(LEDpin5K, LOW);
digitalWrite(LEDpin6K, LOW);
digitalWrite(LEDpin7K, LOW);
digitalWrite(LEDpin8K, LOW);
digitalWrite(LEDpin9K, LOW);
}
if (k == 4) { // 400,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, HIGH);
digitalWrite(LEDpin3K, HIGH);
digitalWrite(LEDpin4K, HIGH);
digitalWrite(LEDpin5K, LOW);
digitalWrite(LEDpin6K, LOW);
digitalWrite(LEDpin7K, LOW);
digitalWrite(LEDpin8K, LOW);
digitalWrite(LEDpin9K, LOW);
}
if (k == 5) { // 500,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, HIGH);
digitalWrite(LEDpin3K, HIGH);
digitalWrite(LEDpin4K, HIGH);
digitalWrite(LEDpin5K, HIGH);
digitalWrite(LEDpin6K, LOW);
digitalWrite(LEDpin7K, LOW);
digitalWrite(LEDpin8K, LOW);
digitalWrite(LEDpin9K, LOW);
}
if (k == 6) { // 600,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, HIGH);
digitalWrite(LEDpin3K, HIGH);
digitalWrite(LEDpin4K, HIGH);
digitalWrite(LEDpin5K, HIGH);
digitalWrite(LEDpin6K, HIGH);
digitalWrite(LEDpin7K, LOW);
digitalWrite(LEDpin8K, LOW);
digitalWrite(LEDpin9K, LOW);
}
if (k == 7) { // 700,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, HIGH);
digitalWrite(LEDpin3K, HIGH);
digitalWrite(LEDpin4K, HIGH);
digitalWrite(LEDpin5K, HIGH);
digitalWrite(LEDpin6K, HIGH);
digitalWrite(LEDpin7K, HIGH);
digitalWrite(LEDpin8K, LOW);
digitalWrite(LEDpin9K, LOW);
}
if (k == 8) { // 800,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, HIGH);
digitalWrite(LEDpin3K, HIGH);
digitalWrite(LEDpin4K, HIGH);
digitalWrite(LEDpin5K, HIGH);
digitalWrite(LEDpin6K, HIGH);
digitalWrite(LEDpin7K, HIGH);
digitalWrite(LEDpin8K, HIGH);
digitalWrite(LEDpin9K, LOW);
}
if (k == 9) { // 900,000 light on
digitalWrite(LEDpin1K, HIGH);
digitalWrite(LEDpin2K, HIGH);
digitalWrite(LEDpin3K, HIGH);
digitalWrite(LEDpin4K, HIGH);
digitalWrite(LEDpin5K, HIGH);
digitalWrite(LEDpin6K, HIGH);
digitalWrite(LEDpin7K, HIGH);
digitalWrite(LEDpin8K, HIGH);
digitalWrite(LEDpin9K, HIGH);
}
}