Devices & Components
Arduino Uno Rev3
SG90 Micro-servo motor
7.4V 1300 mAh LiPo Battery
Resistor 10k ohm
13,000 rpm 6V DC motor
1N4007 – High Voltage, High Current Rated Diode
Power MOSFET N-Channel
Hardware & Tools
3D Printer (generic)
Hot glue gun (generic)
Software & Tools
Arduino IDE
Project description
Code
Ping Pong Ball Cannon
processing
Arduino Code to control Ping Pong Ball Cannon
1/* 2 * Ping Pong Ball Cannon 3 * 2019 - Gord Payne 4 * 5 */ 6 #include <Servo.h> 7 8Servo servo; 9 10int motorPin = 6; // flywheel motors 11int servoPin = 8; // autofeeder servo 12int potPin = A0; // potentiometer for speed adjustment 13int potVal; 14int speedVal; // scaled speed value for motor (potVal/4); 15char theVal; 16 17void setup() { 18 Serial.begin(9600); 19 pinMode(motorPin, OUTPUT); 20 pinMode(potPin, INPUT); 21 22} 23 24void loop() { 25 potVal = analogRead(potPin); 26 speedVal = map(potVal / 4, 0, 255, 80, 220); // you can adjust as appropriate for your setup 27 Serial.print(speedVal); 28 if (Serial.available() > 0) { 29 theVal = Serial.read(); 30 31 32 } 33 switch (theVal) { 34 case '1': // If '1' was received 35 analogWrite(motorPin, speedVal); // turn the motor ON 36 delay(2000); 37 feedBall(); // feed a ball into the flywheels 38 digitalWrite(motorPin,LOW); 39 break; 40 case '0': // If '0' was received 41 digitalWrite(motorPin, LOW); // turn the motor OFF 42 break; 43 default: 44 break; 45 46 } 47 48} 49 50void feedBall(){ 51 servo.attach(servoPin); 52 delay(20); 53 servo.write(10); 54 delay(400); 55 for (int i = 0; i <= 110; i++) { // push the ball into the flywheels 56 servo.write(i); 57 delay(5); 58 } 59 delay(100); 60 for (int i = 110; i >= 0; i--) { // retract the feeder for the next ball 61 servo.write(i); 62 delay(5); 63 } 64 servo.detach(); 65} 66
Downloadable files
Cannon Circuit
Cannon Circuit

Cannon Circuit
Cannon Circuit

Documentation
Flywheels
Flywheels attached to the motors to fling the balls
Flywheels
Flywheels
Flywheels attached to the motors to fling the balls
Flywheels
Comments
Only logged in users can leave comments