Can't control via bluetooth

Hey again,

I got my RC car code compiling and got it to upload to my Arduino Uno board. After connecting with the HC-05 Bluetooth receiver, it didn't seem to work.

Electronics I use:

-Arduino Uno
-HC-05 Bluetooth module
-Adafruit v2.3 motor shield
-NEMA-17 stepper motor
-DC motor

Any help is appreciated!

App: https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&hl=en

Code:

#include <AFMotor.h>

AF_DCMotor motor1(1);        // Creating DC motor with default settings
AF_Stepper motor2(400, 2);   // Creating Stepper motor with default settings

char command;

void setup() 
{
  Serial.begin(38400);  //Sets the data rate in bits per second for serial data transmission, here it would be 38400 baud
}

void loop(){  // Telling arduino what to do after receiving command from app (app: https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&hl=en) 
  if(Serial.available() > 0){ 
  command = Serial.read();
    switch(command){
    case 'F':  
      forward();
      break;
    case 'B':  
       back();
      break;
    case 'L':  
      left();
      break;
    case 'R':
      right();
      break;
    }
  } 
}

void forward()
{
  motor1.setSpeed(255);
  motor1.run(FORWARD);
}

void back()
{
  motor1.setSpeed(255);
  motor1.run(BACKWARD);
}

void left()
{
  motor1.setSpeed(128);
  motor1.run(FORWARD);
  motor2.step(200, FORWARD, SINGLE);
}

void right()
{
  motor1.setSpeed(128);
  motor1.run(FORWARD);
  motor2.step(200, BACKWARD, SINGLE);
}

As you seem to have the Bluetooth module connected to Pins 0 and 1 on the Uno it is not possible to view debug messages on the Serial Monitor.

If this was my project I would have the Bluetooth module on two other pins using SoftwareSerial so I could use Serial.print() to let me see what was being received from the Bluetooth module. However it would be best to use SoftwareSerial at 9600 baud - at least for initial tests.

Have you written a short program just to learn how to work with the Bluetooth module?

...R

Yes, I tested with a short program:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(3,2);

void setup() {
  Serial.begin(9600); //open the serial port
  mySerial.begin(9600); // open the bluetooth serial port
}

void loop() {
  if(mySerial.available()){
    Serial.println(mySerial.readString()); // send from serial to bluetooth
  }
  if(Serial.available()){
    mySerial.println(Serial.readString()); // send from bluetooth to serial
  }
}

I connected my laptop with the bt module and downloaded a bt terminal to send commands, and it got written out to the Serial Monitor. Also changed the baud to 9600 in my main code and soldered the RX and TX to pin 2 and 3

Serial.print(mySerial.read( ));
and
mySerial.print(Serial.read());

is how I would do it.

.

kPa___:
Also changed the baud to 9600 in my main code and soldered the RX and TX to pin 2 and 3

I'm not sure what that refers to. Is it what you did with the test program or is it something you have done with the RC car?

If it is what you did with the RC car then please post the revised program.

...R

Hey,

I just realized why the motors would work :D! I hadn't given my shield energy to power the motors: