le capteur est basé sur un capteur magnetic KMZ10A, ci joint le lien pour la datasheet :
http://www.dz863.com/datasheet-817149763-KMZ10A_Magnetic-Field-Sensor/le code que j'utilise :
unsigned long timeold ; // variable temps
volatile byte rpmcount; // variable rpmcount
unsigned int rpm; // variable rpm
void setup(){
attachInterrupt(0, rpm_fun, RISING);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop(){
// Tachymetre
if (rpmcount >= 20 ){
rpm = 60*1000 / (millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
}
if (startVal == 1){
if (rpm < 4000){
analogWrite (motorPin, motorVal_1);
motorState = 1;
}
else if (rpm >= 4000){
analogWrite (motorPin, motorVal_2);
motorState = 2;
}
else if (rpm >= 8000){
analogWrite (motorPin, motorVal_3);
motorState = 3;
}
}
// Fonction RPM
void rpm_fun() {
rpmcount++; //Each rotation, this interrupt function is run twice
}