I have a pinball bumper that has contacts on the top and bottom. The ball goes into the bumper, joining the contacts and closing the circuit.
I want the ‘button / switch’ that is created to both trigger the solenoid and to add to the player’s score. I can do that by simply running the solenoid on 12V and using the button to close the circuit but I don’t think that the arduino will ‘catch’ the button press.
I have a feeling that with buttons for flippers, servos and several bumpers, the likelihood of the arduino checking the state of the switch at the exact time that the ball hits is very slim. I may end up changing the servos out for solenoids so that will speed up the system.
Is there a way of ‘capturing’ the state of the button with some sort of electronic component until the arduino catches up? Is there a capacitor that can be energised and checked? (I have very little knowledge of capacitors and what they do) Could the 12V of the solenoid circuit be used to change the state of a physical component that can then be checked rather than a boolean state that only changes if the button is being checked at the exact same time the ball hits it?
A couple of solutions come to mind:
- Interrupts (Code). The Arduino supports hardware interrupts - the Interrupt Service Routine can handle incrementing the score. See Chapter 5.4 of the Arduino Workshop. Beware of debouncing the signal - chatter in the switch happens at a much slower timescale than the microcontroller operates which can result in firing the ISR multiple times for one event. Debouncing can be done in hardware or software or both.
- Latches (Hardware). The state can be captured with an SR-latch which can be read at leisure by the microcontroller and then reset. Beware - if you don’t service the SR latch frequently enough then you have the same problem of missing scores.
- What do existing pinball machines do? Surely this must be a solved problem! Do you have any schematics at hand?
Thanks for the awesome advice! I think the Interrupt Service Routine is exactly what I’m after. I had no idea that the arduino was capable of that. The video that you linked to was great in explaining what it is and how it can be used. I will definitely be using that system. The SR-latch looks like its a bit out of my very low level league. I don’t have any schematics on hand. I do know a pinball machine fanatic but he’s out of town at the moment so not much help to me.
I will be using the same contacts to close the 12V solenoid circuit and the button to tell the arduino the bumper has been hit. I assume that I need a voltage regulator to send 5V back to the pin rather than the 12V flowing through the contacts. Correct?
A voltage regulator is for power supplies. You are dealing with a logic level, which is very low current. You would use either a logic level converter or a voltage divider to ensure that the voltage is at an appropriate level for the MCU. You should also have some debouncing, because the logic signal you are creating from the button and bumper will be very noisy.
Description of logic level shifting:
A Quick Guide on Logic Level Shifting : 5 Steps (with Pictures) - Instructables
Note that a logic level converter will usually be designed for the logic levels of 5V and 3.3V, not the 12V you will be dealing with.
Debouncing is described here:
Switch Bounce and How to Deal with It - Technical Articles (allaboutcircuits.com)