0

I have 2 ESC (electronic speed controller) which control these brushless motors: Hobbyking Donkey ST3511 Brushless Motor

I would like to make them work with a poentiometer, under arduino.

I have a program but it only works with one engine. Here is the program :

#include <Servo.h>//Using servo library to control ESC
Servo esc;
Servo esc2;
//Creating a servo class with name as esc
void setup()
{
esc.attach(9); //Specify the esc signal pin,Here as D8
esc.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
esc2.attach(9); //Specify the esc signal pin,Here as D8
esc2.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
}
void loop()
{
int val; //Creating a variable val
val= analogRead(A0); //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
esc2.writeMicroseconds(val);
}

I did not find help on the internet, thank you in advance.

chrisl
16.6k2 gold badges18 silver badges27 bronze badges
asked Mar 26, 2019 at 9:27
4
  • 1
    In your code you are attaching both esc objects to the same pin ( pin 9 ). That cannot be, what you indented. Use two different pins. Commented Mar 26, 2019 at 10:16
  • Oh, and you are beginning the Serial interface also twice. CopyPaste problem? Commented Mar 26, 2019 at 11:50
  • I'd say yes, it's a copy-paste problem as in the OP just duplicated the code without understanding what needs to be changed. Commented Mar 26, 2019 at 13:05
  • You need to assign 2 different hardware pins to your two different speed controllers. Do you want one pot (potentiometer) to control both motors, or a separate pot for each motor? Commented Mar 26, 2019 at 13:06

1 Answer 1

1

If you want one potentiometer to handle BOTH ESCs' speed, you could use this code:

//Using servo library to control ESC
#include <Servo.h>
//Starting the servos
Servo esc1;
Servo esc2;
void setup() {
 esc1.attach(9); // Use a PWM pin to the Servo, in this case 9
 esc1.writeMicroseconds(1000); //initialize the signal to 1000
 esc2.attach(10); // Pick another PWM to the other, in this case 10
 esc2.writeMicroseconds(1000); //initialize the signal to 1000
 Serial.begin(9600);
}
void loop() {
 int val; //Creating a variable val
 val= analogRead(A0); //Read input from analog pin a0 and store in val
 val= map(val, 0, 1023,1000,2000); //mapping val to minimum and maximum(analogRead's goes from 0-1023 and analogWrite's goes from 0-255, check your servo's specs)
 esc1.writeMicroseconds(val); // write to the first ESC
 esc2.writeMicroseconds(val); // write to the second ESC
 delay(100); // We usually set a small delay to avoid excessive readings or over-heating, but thats optional...
}

If you need to use two potentiometers, one for each ESC, then you would have to start another variable to read the 2nd pot value and use it to write on the 2nd ESC, simple as that! :)

answered Mar 26, 2019 at 13:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.