With great respected Sir,
I want a programme for Bluetooth controlled Car. I have lots of programme from websites but these are not working with Arduino Mega 2560.
I would request all of you that please give programme or recommendation for this project.
What have you tried? How much do you know about arduino? Have you looked into the HC-05 or HC-06 modules? is the mega on the car side or the computer/controller side? Does the car already have bluetooth built into it, or are you trying to build your own? Please give more information or trying to help is insanely difficult.
Personally, I would recommend getting a HC-05 bluetooth module, set it to "transmit mode" on the controller/pc/remote side, or "receive mode" for the actual car itself.
NOTE: HC-06 module will only work for receiving a connection, not creating one. AKA, you can connect TO the HC-06, but if you want the HC-06 to connect to another bluetooth device, you'll need a HC-05.
Seriously, this is as far as I can help without more info
Sir, I have HC05 Bluetooth which I have connected Rx to tx of Arduino mega 2560 and tx to Rx.
Ok, that's a start that you already have a HC05.
-
Are you using a arduino for a controller and the car itself? Are you using arduino for just the car? Or just the controller?
-
The only info I have is "I want a programme for Bluetooth controlled Car. I have a correctly connected HC05 Bluetooth and running an arduino Mega". Might need a tiny bit more.
-
"I have lots of programme from websites but these are not working with Arduino Mega 2560" if it's compatible with a HC05, it shouldn't matter what arduino you are using. Have you configured the HC05 correctly?
-
How new are you to arduino? Are you a noob? Moderately ok? Above average? Roughly what sort of a person am I talking to here, just so that I can help you as effectively as possible
I am confirmed that I have Arduino Mega 2560,Bluetooth HC05 and Adafruit motor driver sheild and code is given below but it is not working.
When test my motor with Arduino example it is working.
I request you please help.
include <AFMotor.h>
//initial motors pin
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
char command;
void setup()
{
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop(){
if(Serial.available() > 0){
command = Serial.read();
Stop(); //initialize with motors stoped
//Change pin mode only if new command is different from previous.
//Serial.println(command);
switch(command){
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
}
}
void forward()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255);//Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255);//Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}
void back()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void left()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}
void right()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void Stop()
{
motor1.setSpeed(0); //Define minimum velocity
motor1.run(RELEASE); //stop the motor when release the button
motor2.setSpeed(0); //Define minimum velocity
motor2.run(RELEASE); //rotate the motor clockwise
motor3.setSpeed(0); //Define minimum velocity
motor3.run(RELEASE); //stop the motor when release the button
motor4.setSpeed(0); //Define minimum velocity
motor4.run(RELEASE); //stop the motor when release the button
}
Ok, supplied code, that's a massive help. I'll see what I can do, gimme 5 minutes...
-
You have forgotten the "#" symbol right at the start, easy fix
-
It all seems to compile fine, so my thoughts is that the issue is the actual HC05 itself. I suspect you have just put the HC05 into the circuit without configuring it. There are tonnes of guides online as to how to configure the HC05. The issue is that it won't just pickup any and all signals flying about. It needs to be paired to a device beforehand. Once it's configured THEN you can do exactly what you are trying here.
-
Please note that the HC05 is a 5v board that takes a 3.3v signal, watch out for that. Connecting the Vcc to 3.3v will give garbage results (Trust me, took me a week of debugging to find that one).
Here is a quick "How to" to read through. Remember to set the pins in the code to the ones you are using on the arduino. If you are struggling, try disconnecting the HC05 from pins 0 and 1 altogether and (Just while configuring it), move it to pins 10 and 11 before moving it back: https://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/
Alternatively if you still have troubles, connect your computer to the arduino, connect the HC05 to Serial2 instead of the standard Serial pins 0 and 1, then just send to the computer what the HC05 is recieving (E.g. Serial.println(Serial2.read()); //loop this forever, then look at terminal monitor while the arduino is plugged in)
I have corrected every thing whatever you found out mistakes in my programming. And I have also changed bait rate from 9600 to 115200 but still it is not working. Please recommend me other right way.
When communicating with the other device the arduino can use a bitrate of 115200, but when configuring the HC05 it needs to be talking to it with a bitrate of 9600. I have some code that should help you:
void setup() { }
void loop() { }
This above code is designed to be blank so that the arduino completely ignores everything. That way, you can talk DIRECTLY to the HC05 on pins D0 and D1 (The standard serial communications pins).
Upload the code, then connect the HC05 to pins D0 and D1 making sure to connect "KEY" to 5v to force it into command mode. Then open your serial monitor and type "AT" just like that, all caps. If you get back the response "Ok" then we can continue. If it doesn't do anything, then swap pins D0 and D1 around.If it then STILL doesn't respond with anything, then you may have a faulty HC05.
If it returns something like "ERROR: 17" or something along those lines, then the HC05 is still working. Don't worry, throwing an error for the first message or two is completely normal, if not annoying. It does that for some reason. Even if you give it complete rubbish commands, it should still respond with "ERROR: SOME_ERROR_CODE_HERE", which means the HC05 is functional
Once you have the HC05 returning "Ok" when sending the first basic "AT" command (Or a valid error code), then we can start configuring it.
To check the firmware version, type "AT+VERSION?". It should return something like "+VERSION:2.0-20100601" followed by "Ok". Infact, every single command (Apart from the first one) should return "Ok" after it.
Here are some other commands you may want to type in:
AT+NAME=RC-Bluetooth-Car - This changes the name of the bluetooth module
AT+ROLE=0 - This changes it to slave mode
AT+CLASS? - This requests class data. Should be an integer between 0 and 3?
AT+PSWD=1234 - This sets the default password to 1234
AT+CMODE=1 - This allows the unit to connect to any bluetooth device
AT+RMAAD - This removes all authenticaed devices. This is completely optional
AT+STATE? - This asks the module for it's current status
If you want other commands to try out, this is a site with a list of ALL AT commands that the HC05 will accept, as well as descriptions of how to use them and what they do:
https://www.itead.cc/wiki/Serial_Port_Bluetooth_Module_(Master/Slave)_:_HC-05