ESC Calibration and Speed Adjustment from Serial Port by Arduino

Sometimes we need to know how an Electrical Speed Controller (ESC) responds to a PWM signal so that the motor speed control could be more precisely. This post provides an Arduino sketch to manually calibrate an ESC and adjust the speed of a brushless motor. The schematic view to route wires is shown as following figure. The PWM signal is generated by the UNO and outputted by the pin 4.

Schematic view

The arduino sketch is given as follows:

#include <servo.h>

#define MAX_SIGNAL 2000  % maximum PWM width
#define MIN_SIGNAL 700     % minimum PWM width
#define MOTOR_PIN 4         % define the pin to output PWM signal

Servo motor;

int RUN_SIGNAL=MIN_SIGNAL;  % initialize the output PWM signal

void setup() {
  Serial.begin(9600);
  Serial.println("Program begin...");
  Serial.println("This program will calibrate the ESC.");

  motor.attach(MOTOR_PIN);

  Serial.println("Now writing maximum output.");
  Serial.println("Turn on power source, then wait 2 seconds and press any key.");
  motor.writeMicroseconds(MAX_SIGNAL);

  // Wait start command from serial port
  while (!Serial.available());
  Serial.read();

  // Send min output
  Serial.println("Sending minimum output");
  motor.writeMicroseconds(RUN_SIGNAL);

}

void loop() {  
  char c;
  if(Serial.available()){
    c=Serial.read();
    if(c=='a')
      RUN_SIGNAL+=10; % input 'a' from serial port to increase the PWM width
    if(c=='d')
      RUN_SIGNAL-=10; % input 'd' from serial port to decrease the PWM width
  }
  motor.writeMicroseconds(RUN_SIGNAL); % write the reference width to drive the motor
  Serial.println(RUN_SIGNAL);
}

Leave a Comment

Your email address will not be published. Required fields are marked *