Arduino BT Car does not work

german version see below

Hey, I started a little project with my Arduino Uno but now I reached the end of my knowlegde and need help.

I use:
-Arduino Uno R3
-KA03 Motorshield (L298P)
-hm-10 BT module (used hc-05 but was not connectable with my iPhone)
-resistors (1k and 2.2k at the RX pin)
-dabble (App)

I can find and connect the module with the phone via the app.
If I press now the buttons of the app, nothing happens. I checked the serialmonitor, but it only writes "stop". So maybe the module receives nothing.
I also downloaded the manufactor`s app and connected with it, but it shows "wrong password"?
In the serialmonitor I tried to send "AT" but nothing happened.
Maybe there is a issue in my code.. Thank you for your help!

german:
Hallo, wollte meinen angestaubten Arduino für ein BT-Car nutzen, doch es funktioniert nicht wie gewollt. Ich nutze die "dabble" App und die Verbindung zum hm-10 scheint zu funktionieren, jedoch passiert nichts, wenn ich die Buttons drücke. Im serialmonitor wird immer nur "stop" geschrieben, also scheint kein anderer Befehl befolgt zu werden.
Habe auch die BT-App des Herstellers versucht und die Verbindung wird hergestellt (LED am Modul leuchtet, statt zu blinken), aber es wird "wrong password" angezeigt. Am Telefon wird das Modul nach Verbindung mit der App unter den BT-Geräten als verbunden angezeigt, davor ist es nicht sichtbar. Vielleicht liegt der Fehler aber auch im Code..
Jedenfalls, danke im Voraus.

/*

Code by Pascal

BT hm-10 RX --> 2
         TX --> 3

*/

#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE

#include <Dabble.h>

//setup pins
int motorA_en = 5;
int motorB_en = 9;
int motorA_dirF = 4;
int motorA_dirB = 7;
int motorB_dirF = 12;
int motorB_dirB = 13;

void setup()
{

  Serial.begin(250000);
  Dabble.begin(9600);

  pinMode(motorA_en, OUTPUT);
  pinMode(motorB_en, OUTPUT);
  pinMode(motorA_dirF, OUTPUT);
  pinMode(motorA_dirB, OUTPUT);
  pinMode(motorB_dirF, OUTPUT);
  pinMode(motorB_dirB, OUTPUT);

}

void loop()
{


  Dabble.processInput();


  if (GamePad.isUpPressed())
  {
    Serial.print("UP");
    forward();
  }

  else if (GamePad.isDownPressed())
  {
    Serial.print("DOWN");
    backward();
  }

  else  if (GamePad.isLeftPressed())
  {
    Serial.print("Left");
    left();
  }

  else  if (GamePad.isRightPressed())
  {
    Serial.print("Right");
    right();
  }

  else
  {
    Serial.println("stop");
    Stop();
  }


}

void forward()
{
  analogWrite(motorA_en, 255);
  analogWrite(motorB_en, 255);
  digitalWrite(motorA_dirF, HIGH);
  digitalWrite(motorA_dirB, LOW);
  digitalWrite(motorB_dirF, HIGH);
  digitalWrite(motorB_dirB, LOW);
}
void backward()
{
  analogWrite(motorA_en, 255);
  analogWrite(motorB_en, 255);
  digitalWrite(motorA_dirF, LOW);
  digitalWrite(motorA_dirB, HIGH);
  digitalWrite(motorB_dirF, LOW);
  digitalWrite(motorB_dirB, HIGH);
}
void left()
{
  analogWrite(motorA_en, 255);
  analogWrite(motorB_en, 255);
  digitalWrite(motorA_dirF, LOW);
  digitalWrite(motorA_dirB, HIGH);
  digitalWrite(motorB_dirF, HIGH);
  digitalWrite(motorB_dirB, LOW);
}
void right()
{
  analogWrite(motorA_en, 255);
  analogWrite(motorB_en, 255);
  digitalWrite(motorA_dirF, HIGH);
  digitalWrite(motorA_dirB, LOW);
  digitalWrite(motorB_dirF, LOW);
  digitalWrite(motorB_dirB, HIGH);
}
void Stop()
{
  analogWrite(motorA_en, 0);
  analogWrite(motorB_en, 0);
  digitalWrite(motorA_dirF, LOW);
  digitalWrite(motorA_dirB, LOW);
  digitalWrite(motorB_dirF, LOW);
  digitalWrite(motorB_dirB, LOW);
}

Hello @cornerofcarlos
Can you try to be more informative
Try posting the schematic or hand made circuit diagram of your project
And i did not find to which pin of the Arduino UNO is connected to the BT module ( is not define)
Have you connected the RX and TX of the BT module to the RX and TX of the Arduino ?
I could help you with this .
Lucky!

Hallo
Beginne mit einem ganz einfachen Beispiel. So lernst du wie die Hardware funktioniert.

Hello,
I connected RX with D2 and TX with D3.

Do you mean pin 0(RX) and 1(TX) on the arduino?
BR, Carlos

Danke, werde ich machen. Ein besseres Grundwissen wird mir sicher helfen!

Hi @cornerofcarlos
Then define both the pin D2 and D3 connected in your code something like this

int bt tx=3;
int bt rx=2;

```And you better write the code in this way 
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE

