Hello,
I'm trying to make an RC Arduino Car. I've got 4 motors, a motor shield, and a JDY-24M Bluetooth module. I have tried around 20 apps in the hopes of one being able to control the car, but the only one I could get working was the Serial Bluetooth Terminal, but that isn't really good to use as a remote. I've tried setting 4 buttons with the corresponding command, but that didn't work. There was a slight clicking sound everytime I would send a command. Also, when I try to connect to the module with my phone directly from the settings, it refuses to connect, telling me to check the settings of the device. Do you have guys have any idea?
#include <AFMotor.h>
AF_DCMotor motor1(1); // Conectați motorul 1 la M1
AF_DCMotor motor2(2); // Conectați motorul 2 la M2
AF_DCMotor motor3(3); // Conectați motorul 3 la M3
AF_DCMotor motor4(4); // Conectați motorul 4 la M4
char command;
void setup() {
Serial.begin(9600); // Setarea comunicării seriale
Serial.println("Bluetooth control activat!"); // Mesaj de pornire
}
void loop() {
if (Serial.available() > 0) {
command = Serial.read();
Stop(); // Inițializați cu motoarele oprite
switch (command) {
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
}
}
void forward() {
motor1.setSpeed(255); // Viteză maximă
motor1.run(FORWARD);
motor2.setSpeed(255);
motor2.run(FORWARD);
motor3.setSpeed(255);
motor3.run(FORWARD);
motor4.setSpeed(255);
motor4.run(FORWARD);
}
void back() {
motor1.setSpeed(255); // Viteză maximă
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);
motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);
}
void left() {
motor1.setSpeed(255); // Viteză maximă
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);
motor3.run(FORWARD);
motor4.setSpeed(255);
motor4.run(FORWARD);
}
void right() {
motor1.setSpeed(255); // Viteză maximă
motor1.run(FORWARD);
motor2.setSpeed(255);
motor2.run(FORWARD);
motor3.setSpeed(255);
motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);
}
void Stop() {
motor1.setSpeed(0); // Oprește motorul
motor1.run(RELEASE);
motor2.setSpeed(0);
motor2.run(RELEASE);
motor3.setSpeed(0);
motor3.run(RELEASE);
motor4.setSpeed(0);
motor4.run(RELEASE);
}