Control the Basic ESC with a Potentiometer and Arduino

By DanielG

Introduction

This guide will show you how to use a potentiometer and an Arduino to control the Basic ESC. It builds from our Basic ESC R3 Example Code for Arduino so if you haven’t already, make sure to check that out first.

Parts and Tools

Main components used in this guide.

Main components used in this guide.

You Will Need

You will also need:

Wire Connections

All the components connected.

All the components connected.

Connecting the Potentiometer

  1. A potentiometer will have 3 pins, the two outer pins will connect to 5V and ground and the center pin will connect to an analog input.
  2. Annotation 2020-02-11 175635
  3. Connect one of the outer pins to 5V on the Arduino using a male to female jumper wire.
  4. Connect the other outer pin on the potentiometer to ground on the Arduino using a male to female jumper wire.
  5. Connect the center pin on the potentiometer to one of the analog in pins on the Arduino using a male to female jumper wire. In this example we’re using pin A0.
Potentiometer connected to the Arduino.

Potentiometer connected to the Arduino.

Connecting the ESC

  1. Connect your thruster to the ESC by matching the green, white, and blue wires from the ESC to the green, white, and blue wires from the thruster.
  2. ESC motor wires to thruster.

    ESC motor wires to thruster.

  3. Connect the white signal wire from the ESC to digital pin 9 using a male to male jumper wire.
  4. Connect the black (ground) wire from the ESC to a ground pin on the Arduino using a male to male jumper wire.
  5. ESC signal wires connected to the Arduino.

    ESC signal wires connected to the Arduino.

  6. Connect the ESC to your power source.

Using the Example Sketch

  1. Connect your Arduino to the computer with the USB cable.
  2. Copy the code from the example sketch into a new sketch in the Arduino IDE.
  3. #include <Servo.h>
    
    byte servoPin = 9; // signal pin for the ESC.
    byte potentiometerPin = A0; // analog input pin for the potentiometer.
    Servo servo;
    
    void setup() {
    servo.attach(servoPin);
    servo.writeMicroseconds(1500); // send "stop" signal to ESC. Also necessary to arm the ESC.
    
    delay(7000); // delay to allow the ESC to recognize the stopped signal.
    }
    
    void loop() {
    
    int potVal = analogRead(potentiometerPin); // read input from potentiometer.
    
    int pwmVal = map(potVal,0, 1023, 1100, 1900); // maps potentiometer values to PWM value.
    
    servo.writeMicroseconds(pwmVal); // Send signal to ESC.
    }
    
  4. Make sure the potentiometer knob is turned to the center position.
  5. Upload the sketch to the Arduino.
  6. That’s it! If everything is working correctly you should hear the ESC arm after a few seconds. You can now control the throttle, forward and reverse, with the potentiometer.
If the thruster is spinning in the wrong direction you can just switch two of the motor wires (blue, green, white wires).

Troubleshooting

  • The ESC doesn’t arm after uploading the sketch:
    • If the Arduino was powered on before the ESC then the ESC might have missed the arming signal. Either restart the Arduino or return the potentiometer to the center position to send the correct arming signal.



Authors

DanielG

DanielG is a Technical Support Specialist at Blue Robotics.