#include <Dabble.h>

//setup pins
int motorA_en = 5;
int motorB_en = 9;
int motorA_dirF = 4;
int motorA_dirB = 7;
int motorB_dirF = 12;
int motorB_dirB = 13;
int bt tx=3;
int bt rx=2;
void forward()
{
  analogWrite(motorA_en, 255);
  analogWrite(motorB_en, 255);
  digitalWrite(motorA_dirF, HIGH);
  digitalWrite(motorA_dirB, LOW);
  digitalWrite(motorB_dirF, HIGH);
  digitalWrite(motorB_dirB, LOW);
}
void backward()
{
  analogWrite(motorA_en, 255);
  analogWrite(motorB_en, 255);
  digitalWrite(motorA_dirF, LOW);
  digitalWrite(motorA_dirB, HIGH);
  digitalWrite(motorB_dirF, LOW);
  digitalWrite(motorB_dirB, HIGH);
}
void left()
{
  analogWrite(motorA_en, 255);
  analogWrite(motorB_en, 255);
  digitalWrite(motorA_dirF, LOW);
  digitalWrite(motorA_dirB, HIGH);
  digitalWrite(motorB_dirF, HIGH);
  digitalWrite(motorB_dirB, LOW);
}
void right()
{
  analogWrite(motorA_en, 255);
  analogWrite(motorB_en, 255);
  digitalWrite(motorA_dirF, HIGH);
  digitalWrite(motorA_dirB, LOW);
  digitalWrite(motorB_dirF, LOW);
  digitalWrite(motorB_dirB, HIGH);
}
void Stop()
{
  analogWrite(motorA_en, 0);
  analogWrite(motorB_en, 0);
  digitalWrite(motorA_dirF, LOW);
  digitalWrite(motorA_dirB, LOW);
  digitalWrite(motorB_dirF, LOW);
  digitalWrite(motorB_dirB, LOW);
}
void setup()
{

  Serial.begin(250000);
  Dabble.begin(9600);

  pinMode(motorA_en, OUTPUT);
  pinMode(motorB_en, OUTPUT);
  pinMode(motorA_dirF, OUTPUT);
  pinMode(motorA_dirB, OUTPUT);
  pinMode(motorB_dirF, OUTPUT);
  pinMode(motorB_dirB, OUTPUT);

}

void loop()
{


  Dabble.processInput();


  if (GamePad.isUpPressed())
  {
    Serial.print("UP");
    forward();
  }

  else if (GamePad.isDownPressed())
  {
    Serial.print("DOWN");
    backward();
  }

  else  if (GamePad.isLeftPressed())
  {
    Serial.print("Left");
    left();
  }

  else  if (GamePad.isRightPressed())
  {
    Serial.print("Right");
    right();
  }

  else
  {
    Serial.println("stop");
    Stop();
  }
}
Lucky

And setup this pin to be use as input or output in the void setup()

Hi @justinlucky
I tried to do it, but nothing changed.

added the pins

int bt_tx = 3;
int bt_rx = 2;

(without the "_" i got an compiling error)
and set them up as output

pinMode(bt_rx, OUTPUT);
pinMode(bt_tx, OUTPUT);

(also tried as input without success)

BR, Carlos

Rx = receive = input
Tx = transmit = output

Hey don't worry it will work
Do you have the dabble library ?

And paste the errors in the discussion box
We will still help you
Lucky

thank you, but I tried all 4 ways to be sure..
both as input, both as output, rx input tx output and rx output tx input

Yes, I checked the lib manager to be sure..

compiling error if I use

int bt tx = 3;
int bt rx = 2;

but if I use

