Fix joystick for BLDC

I have a BLDC motor with an ESC controlled by a joystick connected to the Arduino. The motor wants to run when the joystick is in the off position. I have to jingle the stick to get it to shut off and sometimes it just comes back on. It does the same with other joysticks, how can I make it less sensitive, or adjust the code so that the off position is bigger in both directions?

#include <Servo.h> //Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc
void setup()
{
esc.attach(7); //Specify the esc signal pin,Here as D7
esc.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
}

What are the actual values you are getting for "val"? You have looked at them, haven't you?
Paul

Maybe where whoever wrote the code sez “Change if needed”.

Try mapping from 700 to 2300. This shoukd result in a range at the bottom where you motor will be off and a range at the top where it has reached maximum speed even before you reach the joystick end of travel.

Experiment with that range to get the effect you want.

You could akso test if the joystick is below a certain point and write one low value for all that section, a value where the motor will be off, forming a dead band.

a7

Well that doesn't work, if I change that no. to 700 it only goes in one direction and is off all the other direction I tried changing the 1000 and 2000 values, same thing. I don't know what values I should have.

It's not a single task. There are two.

  1. Check the values you get from your joystick. Forget the motor at this point. Do a continuous serial print while you twist the stick.

Ok, now you know how your joystick behaves.

  1. Check how your motor behaves to different values. Forget the joystick. Just output values to the motor, same values to the serial console.

Ok, now you should know how to map everything. How big range of joystick values do you need for the off position? After that you do mappings for each direction.

I meant change the output range of map from 1000, 2000 to 700, 2300. The input range should remain 0, 1023.

I'd you tried that and it did not work, I am out of an idea. Try sending single values to the ESC with this like

esc.writeMicroseconds(1000);

to see where it responds. 1000 - 2000 range is plausible for a start.

Also, is there a calibration procedure for your ESC? It may be necessary to (re)calibrate it.

What is the make news model,of you ESC?

a7

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