Hello, this is my first arduino program. I would like to detect the cessation of a piece of rotating machinery (~1 Hz rate), and turn on a led+buzzer when it stops rotating. The goal is to draw attention to the fact the machine is no longer rotating, which periodically happens throughout the day at unexpected intervals. Normal operation is that the machine is rotating and nothing needs to be done by the program.
My first thought was to put a magnet on the rotating flange, and mount a Hall effect sensor nearby. During normal operation, a magnet periodically passes the sensor, and the LED+buzzer is given repeated instructions to remain LOW. If the machine is no longer rotating and no falling edges are detected after a set amount of time, the default program operation is to set the LED+buzzer HIGH. If noting is happening/detected, the LED+buzzer should default to HIGH.
I'm not sure if this is the best logic to use here, so if you have other suggestions for Hall logic, or maybe an easier sensor to use (acoustic?), I'm all ears.
My issue seems to be that the program roughly works as intended, but is unexpectedly turning the LED+buzzer pair HIGH periodically even when I pass a magnet by the Hall sensor at 1 Hz. I suspect my code is not working the way I intended it to, or maybe the sensor has a very slow "reset" time which won't allow it to continue receiving pulses quickly enough (~1 Hz)? Or something else? Any help is appreciated.
EDIT #2: The pinout below has some incorrect pins, this one may be more accurate from arduino.cc: https://content.arduino.cc/assets/Pinout-Micro_latest.png
-Board: micro (some bad pin data)
-Sensor: Gikfun A3144 (Amazon)
-Sensor configuration as shown here (only with 10 µF because I don't have 0.1 µF lying around)
-Digital pin 0 = LED+piezo-buzzer to ground
-Digital pin 3 = INT#1 looking at Hall sensor output pin
int outputState = HIGH;
void setup() {
// put your setup code here, to run once:
//pin 0 is LED/buzzer
pinMode(0, OUTPUT);
//pin 3 is INT#1
pinMode(3, INPUT);
//look for interrupt on INT#1 (pin 3)
attachInterrupt(1, pin_ISR, FALLING);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (outputState == HIGH) {
digitalWrite(0, HIGH);
} else {
digitalWrite(0, LOW);
delay(2000);
digitalWrite(0, HIGH);
delay(2000);
}
}
void pin_ISR() {
outputState = LOW;
Serial.print(F("Detect"));
Serial.println();
EDIT: Forgot to mention, occasionally the Hall sensor will send an interrupt (which I see through the serial monitor text "Detect") even when nothing is moving by it, as if the Hall sensor has some internal "jitter/bounce" or noise causing it to change state? Is this just due to the fact these are cheap sensors?
