Problem controlling Hitec ESC with Arduino Mega

I recently purchased a Hitec Energy Sport 50A ESC and a brushless motor 930Kv 28.9A . I am using a 12V 35AH SLA battery to power the ESC/motor. I am trying to calibrate and control the ESC with an Arduino Mega 2560. There are three wires on the ESC, brown, red, and orange. The orange wire is connected to pin 9 on the Arduino Mega. The potentiometer is a 50k linear. The following code was uploaded to the Mega. When I run the program the ESC seems to run through the programming mode and ignores changes in the pot reading (high to low).

I viewed a YouTube video that demonstrated the tones used in programming mode for the Hitec ESC. What I noticed is that time between beeps on my ESC are much longer than that on the video. In other words instead of “beep, beep…beep, beep” I hear “beep, beep…beep, beep”.

I do know that the default setting for the battery is LiPo for this ESC, and that an SLA battery should be Nimh, but I don’t know how to change that since I can’t seem to make changes. When I attempt to calibrate the ESC or make changes during programming mode the ESC ignores the response from the potentiometer (high to low).

One question I have is what are other possible values of the Min and Max values for an ESC? I have tried a variety of programs that pretty much do the same thing as the program below, but they have the same result.

Any advice would be most appreciated. Thanks.

#include <Servo.h> //Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc

// These constants won't change. They're used to give names to the pins used:
const int analogInPin = 2;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 13; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
  esc.attach(9); //Specify the esc signal pin,Here as D9
  esc.writeMicroseconds(1000); //initialize the signal to 1000
  Serial.begin(9600);// initialize serial communications at 9600 bps:
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

  int val; //Creating a variable val
  val= analogRead(A2); //Read input from analog pin a0 and store in val
  val= map(val, 0, 1023,1000,2000); //mapping val to minimum and maximum(Change if needed) 
  esc.writeMicroseconds(val); //using val as the signal to esc
  

  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delay(2);
}

Can you give us a wiring diagram? Pencil, paper and a camera are good enough if you include good detail like PIN numbers.

I see that you do print the value of sensorvalue and outputvalue. Why not also print out Val?
Isn’t that what is used to control the esc? What values does it have?

Most esc will require an arming sequence.

ESCs are similar to servos in that they are controlled by a PWM signal with a varying duty cycle. Therefore, you CAN’T use a pot to serve as a controlling input. You can, however, use a pot as an input to the Arduino to set the duty cycle of the controlling PWM signal.

I’ve used many ESCs with Arduino before and all of them have worked perfectly with the servo.h library. Servo.write(0) usually corresponds to no throttle and Servo.write(180) usually corresponds to full throttle, but these limits vary from ESC to ESC.

Does this help?

Hi, Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

A 50K pot is a bit high when it comes to any noise that may be picked up by the Mega analog input, 10K is more the norm but it should work.

Have you got the gnd of the Mega connected to the gnd of the ESC?

Tom.... :)

I apologize for taking so long to reply. I thought I could do the diagram on CAD real quick, but that became another project. Hopefully you can see the attached wiring diagram.

The pot is connected to the Mega with the output connected to pin A2 and the other tabs on the pot to +5V and GND. The signal wire from the ESC is connected to Pin 9 on the Mega, but I did not attach the GND from the ESC to the Mega. I will go back and try that again.

I used a scope to measure the output on pin 9 and I seem to get a pretty clean square wave (although this is the first time I used a scope so how would I know what clean really is) that shows +5V with a pulse width of 1 ms when the pot is rotated all the way counterclockwise and 2 ms when it is rotated all the way clockwise.

Anyway I just wanted to get this posted so nobody would think I was ignoring them. I will try again with the ESC grounded and let you know how it worked. Thanks for the responses thus far.

ESC.jpg

Problem solved.

Connecting the GND of the ESC to the GND of the Mega fixed it. The various examples and videos I was following to get this far used the BEC of the ESC to power the Arduino, so the GND wire was always connected. I used a separate power supply to power the Arduino and never thought that the ESC needed to be grounded for the signal to work.

Thanks to everyone who responded. I have attempted a variety of projects over the years and if it wasn't for the helpful answers to problems like this I never would have gotten off the ground on any of them.

Thanks again. :)