ESC with Arduino MEGA HELP!!

Hi there everyone,

I am a starter with arduino and I am now doing my Final Year Project. I was given by my teacher 2 ESC from hobbywing that are 10A, and 2300Kv brushless motor and he wanted me to get this running on the arduino. I have read many many articles on how to set this up. Like using the servo.lib which I have installed. I read the user guide about the ESC and it said that there is several beeping song that indicate different things. I have actually tested up and my ESC beeping sounded like this. When I power and upload the code that i have written, it went with a special tone 123 then two beep beep sound followed by one long beep. Then when I press the push button the motor started running at the desired PWM that i have set in microsecond. My question here is that the sequence of the beeping sound that I have encounter it is means that the ESC have been armed that make my motor successfully run?

If not, is there any way i could write the code? as I am still unsure of the reason why we have to the number 1000 as low and 2000 as high in PWM (microsecond)? it is always like that? it will mean alot to me if someone could explain to me regarding this

Sorry if I asked some dumb question here as I am totally new to this platform and am really interested in making this project work. Much help appreciated from you all!

Thank you!

1000 microseconds denotes the shortest typical RC pulse,, and 2000 the longest.
These are repeated at 50Hz, so a very low duty cycle of 5 to 10%

My question here is that the sequence of the beeping sound that I have encounter it is means that the ESC have been armed that make my motor successfully run?

If you have used the arming sequence described in the manual for the ESC and it is doing what you want then it sounds like you have got it right. It is actually the brushless motor that is making the noise and the manual for the ECS should describe what the beep sequence means. How are you powering the motor and ESC ?

I am still unsure of the reason why we have to the number 1000 as low and 2000 as high in PWM (microsecond)? it is always like that?

As you did not post your code I will assume that you are using the Servo library and the writeMicroseconds() function. RC servos and ESCs are controlled using a pulse width of between 1000 and 2000 microseconds which give a movement for a servo between one extreme and the other and for ESCs between minimum and maximum speed

If you require more help then you need to post your code and describe any problems that you are having.

Thank you for the fast response!!

I am currently using power supply unit of 7.4v to power the motor and ESC while waiting for my actual battery to arrive. Because I was suggested to use the min voltage instead of the lipo 11.1V one ( is there any differences in using different rated voltage?)

Yes, I am using Servo.lib and also the Microsecond Function. My problem now is that, I showed my progress work to my teacher and he checked on my coding and asked me why I used the microsecond function and why value of 1000 and 2000 i explained to him what i have read online but he didn't seem to get it (was told it was his first time experiencing with ESC too) and told me i just can't take value from what the online said signn.... so now i am just trying to figure out if i am setting up my ESC and brushless motor correctly.

Also, does all ESC require arming? what is arming actually for? still confused as from some articles i read doesn't require arm. if so, how do you code to arm your ESC to the motor?

Arming is for safety, so the props don't start spinning until you want them to.

Arming is a process whereby a certain sequence of commands have to be sent to the ESC before it will supply power to the motor. This, as AWOL says, is a safety measure. Imagine what might happen if the ESC unexpectedly supplied full power to the motor as soon as the battery was connected. Not all ESCs may require arming or it may be possible to disable it. The manual should give you details.

I hope that the explanations of the 1000 to 2000 microsecond range used with writeMicroseconds() will be good enough for you to explain to your teacher.

Thank you so much UKHeliBob and AWOL for your detailed explanation that cleared my doubts and allow me to understand more! Much appreciated !

Now i am more eager to make this project work! is so interesting !

One more question,

I have an idea to control the speed of my motor using 3 different push button, where 1 pushbutton will increase the speed of the motor by 100 in microsecond from the desired speed i have input and another pushbutton will decrease by 100 in microsecond from the previous speed and last pushbutton will just cut the motor whenever needed.

i got the idea of writing in the if, else if, else format but i am not sure how i can write it in that, could you show me a preferred format that i can write together with the servo.lib and i can learn it myself from there

Thank you so much!

Use the StateChange example to explore a bit more about how a button works. The digitalRead() function tells you if the button is currently being pressed and you need to add some code to detect when it changed from not being pressed to pressed.

You should also look up "debounce".

Okay noted i will take a look at what you suggested! Thank you so much!

I just happen to come across this site Arduino Incremental Motor Speed Control | Flying Fast With Quadcopter Source

