Components and supplies
Resistor 1k ohm
Arduino UNO
Resistor 2k ohm
Geared DC Motor, 12 V
Dual H-Bridge motor drivers L298
Arduino Nano R3
Caster Wheel
HC-05 Bluetooth Module
Jumper wires (generic)
Tools and machines
Hot glue gun (generic)
Apps and platforms
Arduino IDE
Project description
Code
HC-05 Slave code
arduino
1#define enA 9 2#define in1 4 3#define in2 5 4#define enB 10 5#define in3 6 6#define in4 7 7 8int xAxis, yAxis; 9unsigned int x = 0; 10unsigned int y = 0; 11 12int motorSpeedA = 0; 13int motorSpeedB = 0; 14 15void setup() 16{ 17 pinMode(enA, OUTPUT); 18 pinMode(enB, OUTPUT); 19 pinMode(in1, OUTPUT); 20 pinMode(in2, OUTPUT); 21 pinMode(in3, OUTPUT); 22 pinMode(in4, OUTPUT); 23 24 Serial.begin(38400); 25} 26 27void loop() 28{ 29 x = 510 / 4; 30 y = 510 / 4; 31 32 while (Serial.available() >= 2) 33 { 34 x = Serial.read(); 35 delay(10); 36 y = Serial.read(); 37 } 38 delay(10); 39 xAxis = x*4; 40 yAxis = y*4; 41 42 if (yAxis < 470) { 43 digitalWrite(in1, HIGH); 44 digitalWrite(in2, LOW); 45 digitalWrite(in3, HIGH); 46 digitalWrite(in4, LOW); 47 motorSpeedA = map(yAxis, 470, 0, 0, 255); 48 motorSpeedB = map(yAxis, 470, 0, 0, 255); 49 } 50 51 else if (yAxis > 550) 52 { 53 digitalWrite(in1, LOW); 54 digitalWrite(in2, HIGH); 55 digitalWrite(in3, LOW); 56 digitalWrite(in4, HIGH); 57 motorSpeedA = map(yAxis, 550, 1023, 0, 255); 58 motorSpeedB = map(yAxis, 550, 1023, 0, 255); 59 } 60 61 else 62 { 63 motorSpeedA = 0; 64 motorSpeedB = 0; 65 } 66 67 if (xAxis < 470) { 68 69 int xMapped = map(xAxis, 470, 0, 0, 255); 70 motorSpeedA = motorSpeedA - xMapped; 71 motorSpeedB = motorSpeedB + xMapped; 72 73 if (motorSpeedA < 0) 74 { 75 motorSpeedA = 0; 76 } 77 if (motorSpeedB > 255) 78 { 79 motorSpeedB = 255; 80 } 81 } 82 if (xAxis > 550) 83 { 84 int xMapped = map(xAxis, 550, 1023, 0, 255); 85 motorSpeedA = motorSpeedA + xMapped; 86 motorSpeedB = motorSpeedB - xMapped; 87 if (motorSpeedA > 255) 88 { 89 motorSpeedA = 255; 90 } 91 if (motorSpeedB < 0) 92 { 93 motorSpeedB = 0; 94 } 95 } 96 97 if (motorSpeedA < 70) 98 { 99 motorSpeedA = 0; 100 } 101 if (motorSpeedB < 70) 102 { 103 motorSpeedB = 0; 104 } 105 analogWrite(enA, motorSpeedA); 106 analogWrite(enB, motorSpeedB); 107}
HC-05 Master code
arduino
1int xAxis, yAxis; 2 3void setup() { 4 Serial.begin(38400); 5} 6 7void loop() { 8 xAxis = analogRead(A0); 9 yAxis = analogRead(A1); 10 Serial.write(xAxis/4); 11 Serial.write(yAxis/4); 12 delay(20); 13}
HC-05 Master code
arduino
1int xAxis, yAxis; 2 3void setup() { 4 Serial.begin(38400); 5} 6 7void loop() { 8 xAxis = analogRead(A0); 9 yAxis = analogRead(A1); 10 Serial.write(xAxis/4); 11 Serial.write(yAxis/4); 12 delay(20); 13}
HC-05 Slave code
arduino
1#define enA 9 2#define in1 4 3#define in2 5 4#define enB 10 5#define in3 6 6#define in4 7 7 8int xAxis, yAxis; 9unsigned int x = 0; 10unsigned int y = 0; 11 12int motorSpeedA = 0; 13int motorSpeedB = 0; 14 15void setup() 16{ 17 pinMode(enA, OUTPUT); 18 pinMode(enB, OUTPUT); 19 pinMode(in1, OUTPUT); 20 pinMode(in2, OUTPUT); 21 pinMode(in3, OUTPUT); 22 pinMode(in4, OUTPUT); 23 24 Serial.begin(38400); 25} 26 27void loop() 28{ 29 x = 510 / 4; 30 y = 510 / 4; 31 32 while (Serial.available() >= 2) 33 { 34 x = Serial.read(); 35 delay(10); 36 y = Serial.read(); 37 } 38 delay(10); 39 xAxis = x*4; 40 yAxis = y*4; 41 42 if (yAxis < 470) { 43 digitalWrite(in1, HIGH); 44 digitalWrite(in2, LOW); 45 digitalWrite(in3, HIGH); 46 digitalWrite(in4, LOW); 47 motorSpeedA = map(yAxis, 470, 0, 0, 255); 48 motorSpeedB = map(yAxis, 470, 0, 0, 255); 49 } 50 51 else if (yAxis > 550) 52 { 53 digitalWrite(in1, LOW); 54 digitalWrite(in2, HIGH); 55 digitalWrite(in3, LOW); 56 digitalWrite(in4, HIGH); 57 motorSpeedA = map(yAxis, 550, 1023, 0, 255); 58 motorSpeedB = map(yAxis, 550, 1023, 0, 255); 59 } 60 61 else 62 { 63 motorSpeedA = 0; 64 motorSpeedB = 0; 65 } 66 67 if (xAxis < 470) { 68 69 int xMapped = map(xAxis, 470, 0, 0, 255); 70 motorSpeedA = motorSpeedA - xMapped; 71 motorSpeedB = motorSpeedB + xMapped; 72 73 if (motorSpeedA < 0) 74 { 75 motorSpeedA = 0; 76 } 77 if (motorSpeedB > 255) 78 { 79 motorSpeedB = 255; 80 } 81 } 82 if (xAxis > 550) 83 { 84 int xMapped = map(xAxis, 550, 1023, 0, 255); 85 motorSpeedA = motorSpeedA + xMapped; 86 motorSpeedB = motorSpeedB - xMapped; 87 if (motorSpeedA > 255) 88 { 89 motorSpeedA = 255; 90 } 91 if (motorSpeedB < 0) 92 { 93 motorSpeedB = 0; 94 } 95 } 96 97 if (motorSpeedA < 70) 98 { 99 motorSpeedA = 0; 100 } 101 if (motorSpeedB < 70) 102 { 103 motorSpeedB = 0; 104 } 105 analogWrite(enA, motorSpeedA); 106 analogWrite(enB, motorSpeedB); 107}
Downloadable files
Arduino-Robot-Car-HC-05-Bluetooth-Control-Circuit-Schematic
The circuit diagram
Arduino-Robot-Car-HC-05-Bluetooth-Control-Circuit-Schematic
Comments
Only logged in users can leave comments
MinukaThesathYapa
0 Followers
•0 Projects
Table of contents
Intro
2
0