RC Car help
I was trying to program an RC car, but the HC-05 will not connect. It shows up on my bluetooth connection list, but will never actually connect. Could someone look at my code and see if it is wrong? Otherwise, would it be hardware problems? I will paste the code here (too large to paste as image)
#include <AFMotor.h>
#include <SoftwareSerial.h>
SoftwareSerial bluetoothSerial(1, 0); // RX, TX
//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
char command;
void setup()
{
bluetoothSerial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop() {
if (bluetoothSerial.available() > 0) {
command = bluetoothSerial.read();
Stop(); //initialize with motors stoped
switch (command) { case 'F': forward(); break; case 'B': back(); break; case 'L': left(); break; case 'R': right(); break; } } } I omitted the driving functions
switch (command) { case 'F': forward(); break; case 'B': back(); break; case 'L': left(); break; case 'R': right(); break; } } } I omitted the driving functions
4 Replies
to start, pins 0 and 1 are used by hardware serial, use different pins for
SoftwareSerial
https://lastminuteengineers.com/hc05-bluetooth-arduino-tutorial/Yea i realized that after i soldered wires to the driver module. But I was going to just unplug the connections for pin 0 and 1 before i upload the code and then plug them in once its done uploading, would that work still?
Or sshould i solder those new wires onto other pins. Would 9 and 10 work?
it's best to use two other pins (9 & 10 are fine)
you want to avoid using 0 & 1, it's a pain to upload, and you have no way of debugging since you can use (or even
.begin
) Serial.ok thanks ill try that and get back to you if its still faulty