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 it will run if I just barely touch it. It does the same with other joysticks, how can I make it less sensitive, adjust the code so that the off position is bigger in both directions?
Code:
#include <Servo.h> //Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc
void setup()
{
esc.attach(9); //Specify the esc signal pin,Here as D9
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
}