How to make a Bluetooth control 4WD car
Now let’s see what other components are needed to create this smart car.
- Arduino Uno board x 1
- Motor driver shield x 1
- Bluetooth module x 1
- Gear motor x 4
- Robot wheels x 4
- Dot board x 1
- Li-ion battery x 2
- Battery holder x 1
- Jumper wires THIS IS THE CIRCUIT DIAGRAM FOR THE CAR
NEXT IS THE CODEOK, let’s look at the code below. First, you need to download the motor driver shield library.The complete program of this project below;
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
int Speed = 230;
char value;
void setup() {
Serial.begin(9600);
motor1.setSpeed(Speed);
motor2.setSpeed(Speed);
motor3.setSpeed(Speed);
motor4.setSpeed(Speed);
}
void loop() {
if (Serial.available() > 0) {
value = Serial.read();
}
if (value == 'F') {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
} else if (value == 'B') {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
} else if (value == 'L') {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
} else if (value == 'R') {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
} else {
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}
}
Comments
Post a Comment