int bt_tx = 3;
int bt_rx = 2;

there is no error..

I hope it is ok if I just copy the error message.

Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Uno"

projectforum:13:8: error: expected initializer before 'tx'

int bt tx = 3;

    ^~

projectforum:14:8: error: expected initializer before 'rx'

int bt rx = 2;

    ^~

C:\Users\Pascal\Desktop\projectforum\projectforum.ino: In function 'void setup()':

projectforum:66:11: error: 'bt_rx' was not declared in this scope

pinMode(bt_rx, INPUT);

       ^~~~~

projectforum:67:11: error: 'bt_tx' was not declared in this scope

pinMode(bt_tx, OUTPUT);

       ^~~~~

exit status 1

expected initializer before 'tx'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Hey @cornerofcarlos
This should work cause it work for my previous project too .

[code]
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
#include <Dabble.h>
int enR = 4;   //These are the pins for our motor driver IC
int inAR = 5;
int inBR = 6;
int enL = 7;
int inAL = 8;
int inBL = 9;

void setup() 
{
  pinMode(enR, OUTPUT);
  pinMode(inAR, OUTPUT); 
  pinMode(inBR, OUTPUT);
  pinMode(enL, OUTPUT);
  pinMode(inAL, OUTPUT); 
  pinMode(inBL, OUTPUT);
  Serial.begin(250000);    // Set your Serial Monitor is set at 250000
  Dabble.begin(9600);      // This is the baude rate of the HM-10
}

void loop() {
Dabble.processInput();  // This line is crucial in grabbing our data  
  
  if (GamePad.isUpPressed())       
  {
    Serial.println("Forward");
    analogWrite(enR, 255);
    digitalWrite(inAR, LOW);
    digitalWrite(inBR, HIGH);
    analogWrite(enL, 255);
    digitalWrite(inAL, LOW);
    digitalWrite(inBL, HIGH);
  }

  else if (GamePad.isDownPressed())
  {
    Serial.println("Backward");
    analogWrite(enR, 255);
    digitalWrite(inAR, HIGH);
    digitalWrite(inBR, LOW);
    analogWrite(enL, 255);
    digitalWrite(inAL, HIGH);
    digitalWrite(inBL, LOW);
  }

  else if (GamePad.isLeftPressed())
  {
    Serial.println("Left");
    analogWrite(enR, 255);
    digitalWrite(inAR, LOW);
    digitalWrite(inBR, HIGH);
    analogWrite(enL, 255);
    digitalWrite(inAL, HIGH);
    digitalWrite(inBL, LOW);
  }

  else if (GamePad.isRightPressed())
  {
    Serial.println("Right");
    analogWrite(enR, 255);
    digitalWrite(inAR, HIGH);
    digitalWrite(inBR, LOW);
    analogWrite(enL, 255);
    digitalWrite(inAL, LOW);
    digitalWrite(inBL, HIGH);
  }
  else 
  {
    Serial.println("Stopped");
    analogWrite(enR, 0);
    digitalWrite(inAR, LOW);
    digitalWrite(inBR, LOW);
    analogWrite(enL, 0);
    digitalWrite(inAL, LOW);
    digitalWrite(inBL, LOW);
  }
}
[/code]

And include this Zip file in the
#include <Dabble.h>
Dabble-master.zip (120.1 KB)

Hope this will work
And wishing you luck
Lucky

@justinlucky I will try it out and give you an Update later.
Anyway, thank you very much for yor support.

Yes sure
And you are welcome
Have you carried out the simulation ?

Tried it out without success.
But I will try another way to make sure the module (or connection) is working or not.

  1. I will try out an example with an LED
  2. I will try it out with an Android phone
  3. If this does not work I will try it out with android and my hc-05 module

I ejected the motorshield and took a closer look at the arduino board and there are 3 LEDs.. 1 RX, 1TX and 1 L.
The "L" and the "TX" LEDs are working(they are shining, not blinking), but the "RX" LED does nothing.

No I did not run any simulation.

@justinlucky
It is working now..
I tried an example with an brightness controlled LED and therefore i made also the wireing new new. I made an mistake and mixed up RX and TX. I am sooo sorry that I wasted much of your time, but now its finally working and I can focus on the next steps of this project. I have learned plenty new things about the arduino. Thank you also for that.

I also want to thank you @paulpaulson and @wno158 for supporting me.

Hello,
many thanks for your reply.
Enjoy the weekend and have a good time :vulcan_salute:

1 Like