Hi i have a working ebike speedo that i can control with a motor speed control sketch
and i aslo have a hertz to rpm sketch ready
Thanks for any help you can give me
Disclaimer i am still a beginner i have lot to learn
i would like to know how to convert this signal into action on the speedo
when i give these signal to the speedo it = that on the speedo
254-255 = 35km/h
217-218 = 30km/h
187-188 = 25km/h
146-147 = 20km/h
126-127 = 15km/h
87-88 = 10km/h
59-60 = 5km/h
additional info
Arduino uno r3 with atmega328p the non SMD variant
Hall Effect Sensor 3144 was used
my electric scooter is capable of 35km/h when the wheel spin in the air for a total RPM(730-735)wich = 35km/h ish with calculator
i will be using 2 magnet on the wheel maybe 4 in the future
my plan if no help given
i will use alot of IF argument for each km/h with is inefficient for my taste hehe
motor sketch i used for the speedo testing
i will aslo merge the rpm sometime
/* PWM pour moteur à courant continu avec réglage de la souplesse de conduite (2 potentiomètres).
Version 1.4, Incroyables Expériences */
/*its now in v1.7 from buder :D*/
#include <PWM.h>
float THRint =0; //THRint requested throttle when thumb removed from throttle // Initialisation du rapport cyclique réel à 0.
float ACCpot=30; //before was (S) base Accel Initialisation // Initialisation de la souplesse de conduite.
int THRpot=0; //Throttle poteniometer // Initialisation du rapport cyclique demandé à 0.
int THRmem=0; //THRmem // Initialisation de la mémoire du rapport cyclique demandé.
int Safety=700; // default 70 safety if the throttle is floored too fast increase number to disable/lower the safety sensibility (at 700 is clearly disabled)
int32_t frequency= 32000;
int Motor = 9; //THRout is throttle to connect to transistor/driver/led/ebike controller
void setup() //setup loop // Boucle d'initialisation.
{
Serial.begin(9600);
InitTimersSafe();
pinMode(Motor, OUTPUT); // pin5 set as THRout (throttle out)
}
void loop() { // main loop // Boucle principale
int insideTHR = constrain(map(THRint, 110, 1200, -22, 340), 0,255); //custom hall effect sensor range and output value for use with system(can't explain each number so fiddle with it it adjust the input range from the hall sensor and the output to the internal code) // int analogOutputValue = constrain(map(THRint, 110, 980, 0, 340), 0,255);
/*analogWrite(5,r/1023*254); // Création du PWM.*/
/* analogWrite(THRout, insideTHR); //writing to pin 5 the throttle sent to a ebike controller or motor driver */
THRpot=analogRead(A0); //throttle pot reading // Lecture du rapport cyclique demandé.
ACCpot=analogRead(A1); //acceleration threshold pot reading // Lecture de la souplesse de conduite demandée.
if(THRpot>THRmem+Safety){ //check for brutale THRpot request (aka flooring the throttle too fast) // Vérification d'une accélération trop brutale (d'origine volontaire ou non).
digitalWrite(Motor,LOW); //imediatly stop if THRout above Safety // Arrêt immédiat du moteur.
while(THRpot>Safety){ //waiting for THRpot to be lower than safety to restart // Attente d'un rapport cyclique très faible pour redémarrer.
THRpot=analogRead(0); // Lecture continue du rapport cyclique demandé.
}
}
THRmem=THRpot; // Mémorisation du rapport cyclique demandé.
if(THRpot>THRint){ // Vérification de la croissance du rapport cyclique demandé.
delay(20); // Délai responsable de la souplesse de conduite.
THRint=THRint+ACCpot/20+2; // Calibrage empirique de la souplesse de conduite.
}
if(THRpot<THRint){ //checking if you removed your thumb from the throttle // Vérification de la décroissance du rapport cyclique demandé.
THRint=THRpot; //stop power being sent if above true(aka thumb removed from throttle) // Diminution immédiate du rapport cyclique réel le cas échéant.
}
Serial.println(insideTHR);
SetPinFrequencySafe(Motor, frequency); //set frequency and speed
pwmWrite(Motor, insideTHR);
}
Hertz to RPM sketch
i didn't make it i just added the part that make hertz to rpm readable for me
/*
* Frequency Measurement Using Arduino
* Inpout is given to Pin 2
* Uses Interrupt to get pulse duration
* F = 1 / pulse duration
*/
#define MainPeriod 100
long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;
void setup()
{
Serial.begin(9600);
attachInterrupt(0, myinthandler, RISING);
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= MainPeriod)
{
previousMillis = currentMillis;
// need to bufferize to avoid glitches
unsigned long _duration = duration;
unsigned long _pulsecount = pulsecount;
duration = 0; // clear counters
pulsecount = 0;
float Freq = 1e6 / float(_duration); //Duration is in uSecond so it is 1e6 / T
Freq *= _pulsecount; // calculate F
// output time and frequency data to RS232
Serial.print(" Frequency: ");
Serial.print(Freq);
Serial.println("Hz");
int RPMmulti = Freq*30;
Serial.print("RPM: ");
Serial.print(RPMmulti);
}
}
void myinthandler() // interrupt handler
{
unsigned long currentMicros = micros();
duration += currentMicros - previousMicros;
previousMicros = currentMicros;
pulsecount++;
}
for the speedo in action controlled with the motor sketch