Is it possible that i can somewhat follow with the link format and write what i want to achieve together with servo.lib?

Is it possible that i can somewhat follow with the link format and write what i want to achieve together with servo.lib?

You can certainly do what you want using the Servo library and by all means look at how other people have done something similar. From observation here, unless you understand how someone else's code works you will end up in a mess when you try to change it.

Better, I think, to write your own code but don't try to do it all at once. Use the principle shown in the StateChangeDetection example to read the inputs, add debouncing then add changing the value of a variable when a debounced change of state has been detected. You don't even need to drive the ESC up to that point. Then add the ESC code to the program and use the value of the variable to control its speed.

was wondering if i should put some delay somewhere when it is changing to the next speed

Why would you do that ? Surely you want the speed to increase or decrease as soon as the button becomes pressed rather than wait a while.

i was wondering if i can increment and decrement the speed at the same time

What ?
Suppose that you were walking along and someone shouted "walk faster" at the same time as someone else shouted "walk slower", what would you do ?

How do you want the code to work ?
Should other button presses be ignored whilst a button is held down or should the program read and respond to any button press regardless of the state of other button inputs ? Or maybe the "stop" input should override all other inputs whatever their state.

Before you can implement code for any of this you need to decide on the specification of what you are trying to do. Your original post mentioned 2 ESCs. Are you going to control both of them independently with the program or only one of them ?

what do you mean by this sentence?

What I meant was that you could test all of the logic of your program using output to the Serial monitor telling you what is going on. You don't need to connect an ESC or even have any explicit code to control it.

Why would you do that ? Surely you want the speed to increase or decrease as soon as the button becomes pressed rather than wait a while.

oh, i just tot that this may help in not damaging the motor from changing speed from one to another. Maybe i misunderstood the use of delays but thank you for pointing that out to me!

What ?
Suppose that you were walking along and someone shouted "walk faster" at the same time as someone else shouted "walk slower", what would you do ?

How do you want the code to work ?
Should other button presses be ignored whilst a button is held down or should the program read and respond to any button press regardless of the state of other button inputs ? Or maybe the "stop" input should override all other inputs whatever their state.

Before you can implement code for any of this you need to decide on the specification of what you are trying to do. Your original post mentioned 2 ESCs. Are you going to control both of them independently with the program or only one of them ?

sorry i think i should not phrase the sentence this way, pardon me. what i actually meant is that i have an idea of controlling my motor with 3 buttons,
so 1st button will focus on increasing the speed of the motor (let say from 1200us to 1300us so on) with one press,
2nd button will focus on decreasing the speed of the motor (let say from 1300us to 1200us) with one press and 3rd button will just brake/stop the motor from working.

so if we put this in an users environment: when one is to use this system, they can control the desired speed they want just by using the push button. (sorry if my idea sound impossible :confused: )

I am focusing on one motor now once i am familar with arduino i will bring another motor in

What I meant was that you could test all of the logic of your program using output to the Serial monitor telling you what is going on. You don't need to connect an ESC or even have any explicit code to control it.

oh so meaning we can test run the code using the serial motor without actually running it with the motor?wow i didn't know that, Arduino sure can do lots! thanks for the information!

ps; sorry if i sounded really dumb in the questions i ask, it must be a hard time answering question from people like me. But i really appreciate your constant reply and help!

1st button will focus on increasing the speed of the motor (let say from 1200us to 1300us so on) with one press,
2nd button will focus on decreasing the speed of the motor (let say from 1300us to 1200us) with one press and 3rd button will just brake/stop the motor from working.

so if we put this in an users environment: when one is to use this system, they can control the desired speed they want just by using the push button. (sorry if my idea sound impossible :confused: )

This is just the sort of thing that the Arduino is good at so it is perfectly possible. As you are using the Servo library the use of other libraries is presumably allowed. If so, then look at the Button2 library GitHub - LennartHennigs/Button2: Arduino/ESP button library that provides callback functions to track single, double, triple and long clicks. It also takes care of debouncing.
It would make reading the 3 buttons very easy.

I am focusing on one motor now once i am familar with arduino i will bring another motor in

Keep in mind the fact that you will be adding a second motor and presumably a second set of controls. Give variables suitable names that can be reused for a second ESC etc and think ahead as to whether you could use arrays and functions to make the code neater without repeating code.