Pinball Machine

42

2

Needed to present a project on Instructables one time...

This is an easy to use pinball machine! It's relatively small (A3 size) and can be adjusted to what you feel most comfortable with.

It incorporates the following:

- Arduino

- Autodesk Fusion 360

- Soldering (optional)

- 4 screws (1.5mm width, and around 8mm height)

- 3D printing

- 1 Potentiometer

- 2 servos

- 1 ultrasonic sensor

- 1 LED

Step 1: The Coding

For the pinball machine to work we need to use code in Arduino. The code will control the ultrasonic sensor, the LED, the potentiometer (which will control the servos), and the servos which will act as the flippers for the pinball machine.

Below is the full code with descriptions of what they do in relation to how things will operate.

#define LED1 13 // This tells the location of the LED
#define potPin A0 // This tells the location of the potentiometer #define servoPin 3 // This tells the location of "myServo" #define servoPeg 5 //This tells the location of "meServo" #define triggerPin 2 // This tells the location of the trigger pin on the ultrasonic sensor #define echoPin 4 // This tells the location of the echo pin on the ultrasonic sensor #define maxDistance 5 //This sets the distance that the ultransonic sensor can detect to five centimeters #include //Includes the code from "Servo.h" library Servo myServo; //Sets the name for one servo to be "myServo" this distinguishes it from the other servo Servo meServo; //Sets the name for the other servo to be "meServo" #include "NewPing.h" //Includes the set of commands and code from the "NewPing.h" library NewPing sonar(triggerPin, echoPin, maxDistance); //Trigger pin sends pulse, echo pin receives pulse, the pulse is up to 5cm void setup() { //The following code runs once at the start of the program pinMode(LED1, OUTPUT); //The LED is set as an output, this allows it to emit light pinMode(potPin, INPUT); //The potentiometer is set as an input so that it's capable of reading analogue signals myServo.attach(servoPin); //Links "myServo" to the value of "servoPin" meServo.attach(servoPeg); //Links "meServo" to the value of "servoPeg" Serial.begin(9600); //We need this line of code to start the serial communication, 9600 bits per second is the rate of communication } void loop() { //Loops the following code continuously int potReading = analogRead(potPin); //This reads the value of the potPin (between 0-1023), this value is being sent off because of the analogRead Serial.print(potReading); //The value from the potentiometer can be displayed on the device being used with this line of code int servoPos = potReading*0.179; //The angle of the servo depends on what value the potentiometer sends, this value gets converted from 0-1023 to 0-179 Serial.print(" --> "); //Displays an arrow on the serial monitor Serial.println(servoPos); //This tells what value needs to be sent to the device (in this case it is the servo position) myServo.write(servoPos); //This writes the value of "servoPos" into "myServo" thus making the servo move accordingly to the potentiometer meServo.write(servoPos); //This writes the value of "servoPos" into "meServo" thus making the servo move accordingly to the potentiometer delay(1); //The time of delay between the potentiometer movement and servo movements is 1 millisecond delay(5); //The delay of time between pings of the ultrasonic sensor is 5 milliseconds int distance = sonar.ping_cm(); //The "distance" variable is how far something is (cm) from the ultrasonic sensor Serial.print("Ping: "); //Displays the word "ping" on the serial monitor Serial.print(distance); //The distance of an object to the potentiometer can be displayed on the device being used with this line of code Serial.println(" cm"); //This tells what value needs to be sent to the device (in this case it is the distance in centimeters) if ((distance <= 5)&&(distance !=0)){ //If the ultrasonic sensor detects something between 0 - 5 centimeters it will trigger something digitalWrite(LED1, HIGH); //In this case when something is detected by the ultrasonic sensor between the distance of 0 - 5 centimeters it will turn an LED on } else{ //When something which hasn't been outlined in the "if" command happens it will trigger the following digitalWrite(LED1, LOW); // In this case when nothing is detected by the ultransonic sensor between the distances of 0 - 5 centimeters the LED will remain or turn off }

}

Step 2: The 3D Modelling

To create this pinball machine we need to use Autodesk Fusion 360 to model blocks and obstacles, the ball, and the flippers. Some of the files for the 3D modelling can be used to print more than one of the same thing, this can add more obstacles and blocks to the game. Add what you feel will bring you the most joy!

Attached are the files for the 3D modelling:

Step 3: Circuit Layout

Now that we have all our code and parts, we need to assemble it all together, above is a circuit diagram outlining how to assemble all Arduino controlled parts. Note that to gain greater connection with the potentiometer, and to create a stronger hold between it and the wires it is advised that if possible you should solder the wires to the pins on the potentiometer.

Step 4: Connecting to the Board

When connecting the circuit layout to the board of the pinball machine, make sure you have at least an A3 sized piece of cardboard (preferably with sides to act as walls).

1.On the piece of cardboard place the 3D printed blocks where you feel they'd work best, trace around the extruded bottom part.

2. Once you've traced an outline of the blocks cut out the area inside the outline (as shown in the picture above).

3. Once there are holes in the cardboard, place the bottom part of the blocks into them (as shown in the picture above), if they don't fit repeat steps 1 and 2 so that you get a bigger hole for the piece to fit in.

4. At the end of the cardboard leave a flattened bit with no walls, in this area cut out a small rectangle for the ultrasonic sensor to fit in.

5. Next, use screws (1.5mm width, around 8mm height) to connect the 3D printed flippers to the servos.

6. Next, trace the bottom of the servos out onto the cardboard - leaving at least a 5cm gap between these and the ultrasonic sensor, cut out the inside of this outline then place the two servos in their respective holes (with flipper attached).

7. Check that the servos are able to support the cardboard, with a gap of only 1.5cm maximum between the middle of flippers and the top of the cardboard. If this isn't the case use super glue on the servos to line the flippers up with the cardboard. (Reference above picture for steps 4 - 7)

8. To help move the ball back to the flippers, you can lean cardboard from the wall to the edge of the servo (seen in the picture above).

Step 5: Playing the Game

Now simply plug a USB cable from a laptop or desktop into the Arduino board, upload the code, and get playing!

HOW TO PLAY:

The basic way to play is through turning the potentiometer, instead of a conventional button for individual flippers, the potentiometer will move both flippers depending on how much you turn it. When the ball gets within 5cm of the ultrasonic sensor the LED will be set off. To make the game more interesting add values to the blocks on the board, aiming to achieve the highest score by hitting the most obstacles.

Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • PCB Contest

      PCB Contest
    • First Time Author

      First Time Author

    2 Discussions