Mini Baseball Game
Here is our miniature baseball game. Follow our instructions to make your own! Here is a video link to help you create it:
Downloads
Supplies
From the Sparkfun Inventors Kit v.4.1.2
- 1 Arduino Uno
- 1 Small Breadboard
- 4 buttons
- 1 Servo Motor
- Enough Wires
- 3 LEDS (One of Each Color)
- 3 330 ohm resistors
Outside of the Kit
- Package of Marbles-Marbles
- Mini Baseball Bats-Baseball Bats
- Cardboard Sheets-Cardboard Sheets
- Hot Glue Gun
- Markers/Paint (Optional)
- Boxcutter/Scissors (some way to cut cardboard)
Constructing the Base of the Field
- For infield-cut two sheets of cardboard into 8x8 squares
- For left field lay another sheet long ways in line with the infield. Cut 2 inches up and 8 inches to the left for two sheets. Then mark 2 inches from the leftmost corner on both to the right and below the corner. Then, cut an arc between the two marks.
- Do the same thing for right field, except two inches up and 8 inches right.
- For center field, line up another sheet in between the left field and right field pieces, with the bottom right corner touching the top corner of the infield. Mark 6 inches to the left of the corner and 6 inches up from the corner and cut an arc between the two marks.
- Using the pieces cut from the left and right fields, on the end towards the infield start cutting two inches to the left and cut diagonally to the bottommost corner.
- Glue all pieces together in a baseball field shape.
Constructing the Rest of the Field
- Evenly space six to eight holes near the back wall of the baseball field. Cut to whatever size desired (ours were 1.5 inches long, ¾ inch wide.)
- Glue all the pieces together with hot glue and cut two-inch pieces of cardboard for the walls on the outside, glue them too.
- Cut two triangles and a straight piece of cardboard to create the mound for pitching. Hot glue it to the center of the field.
- Cut out inch-high pieces of cardboard as supports or legs to go underneath the board. Do this to hide the wires/technology.
- Cut a hole for the servo motor. Start small and keep enlarging until servo fits well into the hole in bottom of field.
Wiring
- Begin by connecting the breadboard to the Arduino Uno by wiring both a power wire and a ground wire between the two.
- Wire both a ground and power wire from the bottom of the breadboard to the top of the breadboard.
- Wire the Servo motor by wiring both a ground and power wire from the Servo to the breadboard. Then wire the signal port from the Servo to Pin 9 on the Arduino board.
- Wire the swing button, with one wire going to ground and the other going to Pin 2 on the Arduino Board.
- Wire the 3 Leds, connecting all of their left sides to the ground on the breadboard. Then put a resistor on the right side of each LED. For the Red LED, wire the right side to Pin 7. For the Green LED, wire the right side to Pin 8. For the Yellow LED, wire the right side to Pin 6.
- Wire the 3 Buttons, connecting each button's left side to the ground on the breadboard. Then for the Green button, wire its right side to Pin 5. For the Red button, wire its right side to Pin 4. For the Yellow Button, wire its right side to Pin 3
- Put the speaker on the breadboard. Positive to pin three, negative to ground.
Constructing the Box
- Create a box that can house the electronics and cut holes to press the buttons. Feel free to decorate it however you feel necessary.
Code
//Baseball game code
//assigning all of the wires for the LEDS, buttons, and the speaker
int Yellow_LED = 6;
int Blue_LED = 7;
int Green_LED = 8;
int button = 4;
int button2 = 5;
int button3 = 9;
int button4 = 2;
int speaker = 3;
//assigning button values for each of the buttons
int buttonval;
int buttonval2;
int buttonval3;
int buttonval4;
//making the servo library
#include <Servo.h>
Servo myservo;
//pin for the servo
int servopin = 10;
void setup() {
//make all of the LEDs outputs of the buttons
pinMode(LED_BUILTIN, OUTPUT);
pinMode(Green_LED, OUTPUT);
pinMode(Yellow_LED, OUTPUT);
pinMode(Blue_LED, OUTPUT);
//making the buttons inputs
pinMode(button, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
myservo.attach(servopin);
pinMode(button4, INPUT_PULLUP);
pinMode(speaker, OUTPUT);
}
void loop() {
// Read the button states
buttonval = digitalRead(button);
buttonval2 = digitalRead(button2);
buttonval3 = digitalRead(button3);
// Control Yellow LED based on button 1
if (buttonval == LOW) { // Button pressed
digitalWrite(Yellow_LED, HIGH);
// Turn on Yellow LED
} else { // Button not pressed
digitalWrite(Yellow_LED, LOW); // Turn off Yellow LED
}
// Control Blue LED based on button 2
if (buttonval2 == LOW) { // Button pressed
digitalWrite(Blue_LED, HIGH);
// Turn on Blue LED
} else { // Button not pressed
digitalWrite(Blue_LED, LOW); // Turn off Blue LED
}
// Control Green LED based on button 3
if (buttonval3 == LOW) { // Button pressed
digitalWrite(Green_LED, HIGH);
// Turn on Green LED
} else { // Button not pressed
digitalWrite(Green_LED, LOW); // Turn off Green LED
}
buttonval4 = digitalRead(button4);
if (buttonval4==HIGH) {
myservo.write(20);
delay(300);
myservo.write(120);
}
if (buttonval4==LOW) {
tone(speaker, 261, 400); // C note (261 Hz) for 400ms
delay(400);
tone(speaker, 330, 400); // E note (330 Hz) for 400ms
delay(400);
tone(speaker, 392, 400); // G note (392 Hz) for 400ms
delay(400);
tone(speaker, 330, 400); // E note (330 Hz) for 400ms
delay(400);
tone(speaker, 261, 400); // C note (261 Hz) for 400ms
delay(400);
tone(speaker, 294, 400); // D note (294 Hz) for 400ms
delay(400);
tone(speaker, 261, 800); // C note (261 Hz) for 800ms (half note)
delay(800);
// "Buy me some peanuts and Cracker Jack" part
tone(speaker, 440, 400); // A note (440 Hz) for 400ms
delay(400);
tone(speaker, 440, 400); // A note (440 Hz) for 400ms
delay(400);
tone(speaker, 466, 400); // B note (466 Hz) for 400ms
delay(400);
tone(speaker, 261, 400); // C note (261 Hz) for 400ms
delay(400);
tone(speaker, 294, 400); // D note (294 Hz) for 400ms
delay(400);
tone(speaker, 261, 400); // C note (261 Hz) for 400ms
delay(400);
tone(speaker, 261, 800); // C note (261 Hz) for 800ms (half note)
delay(800);
}
}