PingPong-TESJI-IMCT
Project members
//Axel Osornio Martinez
//Giovanni Nepamuceno Zamorano
//Angel Daniel Valdez MartÃnez
//Marco Antonio MartÃnez Briones
//Kevin Yael Berny Trejo
Introduction
Background
In the field of mechatronics, hands-on learning is crucial to understanding how mechanical and electronic systems interact. Projects such as the electronic pingpong game allow students to apply programming, electronics, and system design theories in a tangible and entertaining context. These types of projects not only facilitate the understanding of technical concepts, but also stimulate creativity and innovation. The electronic pingpong game, which simulates a real pingpong match with LED lights and buttons, is a perfect example of how these elements can be integrated to create an educational and fun product.
Rationale
The development of this project responds to the need for educational tools that can make learning more interactive and dynamic. By building and programming the electronic pingpong game, mechatronics students have the opportunity to:
Apply programming knowledge: Write the code necessary to control the LEDs and buttons.
Handle electronic components: Correctly connect the LEDs, resistors, and buttons to the Arduino.
Develop practical skills: Assemble the circuit and the physical structure of the game.
Encourage teamwork: Collaborate with peers to solve problems and optimize the design.
This project not only provides a meaningful learning experience, but also prepares students for more complex challenges in their future careers.
Delimitation
The project is limited to the creation of an electronic pingpong game using an Arduino, 15 horizontally arranged LEDs, two buttons for game control, resistors for each LED, and jumper wires for connections. The box containing the game must be robust enough to withstand constant use and ensure a smooth gaming experience. The focus is on the programming and design of the electronic system, not on aesthetic or advanced manufacturing aspects of the box.
Project Content
Problem
The main challenge of the project is to design an interactive and precise system that allows two players to control an LED light that moves along a row of 15 LEDs. Problems include:
Synchronization and fast response: The system must detect and respond quickly to button presses.
Variable Speed: The LED light must increase its speed of movement with each change of direction, which requires precise timing control.
Design Robustness: The physical assembly and connections must be robust enough to withstand repeated use without failure.
Methodology
Circuit Design: Using an Arduino as the main controller. Each LED is connected with an appropriate resistor to limit the current. The buttons are connected to the Arduino's digital inputs, configured to detect interruptions.
Programming: Developing a program in the Arduino Development Environment (IDE) that:
Starts the movement of the LED light when the right button is pressed.
Changes the direction of the LED when the left button is pressed.
Increases the speed of the LED progressively with each change of direction.
Detects when a player loses (by not pressing the button in time).
Physical Assembly: Assembling all components on a base that keeps the LEDs aligned horizontally and the buttons at each end. Using jumper cables to connect all components to the Arduino.
Testing and Tuning: Conducting extensive testing to ensure the system responds appropriately to player inputs and that the LED speed increases in a controlled and predictable manner. Adjusting code and hardware as needed to optimize game performance.
Expected Results
The expected result is a functional electronic pingpong game where:
Smooth Interactivity: Players can interact without any noticeable delays in system response.
Difficulty Increment: The LED speed increases perceptibly with each change in direction, increasing the challenge of the game.
Reliability: The physical and electronic design is robust and reliable, supporting continuous use without failure.
Education and Entertainment: The project serves as an effective educational tool for mechatronics students, demonstrating the practical application of programming and electronics concepts while providing an entertaining gaming experience.
Conclusion
The electronic pingpong project with LEDs and buttons represents an excellent opportunity for mechatronics students to apply their knowledge in a practical and fun context. By combining programming, circuit design, and physical assembly, this project not only enriches technical learning, but also fosters important skills such as problem solving.
Supplies
Bill of Materials
1. Arduino Uno
Description: Microcontroller based on the ATmega328P. It is ideal for programming and electronics projects due to its ease of use and multiple digital and analog inputs/outputs.
Quantity: 1
Purpose: Control the sequence of LEDs and manage button inputs.
2. LEDs
Description: Light-emitting diodes, used to indicate the position of the pingpong "ball."
Quantity: 15
Purpose: Visualize the movement of the ball along the horizontal row.
3. Resistors
Description: Components that limit the electric current passing through the LEDs, typically 220 ohms or 330 ohms.
Quantity: 15
Purpose: Protect the LEDs from excessive currents.
4. Breadboard
Description: Board used to assemble electronic circuits without the need for soldering.
Quantity: 1
Purpose: To facilitate the assembly and temporary connections of circuit components.
5. Jumpers (Connection Cables)
Description: Cables used to make electrical connections between components and the Arduino on the breadboard.
Quantity: 70
Purpose: To connect LEDs, resistors, buttons and other components to the Arduino.
6. Laptop with the Arduino Program
Description: Laptop with the Arduino IDE software installed.
Quantity: 1
Purpose: To write and upload control code to the Arduino Uno.
7. Buttons
Description: Push buttons that allow players to interact with the system.
Quantity: 2
Purpose: To change the direction of the LED and control the game.
8. Data Cable for the Arduino
Description: USB cable that connects the Arduino Uno to the laptop.
Quantity: 1
Purpose: To power the Arduino and upload the program from the laptop.
9. Box
Description: Physical structure to mount all the components of the game.
Quantity: 1
Purpose: To house the LEDs, buttons and provide a stable base for the game.
Arduino to Breadboard Design
Step 1: Assembling the Circuit on the Breadboard
Prepare the Components
Gather all the necessary materials: Arduino Uno, breadboard, 15 LEDs, 15 resistors (220 ohm or 330 ohm), jumpers, and two buttons.
Placing the LEDs and Resistors on the Breadboard
Insert the 15 LEDs into the breadboard in a horizontal row.
Place a resistor in series with each LED. One end of the resistor should be connected to the anode (long leg) of the LED and the other end should be in a separate row on the breadboard.
Connecting the LEDs to the Arduino
Use jumper wires to connect the LEDs to the Arduino's digital inputs according to the following layout:
The first three LEDs connect to the Arduino's analog inputs A0, A1, and A2.
The next six LEDs connect to the Arduino's digital inputs 2, 3, 4, 5, 6, and 7.
The last six LEDs connect to digital inputs 8, 9, 10, 11, 12, and 13 on the Arduino.
Connecting Power to the Breadboard
Connect the Arduino's GND input to the ground (negative) line on the breadboard using a jumper wire.
Connect the Arduino's 5V input to the power (positive) line on the breadboard using another jumper wire.
Adding the Buttons
Insert two buttons into the breadboard. Make sure each button has one leg connected to a different row on the breadboard.
Connect a resistor to each button, making sure one end of the resistor is connected to one leg of the button and the other end to the ground (negative) line on the breadboard.
Connect the buttons to analog inputs A4 (left button) and A5 (right button) on the Arduino using jumper wires.
Programacion
Step 2: Programming the Arduino
To program the Arduino, the code provided will be used. This code controls the sequence of LEDs and the buttons. The following describes how to upload the code to the Arduino and briefly explains how it works.
Uploading the Code Below:
Copy and paste the following code into the Arduino IDE editor:
//Ping Pong Project
#define red1 A2
#define yellow A1
#define green3 A0
#define green4 2
#define green5 3
#define green6 4
#define green7 5
#define green8 6
#define green9 7
#define green10 8
#define green11 9
#define green12 10
#define green13 11
#define yellow14 12
#define red15 13
int LEFT_BUTTON;
int RIGHT_BUTTON;
int aux=7, vel=400;
int right_direction=1;
int left_direction=0;
void setup() {
pinMode(red1,OUTPUT);
pinMode(yellow2,OUTPUT);
pinMode(green3,OUTPUT);
pinMode(green4,OUTPUT);
pinMode(green5,OUTPUT);
pinMode(green6,OUTPUT);
pinMode(green7,OUTPUT);
pinMode(green8,OUTPUT);
pinMode(green9,OUTPUT);
pinMode(green10,OUTPUT);
pinMode(green11,OUTPUT);
pinMode(green12,OUTPUT);
pinMode(green13,OUTPUT);
pinMode(yellow14,OUTPUT);
pinMode(red15,OUTPUT);
pinMode(A5,INPUT);
pinMode(A4,INPUT);
}
void loop() {
LEFT_BUTTON=digitalRead(A5);
RIGHT_BUTTON=digitalRead(A4);
if (aux==2 && LEFT_BUTTON==1){
aux++;
right_address=1;
left_address=0;
BALL();
vel=vel-20;
}
else if (aux==14 && RIGHT_BUTTON==1){
aux--;
right_address=0;
left_address=1;
BALL();
}
else if (right_address==1){
aux++;
BALL();
}
else if (left_address==1){
aux--;
BALL();
}
delay(vel);
}
void BALL(){
switch (aux) {
case 1: //you lose the game
digitalWrite(red1,HIGH);
digitalWrite(yellow2,LOW);
break;
case 2: //yellow left
digitalWrite(red1,LOW);
digitalWrite(yellow2,HIGH);
digitalWrite(green3,LOW);
break;
case 3:
digitalWrite(yellow2,LOW);
digitalWrite(green3,HIGH);
digitalWrite(green4,LOW);
break;
case 4:
digitalWrite(green3,LOW);
digitalWrite(green4,HIGH);
digitalWrite(green5,LOW);
break;
case 5:
digitalWrite(green4,LOW);
digitalWrite(green5,HIGH);
digitalWrite(green6,LOW);
break;
case 6:
digitalWrite(green5,LOW);
digitalWrite(green6,HIGH);
digitalWrite(green7,LOW);
break;
case 7:
digitalWrite(green6,LOW);
digitalWrite(green7,HIGH);
digitalWrite(green8,LOW);
break;
case 8:
digitalWrite(green7,LOW);
digitalWrite(green8,HIGH);
digitalWrite(green9,LOW);
break;
case 9:
digitalWrite(green8,LOW);
digitalWrite(green9,HIGH);
digitalWrite(green10,LOW);
break;
case 10:
digitalWrite(green9,LOW);
digitalWrite(green10,HIGH);
digitalWrite(green11,LOW);
break;
case 11:
digitalWrite(green10,LOW);
digitalWrite(green11,HIGH);
digitalWrite(green12,LOW);
break;
case 12:
digitalWrite(green11,LOW);
digitalWrite(green12,HIGH);
digitalWrite(green13,LOW);
break;
case 13:
digitalWrite(green12,LOW);
digitalWrite(green13,HIGH);
digitalWrite(yellow14,LOW);
break;
case 14: //yellow right
digitalWrite(red13,LOW);
digitalWrite(yellow,HIGH);
digitalWrite(red15,LOW);
break;
case 15: //you lose the game
digitalWrite(red15,HIGH);
digitalWrite(yellow14,LOW);
break;
default:
digitalWrite(red15,HIGH);
digitalWrite(red1,HIGH);
break;
}
}
Save the file with a descriptive name, such as PingPong_Project.ino.
Upload the Code to the Arduino
Click the Verify button (the button with the check mark) to compile the code and make sure there are no errors.
If there are no errors, click the Upload button (the button with the right arrow) to upload the code to the Arduino.
Code Explanation
The code consists of three main sections: variable declaration and setup, the main loop, and the BALL function.
Variable Declaration and Setup
The pins to which the LEDs and buttons are connected are defined.
In the setup function, the pins are configured as outputs (for the LEDs) and inputs (for the buttons).
Main Loop
Reads the state of the left and right buttons.
If the left button is pressed and the light is in position 2, the light direction is changed to the right and the speed is increased.
If the right button is pressed and the light is in position 14, the light direction is changed to the left.
The light automatically moves to the right or left depending on the current direction.
A delay is added to control the speed of the game.
BALL Function
Controls which LEDs turn on and off depending on the current position (aux).
Changes the states of the LEDs depending on the position of the "ball."
If the "ball" reaches the extremes (position 1 or 15), the red LED lights up indicating that the player has lost.
Extending the LEDs and Buttons
Step 3: Extending the LEDs and Buttons
To extend the 15 LEDs and the two buttons, dual jumper wires will be used. This will allow the LEDs and buttons to be placed neatly and accessible for the game to play on.
Instructions for Extending the LEDs and Buttons
Extending the LEDs
Each LED is already connected to the breadboard with a jumper wire.
Take an additional jumper wire and connect it in parallel with each LED, i.e. one end of the jumper connects to the LED pin and the other end to the corresponding pin on the breadboard.
Do this for each of the 15 LEDs.
Make sure to maintain the correct order and polarity when connecting the dual jumpers.
Extending the Buttons
Each button is already connected to the breadboard with a jumper wire.
Take an additional jumper wire and connect it in parallel with each button, similar to how you did with the LEDs.
Connect one end of the jumper to one pin of the button and the other end to the corresponding pin on the breadboard.
Do this for both buttons.
Preparing and Decorating the Box
Step 4: Preparing and Decorating the Box
In this step, you will prepare the box to house the LEDs and buttons, as well as decorate it to your desired theme. Detailed steps for performing this task are outlined below.
Instructions for Preparing and Decorating the Box
Measuring and Marking LED Positions
Use a ruler to measure and mark 15 equidistant points on the top of the box, forming a horizontal line.
Make sure the marks are centered and aligned correctly.
Drilling Holes for the LEDs
Use a suitable tool (such as a drill or hand-held hole punch) to make 15 holes at the marked points.
Make sure the holes are the appropriate size for the LEDs to fit securely.
Placing the LEDs in the Holes
Insert each LED through the holes from the inside of the box to the outside.
Make sure the LEDs are tight and aligned.
Installing Buttons on the Outside of the Case
Choose two accessible locations on the sides of the case for the buttons, so that they are easy to press during gameplay.
Drill suitable holes for the buttons in the selected positions.
Insert and secure the buttons into these holes, making sure they are firmly attached.
Connecting the LEDs and Buttons to the Breadboard
Connect the jumper wires from the LEDs and buttons to the breadboard following the connections previously established.
Make sure all connections are secure and correct.
Decorating the Case
Decorate the case according to your desired theme, whether it is ping pong related or some other game.
Use paints, adhesives, stickers, or other decorative materials to personalize the case.
Make sure not to obstruct the LEDs or buttons with decoration.
Final Check
Final Check
Check All Connections
Check all electrical connections to ensure that the LEDs and buttons are properly connected and function as expected.
Test Game Operation
Connect the Arduino to the laptop and upload the code.
Test the game to ensure that the LEDs light up in the correct sequence and that the buttons respond appropriately.
Make Necessary Adjustments
If any LEDs or buttons do not function properly, check the connections and adjust as necessary.
Make sure the case is well decorated and that the buttons are accessible and comfortable to use.