Wake Interrupts on Arduino Micro

Hoping someone can help me figure out why the Hall Sensor (water flow) I have isn't able to wake the Arduino Micro from sleep. The below is a test sketch and the interrupt works fine during the program. I can shut the Arduino down, but it never wakes back up. Have tried Pins 7 and 3, and experimented with "RISING", "LOW", and "CHANGE". Could it be the Hall Sensor is changing state too quickly such that the wake up sequence doesn't have time to complete?

Here is the code:

#include "LowPower.h"

int flow;

/*
 *   Hall Effect Sensor Setup 
 */ 
volatile int NbTopsFan;                 
int hallsensor = 3;                     //The pin location of the sensor (not all pins can be used as 'interrupts'
long int ds = 1000;                     //Number of Milliseconds to sample for during flow event


void rpm () 
{                                       //This is the function that the interupt calls  
  NbTopsFan++;                          //This function counts the number of revolutions hall effect sensors signal
} 

void setup() {
  Serial.begin(9600);
  while(!Serial);
  
  Serial.println("Initializing... ");

  pinMode(hallsensor, INPUT); 
  attachInterrupt(0, rpm, LOW); //and the interrupt is attached
  Serial.println("Flow Sensor Initialized>>>");

  Serial.println("Setup complete!");
}


void loop() {
 
  digitalWrite(LED_BUILTIN, LOW);
  
  NbTopsFan = 0;                        //Set NbTops to 0 ready for calculations
  flow = 0;                             //Clear the flow variables for next cycle
  
  if(NbTopsFan > 0){
    do{
    digitalWrite(LED_BUILTIN, HIGH);    //Status LED to show when flow is being recorded
    fncReadSensor();
    digitalWrite(LED_BUILTIN, LOW);
    }while(NbTopsFan > 0);
  }else{
    fncSleep();
  }
}

///////////////////////////////////////////////////////////////////////////////
// This function puts the arduino to sleep
void fncSleep()
{
    Serial.println("fnc_sleep");
    delay(500);
    Serial.println("...entering sleep mode...");
    delay(500);
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 
    ///////
    // Arduino seems to sleep fine but doesn't wake up.
    //////
    Serial.println("...waking up...");
}


///////////////////////////////////////////////////////////////////////////////
// This function reads the sensor for 1 second
void fncReadSensor()
{
      NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
      delay (ds);       // period of time to count pulses   
      sei();              // Enables interrupts
      flow = NbTopsFan;    // Transfer value to a variable for future use. 
      Serial.print("Count: "); Serial.println(flow); 
}

If you comment out the call for fncSleep() in the "Else" statement, everything runs just fine.

My goal is have the Micro sleep until flow is detected, then using an RTC for datestamp, log the flow counts to an SD Card while the flow is present. When flow stops, the units shuts down again to save battery power.

lexical43:
Could it be the Hall Sensor is changing state too quickly such that the wake up sequence doesn't have time to complete?

From my experience, if the interrupt wakeup pulse was less than 2ms, my arduino would not wake up.

hope that helps...

Face Palm!

When the arduino goes to sleep it shuts off power to the sensor... thus the sensor won’t register a signal to send back to arduino to trigger the interrupt.

Ok... so this code still doesn't wake the Arduino Micro when flow start. Sensor has dedicated power, reads and prints data as expected. When fncSleep() is uncommented the board never wakes up.

Have tried:

  • Changing Pins (Pin=7/Int=4; Pin=2/Int=1; Pin=3/Int=0)
  • Power sensor on 5V and 3.3V
  • Combining grounds (board and sensor)
  • Interrupt type (CHANGE, LOW, HIGH, RISING)
  • Changing flow rate (250-10 RPSec)

What am I missing?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.