I'm makeing an tachometer-like device.
The exact RPM is not needed.
The only mission of that device is to turn on LED when rpm is 0 and off when it isn't
As a sensor i use A3144 Hall effect sensor
Everything works fine but with one error:
If the magnet is stopped in front of the hall sensor (the sensor pin is pulled to LOW) there is no change on the sensor pin and my nano does not light the LED Up!
Hope that it's not hard to understand me.
How can i fix this in my code?
int hallPin = 2; // A3144 sensori signaali pin
int ledPin = 13; // LED-i pin
int ledPin2 = 12; // Nanol ei ole pin 13, vaid füüsiline led
//siia on vaja joota armatuurlaua led
void setup() {
pinMode(hallPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int rpm = getRPM();
if (rpm == 0) {
digitalWrite(ledPin, HIGH);
} else if (rpm > 50) {
digitalWrite(ledPin, LOW);
}
}
int getRPM() {
int count = 0;
unsigned long startTime = millis();
while (millis() - startTime < 100) {
if (digitalRead(hallPin) == LOW) {
count++;
}
}
int rpm = count * 600 / 7.5;
return rpm;
}```