Diy Pinball with Arduino project

Building a homemade electromechanical pinball machine with Arduino, custom wooden ramps, solenoids and motors.

3 arcade buttons for the flips and the launcher, other buttons for the lights (leds on the table, the spotlight, the bumpers etc…) and for the ramps, the ball makes the contact between the rails. Also added a few sounds.







The flips and launcher are 24v solenoids and working. Maybe too powerful sometimes but it s just a matter of fine tuning of the levers.
What I wanna do now is add a « security » code on Arduino: i want the flips to go off after a few seconds, avoiding the solenoids to burn.
Not the best for gameplay but…
The delay fonction is not what i need i guess, and not sure about the millis…
Thanks in advance for any positive or negative
feedback, still a beginner in Arduino AND pinball construction!

Adrien

Definitely not. Why to destroy gaming experience with that kind of approach when better alternatives are likely available.
Manufacturer states : " Attention:
Power on continuously for 3 minutes, the temperature will rise to 80°C,"
Together with ED 30% it translates quite suitable for your approach without 2s limitation.
If you want to reduce current/heating, you could try with lower voltage like 18V, that would lower the power, force and heating almost to half.
Another option would be full 24V for initial push and then PWM at suitable duty cycle for hold.

I haven't played much pinball. We didn't have arcades where I grew up. But I seem to remember from 30ish years ago, that sometimes you want to hold a flipper button pressed to keep the flipper up. Is that what you are referring to here? And then you want a coded "safety" to release the solenoid after a few seconds?

If that is the case, could you find some kind of analog button or potentiometer in a button form to PWM the solenoid? Full press is full power, medium press is medium power, enough to hold the flipper.

You could still code in a safety for the players that don't understand how to use the button. Or adrenaline...

If the solenoid is fully powered and X amount of seconds have passed, cut the power.

If you are asking for help then "Showcase" is not the right catagory. I skipped over looking at you topic a few times because it was showcase.

Yes that s what I want to do.
Mostly in case of my children would keep the flip up for too long, or a malfunction somewhere. Solenoids are the most expensive pieces so far.
Which fonction can I use, millis?
Thanks.

What if...

When the button is pressed, a one-time pulse activates and deactivates the flipper solenoid AND rotates a servo "gate" that holds the flipper (not the solenoid) at a short distance/degree, perhaps, five degrees.

Only when the button is released, is the "gate" lowered, releasing the flipper.

#include <Servo.h>
Servo gate;

bool firsttime = true;
int buttonpin = 2, servopin = 3, solenoidpin = 13;
int gateup = 15, gatedown = 0, position = gatedown;

void setup() {
  pinMode(buttonpin, INPUT_PULLUP);
  pinMode(solenoidpin, OUTPUT);
  gate.attach(servopin);
  gate.write(position);
}

void loop() {
  if (digitalRead(buttonpin) == 0) { // if button is pressed
    if (firsttime == true) { // test for one-time solenoid activation
      digitalWrite(solenoidpin, HIGH); // activate solenoid.. LED_BUILTIN ON
      digitalWrite(solenoidpin, LOW); // deactivate solenoid... LED_BUILTIN OFF
      firsttime = false; // do not allow solenoid to activate
    }
    position = gateup; // block flipper from resetting
  } else { // button not pressed
    firsttime = true; // allow solenoid to activate
    position = gatedown; // allow flipper to reset
  }
  gate.write(position); // move gate to position
}

I haven't used servos much at all, other than playing around with them when I was bored. I was actually wondering before you posted if a servo can move fast enough to be a flipper??

@rupette If that's the case (in response to your post #6) then I agree with @jim-p that you should move your post to Projects >> General Guidance. Or there may be another better fit.

Also, it would appear as if it is time to post the code you have and the components you are currently using.

Why would the solenoids burn?
Are you supplying to much voltage?

I don’t think a servo could be powerful enough to be a flipper. But the idea is interesting, for keeping them up. At first I used 12v solenoids and they were way too weak.
I have now a separate 24v 10a supply for the solenoids, with mosfets and flyback diodes.
I ve been told that they could heat up pretty badly if activated for too long (20-30sec).
I posted here mostly to have general feedback on this thing. thank you for your time!

How could i do that? Millis?

Yes. If you are using digital read and digital write, when the button is pressed and your debounce time is over, record something like timer=millis;. Then you can use it in the following manner: if((buttonPressed) && (millis() - timer >= interval)){turn off solenoid code}

