Hi i know about nothing how to program in here, i am bad at grammar bare with me 8D
using an arduino mega 2560
problem start here instead of using a potentiometer i am using a hall effect sensor throttle
like on ebike on pin A0 (with is throttle)
but a hall effect throttle is 1v to 4v instead of the 0v to 5v like a pot do
so there alway some pwoer given to the motor making pwm noise and waste power
probably need a dead zone of some sort ?
what the code do is having a soft acceleration controlled with a pot independent of the throttle asked
like having a super slow acceleration even when you give 100% throttle
it decelerate instantly if the throttle is releashed
included a picture with basic wiring instead of D3 pinout i use D5 pinout i use since i burned the D3 pinout.
the code is taken from a french dude who shared his code to all
i aslo speak french if you need the comment in the code translated i can'T figure out most of what it mean but can try
Thanks for any help
/*potentiometer x2 for motor controller.
Version 1.4, Incroyables Expériences */
void setup() // Boucle d'initialisation.
{
pinMode(5, OUTPUT); // Broche 3 réglée comme sortie numérique.
}
float r=0; // Initialisation du rapport cyclique réel à 0.
float s=30; // Initialisation de la souplesse de conduite.
int a=0; // Initialisation du rapport cyclique demandé à 0.
int b=0; // Initialisation de la mémoire du rapport cyclique demandé.
int c=700; // default 70 safety if the throttle is floored too fast
void loop() { // Boucle principale
analogWrite(5,r/1023*254); // Création du PWM.
a=analogRead(0); // Lecture du rapport cyclique demandé.
s=analogRead(1); // Lecture de la souplesse de conduite demandée.
if(a>b+c){ // Vérification d'une accélération trop brutale (d'origine volontaire ou non).
digitalWrite(5,LOW); // Arrêt immédiat du moteur.
while(a>c){ // Attente d'un rapport cyclique très faible pour redémarrer.
a=analogRead(0); // Lecture continue du rapport cyclique demandé.
}
}
b=a; // Mémorisation du rapport cyclique demandé.
if(a>r){ // Vérification de la croissance du rapport cyclique demandé.
delay(20); // Délai responsable de la souplesse de conduite.
r=r+s/20+2; // Calibrage empirique de la souplesse de conduite.
}
if(a<r){ // Vérification de la décroissance du rapport cyclique demandé.
r=a; // Diminution immédiate du rapport cyclique réel le cas échéant.
}
}