Controlling ESC

I have this ESC:

And this motor:

I want to control it with an arduino.

I've tried a couple random bits of code from the forum, all for use with various ESC.

The most basic one worked for a bit, then stopped.

I've attached it here:

#include <Servo.h>

Servo ESC;     // Create servo object to control the ESC

int speed = 0;  // Starting speed of the motor
int increment = 1;  // Speed change per iteration

void setup() {
  // Attach the ESC on pin 9
  ESC.attach(9, 1000, 2000); // (pin, min pulse width, max pulse width in microseconds)
}

void loop() {
  // Speeding up: Increase the speed gradually
  for (speed = 0; speed <= 180; speed++) {
    ESC.write(speed);  // Send the PWM signal to the ESC
    delay(20);         // Delay to control the speed change rate (adjust for smoother transition)
  }

  delay(1000); // Wait for 1 second at full speed

  // Slowing down: Decrease the speed gradually
  for (speed = 180; speed >= 0; speed--) {
    ESC.write(speed);  // Send the PWM signal to the ESC
    delay(20);         // Delay to control the speed change rate
  }

  delay(1000); // Wait for 1 second at stop
}

I have the GND pin (black) from the ESC connected to my Arduino GND, and the control pin (white) connected to pin 9. The red power pin is NOT connected.

I am completely out of my depth here, and I apologize in advance. Anyone with some knowledge or ideas would be very appreciated

That being said, this code does some interesting things:

//This code can be used for any purpose.

#include <Servo.h> //Using servo library to control ESC

Servo ESC1; //Creating a servo class with name as esc

int pos = 0; //Sets position variable


void arm(){

setSpeed(0); //Sets speed variable delay(1000);

}

void setSpeed(int speed){

int angle = map(speed, 0, 100, 0, 180); //maps servo  to different speeds as percentage 

ESC1.write(angle);

}

void setup() {

ESC1.attach(9); //Adds ESC to certain pin. 

arm();

}

void loop() {

int speed; // speed variable

for(speed = 0; speed <= 70; speed += 5) { //Cycles speed up to 70% power for 1 second

setSpeed(speed); //Creates variable for speed to be used in in for loop

delay(1000);

}

delay(4000); //Stays on for 4 seconds

for(speed = 70; speed > 0; speed -= 5) { // Cycles speed down to 0% power for 1 second

setSpeed(speed); 

delay(1000);

}

setSpeed(0); //Sets speed variable to zero no matter what

delay(1000); //Turns off for 1 second

}

The motor starts by beeping once a second four times, silent for two seconds, then two quick beeps. After a number of seconds it repeats. Occasionally next it will spin at low speed for one second or less, other times it gives one long low beep. Other times it will rev up and spin for four seconds. Then other times it sits there and beeps one time a second endlessly until I reset it. Or two long beeps. Or one quick beep and a tiny rev.

Super super random.

Unfortunately, the sellers manual is barely understandable half chinese english and not helpful!

#include <Servo.h>
Servo motor;

int mot_pin = 9;   
int max_pwm = 2300;
int min_pwm = 800;
int pwm;
 
void setup(){
Serial.begin(9600);
motor.attach(mot_pin);
delay(1000);
motor.writeMicroseconds(max_pwm);
delay(2000);
motor.writeMicroseconds(min_pwm);
delay(4000);
}

void loop(){
  pwm = analogRead(A0);
  motor.writeMicroseconds(map(pwm,0,1023,800,2300));
}

That ESC needs to be water cooled.
Are you running water through it?

apparently the motor too

1 Like

The beeping is probably the ESC, not the motor. Listen carefully to verify. The beep codes are telling you info about the signal. AI gives these common beep codes:

Electronic speed controllers (ESCs) emit beeping tones to indicate their status and any errors. The beeps can be high or low, and have different frequencies and repeat rates. Here are some common ESC beep codes:
* **1 beep, 3 seconds**: Waiting for a signal
* **1 beep, 10 seconds**: Idle ESC tone
* **1 beep after commanding motor start**: Stall protection engaged
* **2 beeps, 3 seconds**: Invalid signal
* **3 beeps, 10 seconds**: Bad signal quality
* **3 beeps, once**: Booting to config mode
* **3 beeps, 5 seconds**: Over-temperature
* **4 beeps, once**: Bi-Directional DShot protocol
* **5 beeps, once**: Proshot protocol
* **6 beeps, 3 seconds**: Non-Zero Signal on Start

