Arduino ESC brushless motor control with multiple buttons

I am a beginner working on a design project, I am trying to use 3 buttons to control a brushless motor via ESCs (2 motors, 2 ESCs). The code is supposed to start with sending a stop signal (1500 μs) to the motors and then via 2 different buttons, one increases the signal by 100 μs and the other decreases it by 100 μs. With caps at 1900 μs and 1100 μs. I used these motors, https://bluerobotics.com/learn/thruster-usage-guide/
using their exact specifications for the ESC control, however, it doesn't work, which I believe to be the code.
Any tips?

// Include the Servo library
#include <Servo.h>

// Define the pins for the buttons and motors
#define BUTTON1_PIN 2
#define BUTTON2_PIN 3
#define BUTTON3_PIN 7
#define MOTOR1_PIN 4
#define MOTOR2_PIN 5

// Define the initial values for the motors and escs
int motor1_value = 1500;
int motor2_value = 1500;

// Create servo objects for the motors
Servo motor1;
Servo motor2;

// Setup function
void setup() {
 // Attach the motors to their respective pins
 motor1.attach(MOTOR1_PIN);
 motor2.attach(MOTOR2_PIN);
 pinMode(LED_BUILTIN, OUTPUT);

 // Set the initial positions for the motors
 motor1.writeMicroseconds(motor1_value);
 motor2.writeMicroseconds(motor2_value);

 // Set the button pins as inputs
 pinMode(BUTTON1_PIN, INPUT_PULLUP);
 pinMode(BUTTON2_PIN, INPUT_PULLUP);
 pinMode(BUTTON3_PIN, INPUT_PULLUP);
  //Set serial comms
 Serial.begin(9600);

}

// Loop function
void loop() {
 // Read the state of the buttons
 int button1_state = digitalRead(BUTTON1_PIN);
 int button2_state = digitalRead(BUTTON2_PIN);
 int button3_state = digitalRead(BUTTON3_PIN);

 // Check if button 1 is pressed (Up Power)
 if (button1_state == LOW) {
   // Increase the motor values by 100
   motor1_value += 100;
   motor2_value += 100;
   digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
   delay(250);
 
   // Check if the motor values are greater than 1900
   if (motor1_value > 1900) {
     // Set the motor values to 1900
     motor1_value = 1900;
     motor2_value = 1900;    
   }
 
   if (motor1_value < 1100) {
     motor1_value = 1100;
     motor2_value = 1100;
   }

   // Write the new motor values to the motor
   motor1.writeMicroseconds(motor1_value);
   motor2.writeMicroseconds(motor2_value);
   
 }

 // Check if button 2 is pressed (Down Power)
 if (button2_state == LOW) {
   // Decrease the motor values by 100
   motor2_value -= 100;
   motor1_value -= 100;
   digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
   delay(250);

   // Check if the motor values are greater than 1900
   if (motor1_value > 1900) {
     // Set the motor values to 1900
     motor2_value = 1900;
     motor1_value = 1900;
   }
 
   if (motor1_value < 1100) {
     motor1_value = 1100;
     motor2_value = 1100;
   
   }
 
   // Write the new motor values to the motor
   motor2.writeMicroseconds(motor2_value);
   motor1.writeMicroseconds(motor1_value);
   
 }

 // Set motors too off
 if (button3_state == LOW) {
 
   motor1_value = 1500;
   motor2_value = 1500;
   digitalWrite(LED_BUILTIN, HIGH);
 }
   motor1.writeMicroseconds(motor1_value);
   motor2.writeMicroseconds(motor2_value);
   digitalWrite(LED_BUILTIN, LOW);
   Serial.print("motor 1 ");
   Serial.println(motor1_value);
   Serial.print("motor 2 ");
   Serial.println(motor2_value);
}

Welcome to the forum

That is a very lame description. More details are needed and a schematic of your project would be helpful. How are the motors powered ?

The motors are powered via an external battery, 12V 17A. From the manufacturer's website about how to connect it to ESC it receives the 3 beeps when connected to power and then another 2 beeps when it receives the signal wire, I assume at 1500 μs. Which means the motor is initialized.
Here is an image of the setup currently.
The 2 wires on the right that are not connected to anything go to the battery and at the bottom ESC is connected to the motor.
For testing the Arduino is connected to the USB cable for power


Let me know if this is more helpful.

Which exact thruster are you using?

Which exact ESC are you pairing with each thruster? Have you configured and calibrated them?

a7

I am using the T200 thrusters, and i followed these guidelines for configuring the ESCs,

" 3. Sending the Signal
Connect the white ESC signal wire to the signal source output. Connect the black (ground) ESC wire to a ground pin on the signal source device. Send a PWM signal of 1500 microseconds (µs) to initialize the ESC. The ESC must be initialized before it can accept any other throttle signals. When the ESC is initialized you should hear two more beeps. The first beep indicates the ESC detects a throttle signal and the second beep indicates that the correct 1500 µs signal is detected and the ESC is now fully initialized."

and these are the ESCs,
https://a.co/d/fG8vSCH

I am pretty sure they have the same firmware as what the thrusters need, blheli_s

And I am "pretty sure" that out of the box, these ESCs are not configured for bidirectional control.

The firmware on them may not even be configurable for bidirectional control.

But they are BLHeli_S, which means you can use the BLHeli configurator to see and change firmware settings, and also flash up to a later firmware version if necessary.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.