Arduino ESC brushless motor control through buttons??

as a beginner i am trying to control a brushless motor through arduino by using buttons, is this code correct?

button pressed spinning motor, button not pressed not moving

# include <Servo.h> 
Servo m1;
int pushButton = 2;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(pushButton,2);
m1.attach(6);
delay(1);
m1.write(40); 

}

void loop() {https://forum.arduino.cc/
  // put your main code here, to run repeatedly:
int buttonState = digitalRead(pushButton);
Serial.println(buttonState);
delay(1);
m1.write(80);


}
pinMode(pushButton,2);

That's right but I don't know if it is for the reason you think. What did you mean the 2 to represent here? The pin number? Or the constant INPUT_PULLUP?

void loop() {https://forum.arduino.cc/
  // put your main code here, to run repeatedly:
int buttonState = digitalRead(pushButton);
Serial.println(buttonState);
delay(1);
m1.write(80);


}

You've got a comment hanging out on the first line here without being commented. That's going to throw an error. You read the button, that part is ok. You print the state and that's ok. And then you write 80 to the ESC regardless of what was going on with the button. To get what you describe in your post I would expect to see at least one if statement in there.

Take a look at the Button example. From the Arduino IDE:
File -> Examples -> Digital -> Button

better?

# include <Servo.h> 
Servo m1;
int pushButton = 2;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(pushButton,2);
m1.attach(6);
delay(1);
m1.write(40); 

}

void loop() {https://forum.arduino.cc/
  // put your main code here, to run repeatedly:
int buttonState = digitalRead(pushButton);
Serial.println(buttonState);
delay(1);
 if (buttonState == HIGH) {
m1.write(80, HIGH);
  } else {
m1.write(40, LOW);
  }
}

Why are you putting HIGH and LOW in the write commands for the motor? Where have you seen one written like that?

Hi,
What are the specs/data of your ESC?

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

We need to see how you have connected everything.

Thanks.. Tom... :slight_smile:

its just regular Brushless ESC, http://www.e-fliterc.com/Products/Default.aspx?ProdID=EFLA1060B

high and low they are the state of the button, high button pressed, and low button not pressed,

# include <Servo.h> 
Servo m1;
int pushButton = 2;
int pos = 0;    

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(pushButton, INPUT);
m1.attach(6);
delay(1);
m1.write(40); 

}

void loop() {https://forum.arduino.cc/
  // put your main code here, to run repeatedly:
    if (digitalRead(pushButton) == HIGH) { //Opens the door when the 'open' button is pressed
 m1.attach(9);                     //Gives the servo power
 m1.write(70);                    //Tells servo to move to 0 degree mark
    delay(1000);                       // waits 1000ms for the servo to reach the position

  }
  }

thank you, its working now, next step to use HC-05 rx tx, made on slave and one master, looking through it atm

# include <Servo.h> 
Servo m1;
int pushButton = 2;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
m1.attach(6);
delay(1);
m1.write(40); 
pinMode(pushButton, INPUT);
}

void loop() {https://forum.arduino.cc/
  // put your main code here, to run repeatedly:
    if (digitalRead(pushButton) == HIGH > LOW) { //Opens the door when the 'open' button is pressed
 m1.attach(6);                     //Gives the servo power
 m1.write(90);                    //Tells servo to move to 0 degree mark
    delay(1);                       // waits 1000ms for the servo to reach the position
  } else {
    m1.write(40);
    delay(1);
  }
  }