Yours may or may not conform to these codes.

You probably haven't calibrated the ESC. Try the following steps:

Connect ESC to signal (no power)
Raise throttle all the way up
Connect power
Wait for beep
Bring throttle all the way down
You should hear multiple confirmation beeps
The ESC should be calibrated now with minimum and maximum signal boundaries.

You only need to do this once. Upon load, the ESC should be receiving a signal (1000 for example). If not, it won't work. So give it a 1000 signal during setup, then you can control it inside of your loop using code.

If you don't have a transmitter integrated, then you you can use the "setup" code provided by ua6em to calibrate only once. Then comment it out and replace it by a 1000 signal.

1 Like

This gives me zero response from the motor. Not even a beep.

Not as yet. According to my research the water cooling is only need when running the motor at high speed for long periods of time, or with high torque.

Currently I have it connected up, and everything is very cold. Do you think I need the water yet, or should it be ok?

It is the motor. Definitely NOT the ESC. I was very surprised - never heard a motor beep before!!
Unfortunately I haven't heard any of those beep codes. And mine has multiple pitches too!!

Something like this?

#include <Servo.h>
Servo motor;

int mot_pin = 9;   
int max_pwm = 2300;
int min_pwm = 800;
int pwm;
 
void setup(){
Serial.begin(9600);
motor.attach(mot_pin);
delay(1000);
motor.writeMicroseconds(1000);
delay(2000);
//motor.writeMicroseconds(min_pwm);
//delay(4000);
}

void loop(){
  pwm = analogRead(A0);
  motor.writeMicroseconds(map(pwm,0,1023,800,2300));
}

Here's a short video of some of the beeps.

I've even heard it do scales:

Correct! Once the ESC is calibrated, the code above should work. Just make sure the output of your "map" function matches the range used when calibrating. So use the same 800-2300 to calibrate.

To verify that everything is working properly, the ESC should be beeping (with about a second delay between beeps) during the sketch upload, then it should go quite once it hits setup and receives the 1000 signal. But if you calibrated to start at 800, then use 800 instead of 1000 in setup, so the motor won't be spinning at all. Then as you send higher values, the motor will start spinning.

1 Like

Alternatively, you may just want to stick to 1000-2000 for calibration and mapping. That's the typical range used and the range provided by typical transmitters.

Finally, I don't see the ESC in the video, so there's a small change that it requires a different calibration process; however, the process given works for most ESCs.

Nothing. No beeps. Once the code hits set up, it beeps once a second for four seconds, followed by two quick beeps.

The motor does not spin. Not with this code. Doesn't matter what A0 is reading - the motor does nothing. Ever

Hold on, I'll get you a photo

Yes, I'm using alligator clips. To be perfectly blunt, I could not find anything that actually certifies which ESC wire goes to which motor wire. They aren't colour matched, the motor manual didn't say, and the ESC manual was less than useless.

The current configuration works in that occasionally I'll get a response. Plus it matches the dodgy diagram in the ESC manual exactly

Yikes. Thanks for clarifying though.

Found this document that does mention motors beeping. First I've heard of the motor beeping, huh.

Good luck.

1 Like

Did you see my second video containing it beeping scales?? Next it's gonna get up and talk, or sing opera....

Probably a good idea for me to get the supersonic ESC - though I do need a waterproof one as this is going in a RC boat

1 Like
#include <Servo.h>
Servo motor;

int mot_pin = 9;   
int max_pwm = 2300;
int min_pwm = 800;
int pwm;
 
void setup(){
Serial.begin(9600);
motor.attach(mot_pin);
delay(1000);
motor.writeMicroseconds(1500);
delay(2000);
//motor.writeMicroseconds(min_pwm);
//delay(4000);
}

void loop(){
 // R = 2.5V
  pwm = analogRead(A0);
  motor.writeMicroseconds(map(pwm,0,1023,800,2300));
}

Maybe, sorry I can't say at this point.

What battery are you using? Apologies if you already mentioned it.

Are you sure those alligator clips and wires are conducting properly? I've had it where it was just a broken test wire that was fouling things up, maybe that's the case?