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
}
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.
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.
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.
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.