Components and supplies
Arduino UNO
4WD Smart Robot Car Chassis Kits
Resistor 221 ohm
LEDs
Buzzer
Dual H-Bridge motor drivers L298
HC-06 Bluetooth Module
Tools and machines
Soldering iron (generic)
Hot glue gun (generic)
Apps and platforms
Arduino IDE
android apps
Project description
Code
BTcar_v01.2.ino
c_cpp
1#define light_FR 14 //LED Front Right pin A0 for Arduino Uno 2#define light_FL 15 //LED Front Left pin A1 for Arduino Uno 3#define light_BR 16 //LED Back Right pin A2 for Arduino Uno 4#define light_BL 17 //LED Back Left pin A3 for Arduino Uno 5#define horn_Buzz 18 //Horn Buzzer pin A4 for Arduino Uno 6 7#define ENA_m1 5 // Enable/speed motor Front Right 8#define ENB_m1 6 // Enable/speed motor Back Right 9#define ENA_m2 10 // Enable/speed motor Front Left 10#define ENB_m2 11 // Enable/speed motor Back Left 11 12#define IN_11 2 // L298N #1 in 1 motor Front Right 13#define IN_12 3 // L298N #1 in 2 motor Front Right 14#define IN_13 4 // L298N #1 in 3 motor Back Right 15#define IN_14 7 // L298N #1 in 4 motor Back Right 16 17#define IN_21 8 // L298N #2 in 1 motor Front Left 18#define IN_22 9 // L298N #2 in 2 motor Front Left 19#define IN_23 12 // L298N #2 in 3 motor Back Left 20#define IN_24 13 // L298N #2 in 4 motor Back Left 21 22int command; //Int to store app command state. 23int speedCar = 100; // 50 - 255. 24int speed_Coeff = 4; 25boolean lightFront = false; 26boolean lightBack = false; 27boolean horn = false; 28 29void setup() { 30 31 pinMode(light_FR, OUTPUT); 32 pinMode(light_FL, OUTPUT); 33 pinMode(light_BR, OUTPUT); 34 pinMode(light_BL, OUTPUT); 35 pinMode(horn_Buzz, OUTPUT); 36 37 pinMode(ENA_m1, OUTPUT); 38 pinMode(ENB_m1, OUTPUT); 39 pinMode(ENA_m2, OUTPUT); 40 pinMode(ENB_m2, OUTPUT); 41 42 pinMode(IN_11, OUTPUT); 43 pinMode(IN_12, OUTPUT); 44 pinMode(IN_13, OUTPUT); 45 pinMode(IN_14, OUTPUT); 46 47 pinMode(IN_21, OUTPUT); 48 pinMode(IN_22, OUTPUT); 49 pinMode(IN_23, OUTPUT); 50 pinMode(IN_24, OUTPUT); 51 52 Serial.begin(9600); 53 54 } 55 56void goAhead(){ 57digitalWrite(IN_11, LOW); 58 digitalWrite(IN_12, HIGH); 59 analogWrite(ENA_m1, speedCar); 60 61 62 digitalWrite(IN_13, HIGH); 63 digitalWrite(IN_14, LOW); 64 analogWrite(ENB_m1, speedCar); 65 66 67 digitalWrite(IN_21, HIGH); 68 digitalWrite(IN_22, LOW); 69 analogWrite(ENA_m2, speedCar); 70 71 72 digitalWrite(IN_23, LOW); 73 digitalWrite(IN_24, HIGH); 74 analogWrite(ENB_m2, speedCar); 75 76 } 77 78void goBack(){ 79 80digitalWrite(light_BR, HIGH); digitalWrite(light_BL, HIGH); 81digitalWrite(IN_11, HIGH); 82 digitalWrite(IN_12, LOW); 83 analogWrite(ENA_m1, speedCar); 84 85 digitalWrite(IN_13, LOW); 86 digitalWrite(IN_14, HIGH); 87 analogWrite(ENB_m1, speedCar); 88 89 90 digitalWrite(IN_21, LOW); 91 digitalWrite(IN_22, HIGH); 92 analogWrite(ENA_m2, speedCar); 93 94 95 digitalWrite(IN_23, HIGH); 96 digitalWrite(IN_24, LOW); 97 analogWrite(ENB_m2, speedCar); 98 99 100 101 102 103 104 } 105 106void goRight(){ 107 108 digitalWrite(IN_11, LOW); 109 digitalWrite(IN_12, HIGH); 110 analogWrite(ENA_m1, speedCar); 111 112 113 digitalWrite(IN_13, HIGH); 114 digitalWrite(IN_14, LOW); 115 analogWrite(ENB_m1, speedCar); 116 117 118 digitalWrite(IN_21, LOW); 119 digitalWrite(IN_22, HIGH); 120 analogWrite(ENA_m2, speedCar); 121 122 123 digitalWrite(IN_23, HIGH); 124 digitalWrite(IN_24, LOW); 125 analogWrite(ENB_m2, speedCar); 126 127 128 } 129 130void goLeft(){ 131 132 digitalWrite(IN_11, HIGH); 133 digitalWrite(IN_12, LOW); 134 analogWrite(ENA_m1, speedCar); 135 136 137 digitalWrite(IN_13, LOW); 138 digitalWrite(IN_14, HIGH); 139 analogWrite(ENB_m1, speedCar); 140 141 142 digitalWrite(IN_21, HIGH); 143 digitalWrite(IN_22, LOW); 144 analogWrite(ENA_m2, speedCar); 145 146 147 digitalWrite(IN_23, LOW); 148 digitalWrite(IN_24, HIGH); 149 analogWrite(ENB_m2, speedCar); 150 151 152 } 153 154void goAheadRight(){ 155 156 digitalWrite(IN_11, HIGH); 157 digitalWrite(IN_12, LOW); 158 analogWrite(ENA_m1, speedCar/speed_Coeff); 159 160 digitalWrite(IN_13, LOW); 161 digitalWrite(IN_14, HIGH); 162 analogWrite(ENB_m1, speedCar/speed_Coeff); 163 164 165 digitalWrite(IN_21, LOW); 166 digitalWrite(IN_22, HIGH); 167 analogWrite(ENA_m2, speedCar); 168 169 170 digitalWrite(IN_23, HIGH); 171 digitalWrite(IN_24, LOW); 172 analogWrite(ENB_m2, speedCar); 173 174 } 175 176void goAheadLeft(){ 177 178 digitalWrite(IN_11, HIGH); 179 digitalWrite(IN_12, LOW); 180 analogWrite(ENA_m1, speedCar); 181 182 digitalWrite(IN_13, LOW); 183 digitalWrite(IN_14, HIGH); 184 analogWrite(ENB_m1, speedCar); 185 186 187 digitalWrite(IN_21, LOW); 188 digitalWrite(IN_22, HIGH); 189 analogWrite(ENA_m2, speedCar/speed_Coeff); 190 191 192 digitalWrite(IN_23, HIGH); 193 digitalWrite(IN_24, LOW); 194 analogWrite(ENB_m2, speedCar/speed_Coeff); 195 196 } 197 198void goBackRight(){ 199 200 digitalWrite(IN_11, LOW); 201 digitalWrite(IN_12, HIGH); 202 analogWrite(ENA_m1, speedCar/speed_Coeff); 203 204 205 digitalWrite(IN_13, HIGH); 206 digitalWrite(IN_14, LOW); 207 analogWrite(ENB_m1, speedCar/speed_Coeff); 208 209 210 digitalWrite(IN_21, HIGH); 211 digitalWrite(IN_22, LOW); 212 analogWrite(ENA_m2, speedCar); 213 214 215 digitalWrite(IN_23, LOW); 216 digitalWrite(IN_24, HIGH); 217 analogWrite(ENB_m2, speedCar); 218 219 } 220 221void goBackLeft(){ 222 223 digitalWrite(IN_11, LOW); 224 digitalWrite(IN_12, HIGH); 225 analogWrite(ENA_m1, speedCar); 226 227 228 digitalWrite(IN_13, HIGH); 229 digitalWrite(IN_14, LOW); 230 analogWrite(ENB_m1, speedCar); 231 232 233 digitalWrite(IN_21, HIGH); 234 digitalWrite(IN_22, LOW); 235 analogWrite(ENA_m2, speedCar/speed_Coeff); 236 237 238 digitalWrite(IN_23, LOW); 239 digitalWrite(IN_24, HIGH); 240 analogWrite(ENB_m2, speedCar/speed_Coeff); 241 242 } 243 244void stopRobot(){ 245 246 digitalWrite(IN_11, LOW); 247 digitalWrite(IN_12, LOW); 248 analogWrite(ENA_m1, speedCar); 249 250 251 digitalWrite(IN_13, LOW); 252 digitalWrite(IN_14, LOW); 253 analogWrite(ENB_m1, speedCar); 254 255 256 digitalWrite(IN_21, LOW); 257 digitalWrite(IN_22, LOW); 258 analogWrite(ENA_m2, speedCar); 259 260 261 digitalWrite(IN_23, LOW); 262 digitalWrite(IN_24, LOW); 263 analogWrite(ENB_m2, speedCar); 264 265 } 266 267void loop(){ 268 269if (Serial.available() > 0) { 270 command = Serial.read(); 271 stopRobot(); //Initialize with motors stopped. 272 273if (lightFront) {digitalWrite(light_FR, HIGH); digitalWrite(light_FL, HIGH);} 274if (!lightFront) {digitalWrite(light_FR, LOW); digitalWrite(light_FL, LOW);} 275if (lightBack) {digitalWrite(light_BR, HIGH); digitalWrite(light_BL, HIGH);} 276if (!lightBack) {digitalWrite(light_BR, LOW); digitalWrite(light_BL, LOW);} 277if (horn) {digitalWrite(horn_Buzz, HIGH);} 278if (!horn) {digitalWrite(horn_Buzz, LOW);} 279 280switch (command) { 281case 'F':goAhead();break; 282case 'B':goBack();break; 283case 'L':goLeft();break; 284case 'R':goRight();break; 285case 'I':goAheadRight();break; 286case 'G':goAheadLeft();break; 287case 'J':goBackRight();break; 288case 'H':goBackLeft();break; 289case '0':speedCar = 100;break; 290case '1':speedCar = 115;break; 291case '2':speedCar = 130;break; 292case '3':speedCar = 145;break; 293case '4':speedCar = 160;break; 294case '5':speedCar = 175;break; 295case '6':speedCar = 190;break; 296case '7':speedCar = 205;break; 297case '8':speedCar = 220;break; 298case '9':speedCar = 235;break; 299case 'q':speedCar = 255;break; 300case 'W':lightFront = true;break; 301case 'w':lightFront = false;break; 302case 'U':lightBack = true;break; 303case 'u':lightBack = false;break; 304case 'V':horn = true;break; 305case 'v':horn = false;break; 306 307} 308} 309} 310
BTcar_v01.2.ino
c_cpp
1#define light_FR 14 //LED Front Right pin A0 for Arduino Uno 2#define light_FL 15 //LED Front Left pin A1 for Arduino Uno 3#define light_BR 16 //LED Back Right pin A2 for Arduino Uno 4#define light_BL 17 //LED Back Left pin A3 for Arduino Uno 5#define horn_Buzz 18 //Horn Buzzer pin A4 for Arduino Uno 6 7#define ENA_m1 5 // Enable/speed motor Front Right 8#define ENB_m1 6 // Enable/speed motor Back Right 9#define ENA_m2 10 // Enable/speed motor Front Left 10#define ENB_m2 11 // Enable/speed motor Back Left 11 12#define IN_11 2 // L298N #1 in 1 motor Front Right 13#define IN_12 3 // L298N #1 in 2 motor Front Right 14#define IN_13 4 // L298N #1 in 3 motor Back Right 15#define IN_14 7 // L298N #1 in 4 motor Back Right 16 17#define IN_21 8 // L298N #2 in 1 motor Front Left 18#define IN_22 9 // L298N #2 in 2 motor Front Left 19#define IN_23 12 // L298N #2 in 3 motor Back Left 20#define IN_24 13 // L298N #2 in 4 motor Back Left 21 22int command; //Int to store app command state. 23int speedCar = 100; // 50 - 255. 24int speed_Coeff = 4; 25boolean lightFront = false; 26boolean lightBack = false; 27boolean horn = false; 28 29void setup() { 30 31 pinMode(light_FR, OUTPUT); 32 pinMode(light_FL, OUTPUT); 33 pinMode(light_BR, OUTPUT); 34 pinMode(light_BL, OUTPUT); 35 pinMode(horn_Buzz, OUTPUT); 36 37 pinMode(ENA_m1, OUTPUT); 38 pinMode(ENB_m1, OUTPUT); 39 pinMode(ENA_m2, OUTPUT); 40 pinMode(ENB_m2, OUTPUT); 41 42 pinMode(IN_11, OUTPUT); 43 pinMode(IN_12, OUTPUT); 44 pinMode(IN_13, OUTPUT); 45 pinMode(IN_14, OUTPUT); 46 47 pinMode(IN_21, OUTPUT); 48 pinMode(IN_22, OUTPUT); 49 pinMode(IN_23, OUTPUT); 50 pinMode(IN_24, OUTPUT); 51 52 Serial.begin(9600); 53 54 } 55 56void goAhead(){ 57digitalWrite(IN_11, LOW); 58 digitalWrite(IN_12, HIGH); 59 analogWrite(ENA_m1, speedCar); 60 61 62 digitalWrite(IN_13, HIGH); 63 digitalWrite(IN_14, LOW); 64 analogWrite(ENB_m1, speedCar); 65 66 67 digitalWrite(IN_21, HIGH); 68 digitalWrite(IN_22, LOW); 69 analogWrite(ENA_m2, speedCar); 70 71 72 digitalWrite(IN_23, LOW); 73 digitalWrite(IN_24, HIGH); 74 analogWrite(ENB_m2, speedCar); 75 76 } 77 78void goBack(){ 79 80digitalWrite(light_BR, HIGH); digitalWrite(light_BL, HIGH); 81digitalWrite(IN_11, HIGH); 82 digitalWrite(IN_12, LOW); 83 analogWrite(ENA_m1, speedCar); 84 85 digitalWrite(IN_13, LOW); 86 digitalWrite(IN_14, HIGH); 87 analogWrite(ENB_m1, speedCar); 88 89 90 digitalWrite(IN_21, LOW); 91 digitalWrite(IN_22, HIGH); 92 analogWrite(ENA_m2, speedCar); 93 94 95 digitalWrite(IN_23, HIGH); 96 digitalWrite(IN_24, LOW); 97 analogWrite(ENB_m2, speedCar); 98 99 100 101 102 103 104 } 105 106void goRight(){ 107 108 digitalWrite(IN_11, LOW); 109 digitalWrite(IN_12, HIGH); 110 analogWrite(ENA_m1, speedCar); 111 112 113 digitalWrite(IN_13, HIGH); 114 digitalWrite(IN_14, LOW); 115 analogWrite(ENB_m1, speedCar); 116 117 118 digitalWrite(IN_21, LOW); 119 digitalWrite(IN_22, HIGH); 120 analogWrite(ENA_m2, speedCar); 121 122 123 digitalWrite(IN_23, HIGH); 124 digitalWrite(IN_24, LOW); 125 analogWrite(ENB_m2, speedCar); 126 127 128 } 129 130void goLeft(){ 131 132 digitalWrite(IN_11, HIGH); 133 digitalWrite(IN_12, LOW); 134 analogWrite(ENA_m1, speedCar); 135 136 137 digitalWrite(IN_13, LOW); 138 digitalWrite(IN_14, HIGH); 139 analogWrite(ENB_m1, speedCar); 140 141 142 digitalWrite(IN_21, HIGH); 143 digitalWrite(IN_22, LOW); 144 analogWrite(ENA_m2, speedCar); 145 146 147 digitalWrite(IN_23, LOW); 148 digitalWrite(IN_24, HIGH); 149 analogWrite(ENB_m2, speedCar); 150 151 152 } 153 154void goAheadRight(){ 155 156 digitalWrite(IN_11, HIGH); 157 digitalWrite(IN_12, LOW); 158 analogWrite(ENA_m1, speedCar/speed_Coeff); 159 160 digitalWrite(IN_13, LOW); 161 digitalWrite(IN_14, HIGH); 162 analogWrite(ENB_m1, speedCar/speed_Coeff); 163 164 165 digitalWrite(IN_21, LOW); 166 digitalWrite(IN_22, HIGH); 167 analogWrite(ENA_m2, speedCar); 168 169 170 digitalWrite(IN_23, HIGH); 171 digitalWrite(IN_24, LOW); 172 analogWrite(ENB_m2, speedCar); 173 174 } 175 176void goAheadLeft(){ 177 178 digitalWrite(IN_11, HIGH); 179 digitalWrite(IN_12, LOW); 180 analogWrite(ENA_m1, speedCar); 181 182 digitalWrite(IN_13, LOW); 183 digitalWrite(IN_14, HIGH); 184 analogWrite(ENB_m1, speedCar); 185 186 187 digitalWrite(IN_21, LOW); 188 digitalWrite(IN_22, HIGH); 189 analogWrite(ENA_m2, speedCar/speed_Coeff); 190 191 192 digitalWrite(IN_23, HIGH); 193 digitalWrite(IN_24, LOW); 194 analogWrite(ENB_m2, speedCar/speed_Coeff); 195 196 } 197 198void goBackRight(){ 199 200 digitalWrite(IN_11, LOW); 201 digitalWrite(IN_12, HIGH); 202 analogWrite(ENA_m1, speedCar/speed_Coeff); 203 204 205 digitalWrite(IN_13, HIGH); 206 digitalWrite(IN_14, LOW); 207 analogWrite(ENB_m1, speedCar/speed_Coeff); 208 209 210 digitalWrite(IN_21, HIGH); 211 digitalWrite(IN_22, LOW); 212 analogWrite(ENA_m2, speedCar); 213 214 215 digitalWrite(IN_23, LOW); 216 digitalWrite(IN_24, HIGH); 217 analogWrite(ENB_m2, speedCar); 218 219 } 220 221void goBackLeft(){ 222 223 digitalWrite(IN_11, LOW); 224 digitalWrite(IN_12, HIGH); 225 analogWrite(ENA_m1, speedCar); 226 227 228 digitalWrite(IN_13, HIGH); 229 digitalWrite(IN_14, LOW); 230 analogWrite(ENB_m1, speedCar); 231 232 233 digitalWrite(IN_21, HIGH); 234 digitalWrite(IN_22, LOW); 235 analogWrite(ENA_m2, speedCar/speed_Coeff); 236 237 238 digitalWrite(IN_23, LOW); 239 digitalWrite(IN_24, HIGH); 240 analogWrite(ENB_m2, speedCar/speed_Coeff); 241 242 } 243 244void stopRobot(){ 245 246 digitalWrite(IN_11, LOW); 247 digitalWrite(IN_12, LOW); 248 analogWrite(ENA_m1, speedCar); 249 250 251 digitalWrite(IN_13, LOW); 252 digitalWrite(IN_14, LOW); 253 analogWrite(ENB_m1, speedCar); 254 255 256 digitalWrite(IN_21, LOW); 257 digitalWrite(IN_22, LOW); 258 analogWrite(ENA_m2, speedCar); 259 260 261 digitalWrite(IN_23, LOW); 262 digitalWrite(IN_24, LOW); 263 analogWrite(ENB_m2, speedCar); 264 265 } 266 267void loop(){ 268 269if (Serial.available() > 0) { 270 command = Serial.read(); 271 stopRobot(); //Initialize with motors stopped. 272 273if (lightFront) {digitalWrite(light_FR, HIGH); digitalWrite(light_FL, HIGH);} 274if (!lightFront) {digitalWrite(light_FR, LOW); digitalWrite(light_FL, LOW);} 275if (lightBack) {digitalWrite(light_BR, HIGH); digitalWrite(light_BL, HIGH);} 276if (!lightBack) {digitalWrite(light_BR, LOW); digitalWrite(light_BL, LOW);} 277if (horn) {digitalWrite(horn_Buzz, HIGH);} 278if (!horn) {digitalWrite(horn_Buzz, LOW);} 279 280switch (command) { 281case 'F':goAhead();break; 282case 'B':goBack();break; 283case 'L':goLeft();break; 284case 'R':goRight();break; 285case 'I':goAheadRight();break; 286case 'G':goAheadLeft();break; 287case 'J':goBackRight();break; 288case 'H':goBackLeft();break; 289case '0':speedCar = 100;break; 290case '1':speedCar = 115;break; 291case '2':speedCar = 130;break; 292case '3':speedCar = 145;break; 293case '4':speedCar = 160;break; 294case '5':speedCar = 175;break; 295case '6':speedCar = 190;break; 296case '7':speedCar = 205;break; 297case '8':speedCar = 220;break; 298case '9':speedCar = 235;break; 299case 'q':speedCar = 255;break; 300case 'W':lightFront = true;break; 301case 'w':lightFront = false;break; 302case 'U':lightBack = true;break; 303case 'u':lightBack = false;break; 304case 'V':horn = true;break; 305case 'v':horn = false;break; 306 307} 308} 309} 310
Downloadable files
the wiring diagram image
the wiring diagram image
Comments
Only logged in users can leave comments