user76821: 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.

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

76821: <p>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. <strong>The problem I'm having is that my motor will start twitching at very random times even though my Arduino code specifies <code>ESC.write(0)</code></strong>, meaning the ESC should remain completely still.</p>
<p>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 <a href="https://drive.google.com/file/d/1NwVl3F15rTog_EPCxPceJfow1yBoHfq2/view?usp=sharing" rel="nofollow noreferrer">this link</a>.</p>
<p>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 <a href="https://drive.google.com/file/d/1dyn3_VLeubOUxQb4ZejbKco4c8cEg81V/view?usp=sharing" rel="nofollow noreferrer">burn holes</a>.</p>
<p>Here is my arduino code</p>
<pre class="lang-cpp prettyprint-override"><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 &lt;SoftwareSerial.h&gt;

#include &lt;RemoteXY.h&gt;

#include &lt;Servo.h&gt;

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() 


}
</code></pre>
<p>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.</p>
<p>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.</p>
 81923: <p>try detaching the ESC instead of ESC.write(0)</p>
