Control a brushless motor via HC06

Hello everybody,

I'm new in this forum.

I'm looking for a code with an Arduino nano to control a brushless motor via Bluetooth HC06. I've been looking for this sketch for some time and I don't see anything comparable on the internet.

The idea is to be able to run the motor at different speeds according to a value to be encoded via Bluetooth (with a Android device for example).

Below you can see what i want in the sketch like value:

0: motor stop
1: motor running at 50%
2: motor running at 100%

My wiring schema and my sketch is in copy.

Or, is there a topic that would meet my project in this forum ?

Thank for your help :slight_smile:

MoteurBrushlessBT.ino (963 Bytes)

What does your code do? What problems are you having making it do what you want it to do? What are you using to send the data to it?

If you search for "Arduino brushless motor bluetooth" you should get some ideas but maybe not find exactly what you want.

Steve

Hi Steve,

My code must run a brushless motor via a bluetooth android application.

My problem is that on the one hand despite the fact that the code is good with the wiring, the bluetooth transmission does not work.

On the other hand, I would like to modify my code so that, depending on the encoded value, it can turn and stop.

To send the data to it, i use an Android application (Arduino Bluetooth Control).

pulsar7:
My problem is that on the one hand despite the fact that the code is good with the wiring, the bluetooth transmission does not work.

It makes no sense running SoftwareSerial on the hardware Serial pins 0 and 1 and also trying to use them for Serial.prints. Move the HC-06/Bluetooth to different pins.

Then you can use the Serial.println to see what is arriving via bluetooth. Until you get the right data turning up there's no point worrying about the ESC and motor.

Steve

I changed the pins. the bluetooth transmission is working: values appear in the terminal but the motor does not run. How to use these values to run the motor?

What terminal? What values are you getting? Your code said that you were expecting 0-1023. Is that what you are sending?

The esc.write() is expecting something like 0 for stop, 90 for half speed and 180 for full speed (ESCs aren't very linear so that might vary a bit). But whatever values you are sending you need to translate to those. Have a go and post your latest code. And this time please post the code inline properly using </> code tags as described in How to use this forum point 7.

Steve

Here is my code:

#include <SoftwareSerial.h> // TX RX software library for bluetooth

#include <Servo.h> // servo library 
Servo esc; // servo name

int bluetoothTx = 10; // bluetooth tx to rx pin arduino
int bluetoothRx = 11; // bluetooth rx to tx pin arduino

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  esc.attach(2); // attach servo signal wire to pin 2
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()> 0 ) // receive number from bluetooth
  {
    int throttle = bluetooth.read(); // save the received number to throttle
    throttle = map(throttle, 0, 1023, 0, 179);
    Serial.println(throttle); // serial print throttle current number received from bluetooth
    esc.write(throttle); // Turn the motor from the android app
  }


}

When i send 1023 in the terminal server from Android Bluetooth, i get two values, 17 and 44 in the terminal server in the Arduino IDE.

When i send 0, i get only one value, 44.

pulsar7:
When i send 1023 in the terminal server from Android Bluetooth, i get two values, 17 and 44 in the terminal server in the Arduino IDE.

When i send 0, i get only one value, 44.

I've never used the Android "Arduino Bluetooth Control" app if that's what you mean so I don't know what it transmits. And those numbers make no obvious sense so I have no idea what's happening.

Steve