├── MIT App Inventor Files ├── RC_Tank.aia ├── android.keystore ├── RC_Sherman_Tank.aia ├── RC_6Axis_Arm_Tank.aia └── RC_Nerf_Turret_Tank.aia ├── Fritzing Circuit Schematics ├── RC Arm Tank.fzz ├── RC Sherman Tank.fzz └── RC Nerf Turret Tank.fzz ├── LICENSE ├── RC_Bluetooth_Tank_6-Axis_Arm_Version__Servant_ └── RC_Bluetooth_Tank_6-Axis_Arm_Version__Servant_.ino ├── RC_Bluetooth_Tank_Nerf_Turret_Version_Servant └── RC_Bluetooth_Tank_Nerf_Turret_Version_Servant.ino ├── RC_Bluetooth_Tank_Base_Version └── RC_Bluetooth_Tank_Base_Version.ino ├── RC_Bluetooth_Tank_6-Axis_Arm_Version__Master_ └── RC_Bluetooth_Tank_6-Axis_Arm_Version__Master_.ino ├── RC_Bluetooth_Tank_Nerf_Turret_Version_Master └── RC_Bluetooth_Tank_Nerf_Turret_Version_Master.ino └── RC_Bluetooth_Tank_Sherman_Version └── RC_Bluetooth_Tank_Sherman_Version.ino /MIT App Inventor Files/RC_Tank.aia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elephant333/Modular-Arduino-Tank/HEAD/MIT App Inventor Files/RC_Tank.aia -------------------------------------------------------------------------------- /MIT App Inventor Files/android.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elephant333/Modular-Arduino-Tank/HEAD/MIT App Inventor Files/android.keystore -------------------------------------------------------------------------------- /MIT App Inventor Files/RC_Sherman_Tank.aia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elephant333/Modular-Arduino-Tank/HEAD/MIT App Inventor Files/RC_Sherman_Tank.aia -------------------------------------------------------------------------------- /Fritzing Circuit Schematics/RC Arm Tank.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elephant333/Modular-Arduino-Tank/HEAD/Fritzing Circuit Schematics/RC Arm Tank.fzz -------------------------------------------------------------------------------- /MIT App Inventor Files/RC_6Axis_Arm_Tank.aia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elephant333/Modular-Arduino-Tank/HEAD/MIT App Inventor Files/RC_6Axis_Arm_Tank.aia -------------------------------------------------------------------------------- /Fritzing Circuit Schematics/RC Sherman Tank.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elephant333/Modular-Arduino-Tank/HEAD/Fritzing Circuit Schematics/RC Sherman Tank.fzz -------------------------------------------------------------------------------- /MIT App Inventor Files/RC_Nerf_Turret_Tank.aia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elephant333/Modular-Arduino-Tank/HEAD/MIT App Inventor Files/RC_Nerf_Turret_Tank.aia -------------------------------------------------------------------------------- /Fritzing Circuit Schematics/RC Nerf Turret Tank.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elephant333/Modular-Arduino-Tank/HEAD/Fritzing Circuit Schematics/RC Nerf Turret Tank.fzz -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Elephant333 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /RC_Bluetooth_Tank_6-Axis_Arm_Version__Servant_/RC_Bluetooth_Tank_6-Axis_Arm_Version__Servant_.ino: -------------------------------------------------------------------------------- 1 | //Nathan Li - RC Bluetooth Tank 6-Axis Arm Version (Servant) - 28 January 2021 2 | 3 | #include 4 | #include 5 | 6 | int waist = 3; 7 | int shoulder = 5; 8 | int elbow = 6; 9 | int wristRoll = 9; 10 | int wristPitch = 10; 11 | int grip = 11; 12 | Servo waistServo; 13 | Servo shoulderServo; 14 | Servo elbowServo; 15 | Servo wristRollServo; 16 | Servo wristPitchServo; 17 | Servo gripServo; 18 | int servoPos; 19 | 20 | int servoSpeed = 51; 21 | 22 | int state = 0; 23 | 24 | void setup() 25 | { 26 | waistServo.attach(waist); 27 | shoulderServo.attach(shoulder); 28 | elbowServo.attach(elbow); 29 | wristRollServo.attach(wristRoll); 30 | wristPitchServo.attach(wristPitch); 31 | gripServo.attach(grip); 32 | 33 | waistServo.write(90); 34 | shoulderServo.write(90); 35 | elbowServo.write(90); 36 | wristRollServo.write(90); 37 | wristPitchServo.write(90); 38 | gripServo.write(90); 39 | 40 | Wire.begin(3); 41 | Wire.onReceive(receiveEvent); 42 | } 43 | 44 | void receiveEvent(int bytes) 45 | { 46 | state = Wire.read(); 47 | } 48 | 49 | void loop() 50 | { 51 | /***********************Servo Speed****************************/ 52 | if (state >= 200 && state <= 250) 53 | { 54 | servoSpeed = map(state, 200, 250, 51, 10); //will be used for delay, but 51 will constitute no movement 55 | } 56 | 57 | /***********************Waist****************************/ 58 | if (state == 9 || state == 10) 59 | { 60 | moveServo(waistServo, 180, 0); 61 | } 62 | 63 | /***********************Shoulder****************************/ 64 | if (state == 11 || state == 12) 65 | { 66 | moveServo(shoulderServo, 180, 0); 67 | } 68 | 69 | /***********************Elbow****************************/ 70 | if (state == 13 || state == 14) 71 | { 72 | moveServo(elbowServo, 180, 0); 73 | } 74 | 75 | /***********************Wrist Roll****************************/ 76 | if (state == 15 || state == 16) 77 | { 78 | moveServo(wristRollServo, 180, 0); 79 | } 80 | 81 | /***********************Wrist Pitch****************************/ 82 | if (state == 17 || state == 18) 83 | { 84 | moveServo(wristPitchServo, 180, 0); 85 | } 86 | 87 | /***********************Grip****************************/ 88 | if (state == 19 || state == 20) 89 | { 90 | moveServo(gripServo, 90, 0); 91 | } 92 | } 93 | 94 | void moveServo(Servo &theServo, int maxPos, int minPos) 95 | { 96 | servoPos = theServo.read(); 97 | if (servoSpeed == 51) 98 | { 99 | theServo.write(servoPos); 100 | } 101 | else 102 | { 103 | if (state % 2 == 1) 104 | { 105 | if (servoPos < maxPos) 106 | { 107 | servoPos = servoPos + 2; 108 | theServo.write(servoPos); 109 | delay(servoSpeed); 110 | } 111 | else 112 | { 113 | servoPos = maxPos; 114 | theServo.write(servoPos); 115 | } 116 | } 117 | if (state % 2 == 0) 118 | { 119 | if (servoPos > minPos) 120 | { 121 | servoPos = servoPos - 2; 122 | theServo.write(servoPos); 123 | delay(servoSpeed); 124 | } 125 | else 126 | { 127 | servoPos = minPos; 128 | theServo.write(servoPos); 129 | } 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /RC_Bluetooth_Tank_Nerf_Turret_Version_Servant/RC_Bluetooth_Tank_Nerf_Turret_Version_Servant.ino: -------------------------------------------------------------------------------- 1 | //Nathan Li - RC Bluetooth Tank Nerf Turret Version (Servant) - 21 April 2021 2 | 3 | #include 4 | #include 5 | 6 | int waist = 3; 7 | int shoulder = 5; 8 | int trigger = 6; 9 | int flywheels = 11; 10 | Servo waistServo; 11 | Servo shoulderServo; 12 | Servo triggerServo; 13 | int servoPos; 14 | 15 | int servoSpeed = 51; 16 | 17 | int state = 0; 18 | 19 | void setup() 20 | { 21 | waistServo.attach(waist); 22 | shoulderServo.attach(shoulder); 23 | triggerServo.attach(trigger); 24 | pinMode(flywheels, OUTPUT); 25 | 26 | waistServo.write(90); 27 | shoulderServo.write(90); 28 | triggerServo.write(115); 29 | digitalWrite(flywheels, LOW); 30 | 31 | Wire.begin(3); 32 | Wire.onReceive(receiveEvent); 33 | } 34 | 35 | void receiveEvent(int bytes) 36 | { 37 | state = Wire.read(); 38 | } 39 | 40 | void loop() 41 | { 42 | /***********************Servo Speed****************************/ 43 | if (state >= 200 && state <= 250) 44 | { 45 | servoSpeed = map(state, 200, 250, 51, 10); //will be used for delay, but 51 will constitute no movement 46 | } 47 | 48 | /***********************Waist****************************/ 49 | else if (state == 9 || state == 10) 50 | { 51 | moveServo(waistServo, state, 180, 0); 52 | } 53 | 54 | /***********************Shoulder****************************/ 55 | else if (state == 11 || state == 12) 56 | { 57 | moveServo(shoulderServo, state, 130, 0); 58 | } 59 | 60 | /***********************Trigger****************************/ 61 | else if (state == 19) 62 | { 63 | triggerServo.write(55); 64 | delay(250); 65 | triggerServo.write(115); 66 | delay(250); 67 | } 68 | 69 | /***********************Flywheel Motors****************************/ 70 | else if (state == 17) 71 | { 72 | digitalWrite(flywheels, LOW); 73 | } 74 | else if (state == 18) 75 | { 76 | digitalWrite(flywheels, HIGH); 77 | } 78 | 79 | /***********************Waist/Shoulder****************************/ 80 | else if (state == 13) 81 | { 82 | moveServo(waistServo, 9, 180, 0); 83 | moveServo(shoulderServo, 11, 130, 0); 84 | } 85 | else if (state == 14) 86 | { 87 | moveServo(waistServo, 10, 180, 0); 88 | moveServo(shoulderServo, 11, 130, 0); 89 | } 90 | else if (state == 15) 91 | { 92 | moveServo(waistServo, 9, 180, 0); 93 | moveServo(shoulderServo, 12, 130, 0); 94 | } 95 | else if (state == 16) 96 | { 97 | moveServo(waistServo, 10, 180, 0); 98 | moveServo(shoulderServo, 12, 130, 0); 99 | } 100 | } 101 | 102 | void moveServo(Servo &theServo, int newState, int maxPos, int minPos) //using newState so that can combine waist/shoulder movements 103 | { 104 | servoPos = theServo.read(); 105 | if (servoSpeed == 51) 106 | { 107 | theServo.write(servoPos); 108 | } 109 | else 110 | { 111 | if (newState % 2 == 1) //if state is odd, typically left or down 112 | { 113 | if (servoPos < maxPos) 114 | { 115 | servoPos = servoPos + 2; 116 | theServo.write(servoPos); 117 | delay(servoSpeed); 118 | } 119 | else 120 | { 121 | servoPos = maxPos; 122 | theServo.write(servoPos); 123 | } 124 | } 125 | if (newState % 2 == 0) //if state is even, typically right or up 126 | { 127 | if (servoPos > minPos) 128 | { 129 | servoPos = servoPos - 2; 130 | theServo.write(servoPos); 131 | delay(servoSpeed); 132 | } 133 | else 134 | { 135 | servoPos = minPos; 136 | theServo.write(servoPos); 137 | } 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /RC_Bluetooth_Tank_Base_Version/RC_Bluetooth_Tank_Base_Version.ino: -------------------------------------------------------------------------------- 1 | //Nathan Li - RC Bluetooth Tank Base Version - 28 December 2020 2 | 3 | int motorA1 = 6; //Left Forward 4 | int motorA2 = 11; 5 | int motorB1 = 3; //Right Forward 6 | int motorB2 = 5; 7 | int dataIn[3] = {255, 125, 125}; //initialize 255, x, and y to be in the center of joystick (meaning stop) 8 | int in_byte; 9 | int index; 10 | int mainSpeed; 11 | 12 | void setup() 13 | { 14 | pinMode(motorA1, OUTPUT); 15 | pinMode(motorA2, OUTPUT); 16 | pinMode(motorB1, OUTPUT); 17 | pinMode(motorB2, OUTPUT); 18 | Serial.begin(9600); 19 | } 20 | 21 | void loop() 22 | { 23 | //Save incoming data to variable 'in_byte' 24 | if(Serial.available() > 0) 25 | { 26 | in_byte = Serial.read(); 27 | if (in_byte == (255)) 28 | { 29 | index = 0; 30 | } 31 | dataIn[index] = in_byte; 32 | index = index + 1; 33 | } 34 | 35 | Serial.print (dataIn[0]); 36 | Serial.print (", X: "); 37 | Serial.print (dataIn[1]); 38 | Serial.print (", Y: "); 39 | Serial.println (dataIn[2]); 40 | /***********************Forward****************************/ 41 | if (dataIn[2] <= 100 && dataIn[1] >= 100 && dataIn[1] <= 150) //pushing joystick forward 42 | { 43 | mainSpeed = map(dataIn[2], 100, 0, 125, 255); 44 | analogWrite(motorA1, mainSpeed); analogWrite(motorA2, 0); 45 | analogWrite(motorB1, mainSpeed); analogWrite(motorB2, 0); 46 | } 47 | 48 | /***********************Backward****************************/ 49 | else if (dataIn[2] >= 150 && dataIn[1] >= 100 && dataIn[1] <= 150) 50 | { 51 | mainSpeed = map(dataIn[2], 150, 250, 125, 255); 52 | analogWrite(motorA1, 0); analogWrite(motorA2, mainSpeed); 53 | analogWrite(motorB1, 0); analogWrite(motorB2, mainSpeed); 54 | } 55 | 56 | /***************************Right*****************************/ 57 | else if (dataIn[2] > 100 && dataIn[2] < 150 && dataIn[1] >= 150 && dataIn[1] <= 250) 58 | { 59 | mainSpeed = map(dataIn[1], 150, 250, 125, 255); 60 | analogWrite(motorA1, mainSpeed); analogWrite(motorA2, 0); 61 | analogWrite(motorB1, 0); analogWrite(motorB2, mainSpeed); 62 | } 63 | 64 | /***************************Left*****************************/ 65 | else if (dataIn[2] > 100 && dataIn[2] < 150 && dataIn[1] >= 0 && dataIn[1] <= 100) 66 | { 67 | mainSpeed = map(dataIn[1], 100, 0, 125, 255); 68 | analogWrite(motorA1, 0); analogWrite(motorA2, mainSpeed); 69 | analogWrite(motorB1, mainSpeed); analogWrite(motorB2, 0); 70 | } 71 | 72 | /**********************Forward Right************************/ 73 | else if (dataIn[2] <= 100 && dataIn[1] >= 150 && dataIn[1] <= 250) 74 | { 75 | mainSpeed = map(dataIn[2], 100, 0, 125, 255); 76 | analogWrite(motorA1, mainSpeed); analogWrite(motorA2, 0); 77 | analogWrite(motorB1, map(dataIn[1], 150, 250, mainSpeed, 0)); analogWrite(motorB2, 0); 78 | } 79 | 80 | /**********************Forward Left************************/ 81 | else if (dataIn[2] <= 100 && dataIn[1] >= 0 && dataIn[1] <= 100) 82 | { 83 | mainSpeed = map(dataIn[2], 100, 0, 125, 255); 84 | analogWrite(motorA1, map(dataIn[1], 100, 0, mainSpeed, 0)); analogWrite(motorA2, 0); 85 | analogWrite(motorB1, mainSpeed); analogWrite(motorB2, 0); 86 | } 87 | 88 | /**********************Backward Right************************/ 89 | else if (dataIn[2] >= 150 && dataIn[1] >= 150 && dataIn[1] <= 250) 90 | { 91 | mainSpeed = map(dataIn[2], 150, 250, 125, 255); 92 | analogWrite(motorA1, 0); analogWrite(motorA2, mainSpeed); 93 | analogWrite(motorB1, 0); analogWrite(motorB2, map(dataIn[1], 150, 250, mainSpeed, 0)); 94 | } 95 | 96 | /**********************Backward Left************************/ 97 | else if (dataIn[2] >= 150 && dataIn[1] >= 0 && dataIn[1] <= 100) 98 | { 99 | mainSpeed = map(dataIn[2], 150, 250, 125, 255); 100 | analogWrite(motorA1, 0); analogWrite(motorA2, map(dataIn[1], 100, 0, mainSpeed, 0)); 101 | analogWrite(motorB1, 0); analogWrite(motorB2, mainSpeed); 102 | } 103 | 104 | /***************************Stop*****************************/ 105 | else if (dataIn[2] > 100 && dataIn[2] < 150 && dataIn[1] > 100 && dataIn[1] < 150) 106 | { 107 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 108 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /RC_Bluetooth_Tank_6-Axis_Arm_Version__Master_/RC_Bluetooth_Tank_6-Axis_Arm_Version__Master_.ino: -------------------------------------------------------------------------------- 1 | //Nathan Li - RC Bluetooth Tank 6-Axis Arm Version (Master) - 28 January 2021 2 | 3 | #include 4 | #include 5 | 6 | SoftwareSerial BT(4, 2); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX) 7 | //Another thing I learned: use SoftwareSerial for bluetooth instead of just Serial because Serial is more for the serial monitor, while SoftwareSerial is better used for bluetooth electronics communications. 8 | //I believe this is what solved the delay issues I was having previously between the app, bluetooth module, and Arduino controller. 9 | 10 | int motorA1 = 6; //Left Forward 11 | int motorA2 = 11; 12 | int motorB1 = 3; //Right Forward 13 | int motorB2 = 5; 14 | int state = 0; 15 | int index; 16 | int motorSpeed = 0; 17 | 18 | void setup() 19 | { 20 | pinMode(motorA1, OUTPUT); 21 | pinMode(motorA2, OUTPUT); 22 | pinMode(motorB1, OUTPUT); 23 | pinMode(motorB2, OUTPUT); 24 | 25 | Serial.begin(9600); 26 | BT.begin(9600); 27 | 28 | Wire.begin(); 29 | } 30 | 31 | void loop() 32 | { 33 | //Save incoming data to variable 'state' 34 | if(BT.available() > 0) 35 | { 36 | state = BT.read(); 37 | } 38 | 39 | Serial.print("state: " ); 40 | Serial.println(state); 41 | 42 | /***********************Motor Speed****************************/ 43 | if (state >= 50 && state <= 199) 44 | { 45 | motorSpeed = map(state, 50, 199, 0, 255); 46 | } 47 | 48 | /***********************Servo Speed****************************/ 49 | if (state >= 200 && state <= 250) 50 | { 51 | Wire.beginTransmission(3); //transmit to device #3, where 3 is an arbitrary number that we use as an ID 52 | Wire.write(state); 53 | Wire.endTransmission(); 54 | } 55 | 56 | /***********************Forward****************************/ 57 | if (state == 1) 58 | { 59 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 60 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 61 | } 62 | 63 | /***********************Backward****************************/ 64 | else if (state == 5) 65 | { 66 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 67 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 68 | } 69 | 70 | /***************************Right*****************************/ 71 | else if (state == 3) 72 | { 73 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 74 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 75 | } 76 | 77 | /***************************Left*****************************/ 78 | else if (state == 7) 79 | { 80 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 81 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 82 | } 83 | 84 | /**********************Forward Right************************/ 85 | else if (state == 2) 86 | { 87 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 88 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 89 | } 90 | 91 | /**********************Forward Left************************/ 92 | else if (state == 8) 93 | { 94 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 95 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 96 | } 97 | 98 | /**********************Backward Right************************/ 99 | else if (state == 4) 100 | { 101 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 102 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 103 | } 104 | 105 | /**********************Backward Left************************/ 106 | else if (state == 6) 107 | { 108 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 109 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 110 | } 111 | 112 | /***************************Stop*****************************/ 113 | else if (state == 0) 114 | { 115 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 116 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 117 | Wire.beginTransmission(3); //transmit to device #3, where 3 is an arbitrary number that we use as an ID 118 | Wire.write(state); 119 | Wire.endTransmission(); 120 | } 121 | 122 | /***************************Arm Servos*****************************/ 123 | else if (state >= 9 && state <= 20) 124 | { 125 | Wire.beginTransmission(3); //transmit to device #3, where 3 is an arbitrary number that we use as an ID 126 | Wire.write(state); 127 | Wire.endTransmission(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /RC_Bluetooth_Tank_Nerf_Turret_Version_Master/RC_Bluetooth_Tank_Nerf_Turret_Version_Master.ino: -------------------------------------------------------------------------------- 1 | //Nathan Li - RC Bluetooth Tank Nerf Turret Version (Master) - 21 April 2021 2 | 3 | #include 4 | #include 5 | 6 | SoftwareSerial BT(4, 2); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX) 7 | //Another thing I learned: use SoftwareSerial for bluetooth instead of just Serial because Serial is more for the serial monitor, while SoftwareSerial is better used for bluetooth electronics communications. 8 | //I believe this is what solved the delay issues I was having previously between the app, bluetooth module, and Arduino controller. 9 | 10 | int motorA1 = 6; //Left Forward 11 | int motorA2 = 11; 12 | int motorB1 = 3; //Right Forward 13 | int motorB2 = 5; 14 | int state = 0; 15 | int index; 16 | int motorSpeed = 0; 17 | 18 | void setup() 19 | { 20 | pinMode(motorA1, OUTPUT); 21 | pinMode(motorA2, OUTPUT); 22 | pinMode(motorB1, OUTPUT); 23 | pinMode(motorB2, OUTPUT); 24 | 25 | Serial.begin(9600); 26 | BT.begin(9600); 27 | 28 | Wire.begin(); 29 | } 30 | 31 | void loop() 32 | { 33 | //Save incoming data to variable 'state' 34 | if(BT.available() > 0) 35 | { 36 | state = BT.read(); 37 | } 38 | 39 | Serial.print("state: " ); 40 | Serial.println(state); 41 | 42 | /***********************Motor Speed****************************/ 43 | if (state >= 50 && state <= 199) 44 | { 45 | motorSpeed = map(state, 50, 199, 0, 255); 46 | } 47 | 48 | /***********************Servo Speed****************************/ 49 | if (state >= 200 && state <= 250) 50 | { 51 | Wire.beginTransmission(3); //transmit to device #3, where 3 is an arbitrary number that we use as an ID 52 | Wire.write(state); 53 | Wire.endTransmission(); 54 | } 55 | 56 | /***********************Forward****************************/ 57 | if (state == 1) 58 | { 59 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 60 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 61 | } 62 | 63 | /***********************Backward****************************/ 64 | else if (state == 5) 65 | { 66 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 67 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 68 | } 69 | 70 | /***************************Right*****************************/ 71 | else if (state == 3) 72 | { 73 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 74 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 75 | } 76 | 77 | /***************************Left*****************************/ 78 | else if (state == 7) 79 | { 80 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 81 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 82 | } 83 | 84 | /**********************Forward Right************************/ 85 | else if (state == 2) 86 | { 87 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 88 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 89 | } 90 | 91 | /**********************Forward Left************************/ 92 | else if (state == 8) 93 | { 94 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 95 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 96 | } 97 | 98 | /**********************Backward Right************************/ 99 | else if (state == 4) 100 | { 101 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 102 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 103 | } 104 | 105 | /**********************Backward Left************************/ 106 | else if (state == 6) 107 | { 108 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 109 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 110 | } 111 | 112 | /***************************Stop*****************************/ 113 | else if (state == 0) 114 | { 115 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 116 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 117 | Wire.beginTransmission(3); //transmit to device #3, where 3 is an arbitrary number that we use as an ID 118 | Wire.write(state); 119 | Wire.endTransmission(); 120 | } 121 | 122 | /***************************Nerf Turret Servos/Motors*****************************/ 123 | else if (state >= 9 && state <= 19) 124 | { 125 | Wire.beginTransmission(3); //transmit to device #3, where 3 is an arbitrary number that we use as an ID 126 | Wire.write(state); 127 | Wire.endTransmission(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /RC_Bluetooth_Tank_Sherman_Version/RC_Bluetooth_Tank_Sherman_Version.ino: -------------------------------------------------------------------------------- 1 | //Nathan Li - RC Bluetooth Tank Sherman Version - 13 January 2021 2 | 3 | #include //Something I learned during this project: calling the servo library disables PWM for pins 9 and 10, and that is why the right motor was having trouble. 4 | #include 5 | 6 | SoftwareSerial BT(4, 2); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX) 7 | //Another thing I learned: use SoftwareSerial for bluetooth instead of just Serial because Serial is more for the serial monitor, while SoftwareSerial is better used for bluetooth electronics communications. 8 | //I believe this is what solved the delay issues I was having previously between the app, bluetooth module, and Arduino controller. 9 | 10 | int motorA1 = 6; //Left Forward 11 | int motorA2 = 11; 12 | int motorB1 = 3; //Right Forward 13 | int motorB2 = 5; 14 | int LED1 = 7; //front lights 15 | int LED2 = 8; 16 | int LED3 = 12; //rear lights 17 | int LED4 = 13; 18 | int state = 0; 19 | int index; 20 | int motorSpeed = 0; 21 | int turretSpeed = 51; //the delay between turret changes 22 | int turretPos = 90; 23 | 24 | Servo myservo; 25 | 26 | void setup() 27 | { 28 | pinMode(motorA1, OUTPUT); 29 | pinMode(motorA2, OUTPUT); 30 | pinMode(motorB1, OUTPUT); 31 | pinMode(motorB2, OUTPUT); 32 | pinMode(LED1, OUTPUT); 33 | pinMode(LED2, OUTPUT); 34 | pinMode(LED3, OUTPUT); 35 | pinMode(LED4, OUTPUT); 36 | myservo.attach(9); 37 | myservo.write(turretPos); 38 | 39 | digitalWrite(LED1, HIGH); 40 | digitalWrite(LED2, HIGH); 41 | digitalWrite(LED3, HIGH); 42 | digitalWrite(LED4, HIGH); 43 | 44 | Serial.begin(9600); 45 | BT.begin(9600); 46 | } 47 | 48 | void loop() 49 | { 50 | //Save incoming data to variable 'state' 51 | if(BT.available() > 0) 52 | { 53 | state = BT.read(); 54 | } 55 | 56 | Serial.print("state: " ); 57 | Serial.println(state); 58 | 59 | /***********************Motor Speed****************************/ 60 | if (state >= 50 && state <= 199) 61 | { 62 | motorSpeed = map(state, 50, 199, 0, 255); 63 | } 64 | 65 | /***********************Turret Speed****************************/ 66 | if (state >= 200 && state <= 250) 67 | { 68 | turretSpeed = map(state, 200, 250, 51, 10); //will be used for delay, but 51 will constitute no movement 69 | } 70 | 71 | /***********************Forward****************************/ 72 | if (state == 1) 73 | { 74 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 75 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 76 | } 77 | 78 | /***********************Backward****************************/ 79 | else if (state == 5) 80 | { 81 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 82 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 83 | } 84 | 85 | /***************************Right*****************************/ 86 | else if (state == 3) 87 | { 88 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 89 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 90 | } 91 | 92 | /***************************Left*****************************/ 93 | else if (state == 7) 94 | { 95 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 96 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 97 | } 98 | 99 | /**********************Forward Right************************/ 100 | else if (state == 2) 101 | { 102 | analogWrite(motorA1, motorSpeed); analogWrite(motorA2, 0); 103 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 104 | } 105 | 106 | /**********************Forward Left************************/ 107 | else if (state == 8) 108 | { 109 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 110 | analogWrite(motorB1, motorSpeed); analogWrite(motorB2, 0); 111 | } 112 | 113 | /**********************Backward Right************************/ 114 | else if (state == 4) 115 | { 116 | analogWrite(motorA1, 0); analogWrite(motorA2, motorSpeed); 117 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 118 | } 119 | 120 | /**********************Backward Left************************/ 121 | else if (state == 6) 122 | { 123 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 124 | analogWrite(motorB1, 0); analogWrite(motorB2, motorSpeed); 125 | } 126 | 127 | /***************************Stop*****************************/ 128 | else if (state == 0) 129 | { 130 | analogWrite(motorA1, 0); analogWrite(motorA2, 0); 131 | analogWrite(motorB1, 0); analogWrite(motorB2, 0); 132 | } 133 | 134 | /***********************Turret Left****************************/ 135 | else if (state == 9) //to do: make the turret turn a bit faster by increasing turretPos change and adding a limitation to change in order to prevent <0 or >180 outputs 136 | { 137 | if (turretSpeed == 51) 138 | { 139 | myservo.write(turretPos); 140 | } 141 | else 142 | { 143 | if (turretPos < 180) 144 | { 145 | turretPos = turretPos + 2; 146 | myservo.write(turretPos); 147 | delay(turretSpeed); 148 | } 149 | else 150 | { 151 | turretPos = 180; 152 | myservo.write(turretPos); 153 | } 154 | } 155 | } 156 | 157 | /***********************Turret Right****************************/ 158 | else if (state == 10) 159 | { 160 | if (turretSpeed == 51) 161 | { 162 | myservo.write(turretPos); 163 | } 164 | else 165 | { 166 | if (turretPos > 0) 167 | { 168 | turretPos = turretPos - 2; 169 | myservo.write(turretPos); 170 | delay(turretSpeed); 171 | } 172 | else 173 | { 174 | turretPos = 0; 175 | myservo.write(turretPos); 176 | } 177 | } 178 | } 179 | } 180 | --------------------------------------------------------------------------------