If you're using analog read and analog write to pwm the solenoid, the idea would be similar. Just capture the timer whenever the analog written value is greater than a number you're comfortable holding your solenoid at for very long. Does that make sense?

My apologies for not using code brackets. I'm on my cell phone right now and it's a rather pain in the rear to use the editing features while on my cell phone. If these don't make sense I will rewrite it when I get back to a computer later. Or someone else can rewrite it in the meantime.

One thing worth checking is whether the solenoids really need full power once they have reached their end position.

Many coils require a relatively high current to pull in, but can be held in position with much less current afterwards. If that is the case here, you could switch from a short full-power pulse to a lower hold voltage / current.

I have used that successfully with relays that had to stay energized for long periods: full voltage to activate, then reduced voltage to hold.

Maybe something similar is possible with your solenoids too.

That's a good idea.

Yes it does. Thanks, I ll also put my current code when on the computer. And maybe move my topic to the right section of the forum. And yes, the coils need their full power only for the initial kick, then much less is needed to maintain the position.

Probably not. The servo would be a "stopper" for the flipper in the "hold" position. Another solenoid could be used as the "gate" rather than a servo.

Give the code in Post #7 a try in a simulator (wokwi.com) with a button on pin 2 and a servo on pin 3.

diagram.json for wokwi
{
  "version": 1,
  "author": "xfpd",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": 4.8, "left": -0.5, "attrs": {} },
    {
      "type": "wokwi-pushbutton",
      "id": "btn1",
      "top": -41.8,
      "left": 153.6,
      "attrs": { "color": "green", "xray": "1" }
    },
    { "type": "wokwi-servo", "id": "servo1", "top": -155.6, "left": 163.2, "attrs": {} }
  ],
  "connections": [
    [ "nano:GND.1", "btn1:2.l", "black", [ "v0" ] ],
    [ "nano:GND.1", "servo1:GND", "black", [ "v0" ] ],
    [ "nano:5V", "servo1:V+", "red", [ "v0" ] ],
    [ "nano:2", "btn1:1.l", "green", [ "v0" ] ],
    [ "nano:3", "servo1:PWM", "green", [ "v0" ] ]
  ],
  "dependencies": {}
}

I didn't think the servos would move fast enough. I get your idea though.

Here is a concept derived from what I think @InquisitiveMind is saying. Based loosely on what I was thinking about the "safety don't burn the solenoid" code.

int interval = 500;  // 500 mS should be more than enough time to fully retract the solenoid




if (digitalRead(buttonPin) == LOW) {  //Or button press may read HIGH, depending on how it's wired

  if (millis based debounce code) {   //Don't forget to debounce the button

    analogWrite(solenoidPin, 255);    //Fully power solenoid to flip

    timer = millis();                 //Start inteval timer

    buttonPressed = true;             //Set boolean true for later use

  }

} else {

  analogWrite(solenoidPin, 0);  //If button not pressed, turn off solenoid

}




if (buttonPressed && millis() - timer >= interval) {  // Is button pressed and has interval elapsed? If so, rewrite solenoid pin.

  analogWrite(solenoidPin, 128);                      //Reduce solenoid power. Actual value may be derived from testing.

} 

This isn't really meant to be copied, pasted, and used directly. It is just an idea to be adapted to your requirements. It looks like you already have mosfet drivers? So something like this might work without reinventing the wheel.

It's impressive to see how much progress you've made so far. Projects like this always seem straightforward at the beginning, but once you start dealing with sensors, timing, solenoids, and game logic, the complexity adds up quickly.

I'm especially interested in how you're handling reliability and testing as more features get added. Have you run into any unexpected issues that required redesigning part of the hardware or code?

Good concept, but there is one important detail to watch out for.

If this code runs repeatedly while the button remains pressed, this part may also run repeatedly:

analogWrite(solenoidPin, 255);
timer = millis();

In that case the timer would be restarted again and again, and the code might never reach the reduced hold-power state.

So the full-power pulse should ideally be started only once, on the transition from "button not pressed" to "button pressed", not continuously while the button is held down.

In other words: detect the button edge, start the full-power pulse once, then after the interval switch to the hold PWM value as long as the button remains pressed.

My code (post #7, "in theory") sends one "pulse" to actuate the solenoid, then de-energizes the solenoid, so it is ON and OFF immediately. The servo (when timed right) traps the flipper in the "on" position, so no "safety" timing is needed for the solenoid. When the button is released, the servo gate falls, allowing the flipper to return home.