Good afternoon forum. First time posting; not sure if this is a coding issue or something with the Nano so figured I'd start here. Just started working on Arduino projects. Have an issue with a current project I'm working on regarding RPM readings. I'm using a hall effect sensor and Arduino Nano Every to report RPM speed of a DC motor. I initially ran the code on an Uno and it worked fine without issue. I transferred over to the Nano and the code is not working here. I have the hall effect sensor still attached to pin 2 as I did with the Uno. Upon further troubleshooting, it appears that the interrupt function I have to increase the pulse count is not being called. I know the sensor is working as I can see the high/low transition as my magnet passes and I know the Nano is receiving it (I used an oscilloscope to read pin 2 and verified the sensor function). Am I incorrectly using interrupts on the Nano somehow? A snippet of my full code is below and pertains only to the HES. Any thoughts or feedback would be super helpful. Thank you!
//Hall effect sensor obhject declarations
int hall_pin = 2; // digital pin 2 is the hall pin
float hall_thresh = 100.0; // set number of hall trips for RPM reading (higher improves accuracy)
float pulses;
int rpm;
unsigned long timeOld;
void setup()
{
Serial.begin(115200);
//Setup and initialize interrupt to count pulses
attachInterrupt(0, pulseCounter, FALLING);
//Initialize variables for calculating RPM
pulses = 0;
rpm = 0;
timeOld = 0;
pinMode(hall_pin, INPUT);
//Turn on the LED
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
void loop()
{
if (pulses >= 25)
{
detachInterrupt(0);
rpm = 60000.0/(millis()-timeOld)*pulses;
timeOld = millis();
pulses=0;
attachInterrupt(0, pulseCounter, FALLING);
}
if (pulses <= 25 && (millis()-timeOld >= 1500))
{
rpm = 0;
}
Serial.print(pulses);
Serial.print('\n');
}
//Interrupt function that will count all the pulses from the Hall effect sensor
void pulseCounter()
{
pulses++;
}