1

I've been trying to make a Bluetooth slider app that can control the spin speed of a brushless motor. The transmitter I am using is Arduino Mega. The problem I'm having is that my motor will start twitching at very random times even though my Arduino code specifies ESC.write(0), meaning the ESC should remain completely still.

Furthermore, I've noticed that the twitching begins the exact moment I connect my HM10 Bluetooth module to the Arduino. The motor is still able to be controlled by the slider on my app, however, even when the slider is set at zero, the motor turns on its own! I will attach a video to the problem in this link.

A couple of things I've noticed that may be of interest: when the ESC bullet connectors touch each other, there are audible sparks as well as burn holes.

Here is my arduino code


/*
   -- New project --
   
   This source code of graphical user interface 
   has been generated automatically by RemoteXY editor.
   To compile this code using RemoteXY library 2.4.3 or later version 
   download by link http://remotexy.com/en/library/
   To connect using RemoteXY mobile app by link http://remotexy.com/en/download/                   
     - for ANDROID 4.7.12 or later version;
     - for iOS 1.4.7 or later version;
    
   This source code is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.    
*/

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

#include <RemoteXY.h>

#include <Servo.h>

Servo ESC; //create servo object

// RemoteXY connection settings 
#define REMOTEXY_SERIAL_RX 10
#define REMOTEXY_SERIAL_TX 11
#define REMOTEXY_SERIAL_SPEED 9600


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,2,0,0,0,60,0,11,13,1,
  4,0,23,16,17,64,2,26,2,0,
  31,5,22,11,2,26,31,31,79,78,
  0,79,70,70,0,129,0,5,7,18,
  6,17,76,69,68,0,129,0,15,85,
  37,6,17,83,101,114,105,97,108,32,
  111,117,116,112,117,116,0 };
  
// this structure defines all the variables and events of your control interface 
struct {

    // input variables
  int8_t slider_1; // =0..100 slider position 
  uint8_t switch_1; // =1 if switch ON and =0 if OFF 

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0 

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

int power = 8;
int ledPin = 2;

void setup() 
{
  RemoteXY_Init (); 

  digitalWrite(LED_BUILTIN, HIGH);
  // TODO you setup code

  pinMode (LED_BUILTIN, OUTPUT);
  pinMode (power, OUTPUT);
  pinMode (ledPin, OUTPUT);
  //pinMode (7, OUTPUT);
  //int ledMapping;

  ESC.attach(6, 1000, 2000); //attach ESC to output from pin 6
  
  Serial.begin(9600);
}

void loop() 
{ 
  RemoteXY_Handler ();


  //Serial.println(RemoteXY.slider_1);
  digitalWrite(power, HIGH); //supply power to Bluetooth module through pin 8
  //digitalWrite(7, HIGH);
  int ledMapping = map(RemoteXY.slider_1, 0, 100, 0, 255);
  //Serial.println(ledMapping);
  analogWrite(ledPin, ledMapping);

  int spinMapping = map(RemoteXY.slider_1, 0, 100, 0, 180); //map the slider to the servo
  if (RemoteXY.switch_1 == 1){
  ESC.write(spinMapping); //write to the ESC the value of mapped slider
  }
  else if (RemoteXY.switch_1 == 0){
  ESC.write(0);
  }
  Serial.println(spinMapping);
  
  if(RemoteXY.switch_1 == 1){
  digitalWrite(LED_BUILTIN, HIGH);
  }
  else if (RemoteXY.switch_1 == 0){
   digitalWrite(LED_BUILTIN, LOW);
  }
  
  // TODO you loop code
  // use the RemoteXY structure for data transfer
  // do not call delay() 


}

But I don't think it is the problem. The reason is because even though I have ESC.write(0) when the LED switch is off, the ESC still turns (as is apparent in the video) randomly and twitches.

Any help would be greatly appreciated. I am trying to use this as a prototype for an eletric skateboard, but obivously if the motor is turning on its own even when it should be stopped, it is very dangerous to use.

7
  • 1
    please include the actual code instead of a link .... also add a schematic diagram of the circuit
    – jsotola
    May 8, 2021 at 1:12
  • what is your question? ... this is a Q&A site
    – jsotola
    May 8, 2021 at 1:19
  • Here is my arduino code, which I don't think is the problem. The reason is because even though I have ESC.write(0) when the LED switch is off ... how do you know that the led is off? ... the LED code is in a different if statement from the motor code ... also the LED could light very briefly, and you would never see it ... your code contains no debugging functions that could be used to confirm your thinking
    – jsotola
    May 8, 2021 at 1:30
  • 1
    faulty connection may be causing the ESC to deliver power to the motor ... start thinking about testing individual components ... test the "bad connection" theory ... write code that runs the motor for one or two seconds, stops motor for five seconds, and repeats
    – jsotola
    May 8, 2021 at 18:32
  • 1
    look at blinkWithoutDelay example code ... modify it so that the LED is turned off every second, or two, no matter what state it is in .... turn the LED on using if(RemoteXY.switch_1 == 1){ .... that will tell you if there are any phantom button presses .... basically, only a button press turns on the LED, and only a timeout turns it off .... chances are very high that the LED will stay on long enough for you to see it, if a phantom button press is received
    – jsotola
    May 8, 2021 at 18:40

1 Answer 1

1

try detaching the ESC instead of ESC.write(0)

1
  • Could you please expand on your answer. Like quickly explaining how to detach ESC and how that will have an effect.
    – sa_leinad
    Dec 23, 2021 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.