Brushless motor keeps beeping -

Hello everyone, I have a question regarding my program in arduino. I have to control ESC by arduino, I need only to run up the motor to the certain power and then go to 0 again. I made the program below but when I connect arduino into ESC, ESC starts beeping quickly, which means according to the manual that the throttle is not set to minimum. I tried to set the throttle to minimum by arming process in my program however it is not probably correct. I´m very beginner with arduino and this is my first project, so I´m sorry for possible stupid mistakes in my program.
Thanks in advance,
Pavel

#include <Servo.h>;
Servo ESC;

int pos = 0; //Sets position variable

void arm(){

setSpeed(0); //Sets speed variable delay(1000);

}

void setSpeed(int speed){

int angle = map(speed, 0, 100, 0, 180); //Sets servo positions to different speeds ESC1.write(angle);

}

void setup() {

ESC.attach(3); //Adds ESC to D3 pin. arm();

}

void loop() {

int speed; //Implements speed variable

for(speed = 0; speed <= 50; speed += 5) { //Cycles speed up to 50% power for 1 second

setSpeed(speed); //Creates variable for speed to be used in in for loop

delay(1000);

}

delay(4000); //Stays on for 4 seconds

for(speed = 50; speed > 0; speed -= 5) { // Cycles speed down to 0% power for 1 second

setSpeed(speed); delay(1000);

}

setSpeed(0); //Sets speed variable to zero no matter what

delay(1000); //Turns off for 1 second

}

A few items. Unnecessary white space (like your extra blank lines) and no formatting make your code hard to read.
I loaded your sketch (thank you for proper use of code tags), formatted it (CTRL-T) and removed the extra lines.
Don’t you agree that this is easier to read?

#include <Servo.h>;
Servo ESC;

int pos = 0; //Sets position variable

void arm() {
  setSpeed(0); //Sets speed variable delay(1000);
}

void setSpeed(int speed) {
  int angle = map(speed, 0, 100, 0, 180); //Sets servo positions to different speeds ESC1.write(angle);
}

void setup() {
  ESC.attach(3); //Adds ESC to D3 pin. arm();
}

void loop() {
  int speed; //Implements speed variable
  for (speed = 0; speed <= 50; speed += 5) { //Cycles speed up to 50% power for 1 second
    setSpeed(speed); //Creates variable for speed to be used in in for loop
    delay(1000);
  }
  delay(4000); //Stays on for 4 seconds
  for (speed = 50; speed > 0; speed -= 5) { // Cycles speed down to 0% power for 1 second
    setSpeed(speed); delay(1000);
  }
  setSpeed(0); //Sets speed variable to zero no matter what
  delay(1000); //Turns off for 1 second
}

Now, you see that you have an arm function. But I cannot find it being called.
Consider calling it in the setup.
Also, many ESCs require some delay at zero throttle to arm.
Consider putting in a small delay (one second?) after you set the speed to zero.

Putting the delay(1000) in the arm() routine (instead of it just being in a comment) should fix the arming.

  for (speed = 0; speed <= 50; speed += 5) { //Cycles speed up to 50% power for 1 second
    setSpeed(speed); //Creates variable for speed to be used in in for loop
    delay(1000);

But then with the delay(1000) in your for loops it waits 1 second between each +/-5 move…so takes 10 seconds to get to 50% or back to 0%. The comment is a bit misleading.

Also you keep setting the variable ‘speed’ but you never write it or anything else to the ESC so there’s definitely still some work to do.

Steve

Thank you for the advices, it´s working as I need now.
Working code below

#include <Servo.h>;
Servo ESC;
int pos = 0; //Sets position variable
int speed; //Implements speed variable

void arm(){
setSpeed(0); //Sets speed variable
delay(2000);
}

void setSpeed(int speed){
int angle = map(speed, 0, 100, 0, 180); //Sets servo positions to different speeds 
ESC.write(angle);
}

void setup() {
ESC.attach(3); //Adds ESC to D3 pin. 
arm();
}

void loop() {
int speed; //Implements speed variable
for(speed = 0; speed <= 50; speed += 5) { //Cycles speed up to 50% power for 1 second each step
setSpeed(speed); //Creates variable for speed to be used in in for loop
delay(1000);
}

delay(4000); //Stays on for 4 seconds
for(speed = 50; speed > 0; speed -= 5) { // Cycles speed down to 0% power for 1 second
setSpeed(speed); 
delay(1000);
}

setSpeed(0); //Sets speed variable to zero no matter what
delay(1000); //Turns off for 1 second
}

Still not indenting your code?

Hi #MarkT,

I’m having an interesting problem after the fan shuts off with the above code.

I’m trying to delay the start for 1 minute on and 1 minute off etc.

but, when its on 1 minute off, the motor “beeps” every 2 to 4 secs.
I need silent for the 1 minute.

Once this works, the total fan run time is for 1 hour on and 2 hours off each day.
cheers Jason

My sketch is:

const long oneSecond = 1000; // a second is a thousand milliseconds
const long oneMinute = oneSecond * 60;
const long threeMinute = oneMinute * 3;
const long oneHour = oneMinute * 60;
const long twoHour = oneHour * 2;
const long threeHour = oneHour * 3;

int sensorPin = A0; // select the input pin for LDR//
int sensorValue = 0; // variable to store the value coming from the senso

#include <Servo.h>;

Servo ESC;
int pos = 0; //Sets position variable
int speed; //Implements speed variable

void arm(){
setSpeed(0); //Sets speed variable
delay(2000);
}

void setSpeed(int speed){
int angle = map(speed, 0, 100, 0, 180); //Sets servo positions to different speeds
ESC.write(angle);
}

void setup() {
ESC.attach(9); //Adds ESC to D9 pin.
arm();
}

void loop() {
int speed; //Implements speed variable
for(speed = 0; speed <= 40; speed += 5) { //Cycles speed up to 50% power for 1 second each step
setSpeed(speed); //Creates variable for speed to be used in in for loop
delay(1000);
}

delay(oneMinute); //Stays on for 1 minute
for(speed = 40; speed > 0; speed -= 5) { // Cycles speed down to 0% power for 1 second
setSpeed(speed);
delay(1000);
}

setSpeed(0); //Sets speed variable to zero no matter what
delay(1000); //Turns off for 1 sec

}

The ESC beeps the motor, to show its still armed. This is a safety feature to prevent injury, I doubt it can
be prevented.