Sleep mode NOT working propetly

Hi, I am using some WS2812B leds with an arduino nano 328p (without leds) and with a battery to power it. Because my device must be awake with a hall sensor (INTERRUPT 2), I code the arduino that it must be in sleep mode for the rest of the day. And I don't know why but yesterday the battery had 3.837V and today it has 3.691 V. So there's something about the sleep mode I've made wrong (I am 99% sure the Arduino is put to sleep). Here's the part of the code on putting the Arduino to sleep:

#include <avr/sleep.h>

void setup () {

}

void loop () {

   delay (2000);
   ADCSRA = 0;  
   set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
   sleep_enable();
   noInterrupts ();
   attachInterrupt (0, wake, HIGH);
   EIFR = bit (INTF0);
   MCUCR = bit (BODS) | bit (BODSE);
   MCUCR = bit (BODS);
   interrupts (); 
   sleep_cpu ();  
   attachInterrupt(digitalPinToInterrupt(sensorPin),pulseCounter , FALLING);    


}

Please ALL the code. What does "1 minute" have to do with the problem, and how are you keeping track of time?

Also post links to the sensor(s), and a hand drawn wiring diagram, showing all connected components.

Image posting guide.

Keep in mind that the sensors draw power when the Arduino is sleeping.

#include <avr/sleep.h>

#include <FastLED.h>
#define LED_PIN     4
#define NUM_LEDS    8
CRGB leds[NUM_LEDS];
byte sensorInterrupt = 0;  
byte sensorPin       = 2;

float calibrationFactor = 4;

volatile byte pulseCount; 
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;
int delayTime = 400;
int ON=10;

unsigned long lastTimeFlowRateAboveZero;
unsigned long lastTimeRESET;

void setup() {

  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter , FALLING); 
  pinMode (2, INPUT);

  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);




}


void loop() {

 if (flowRate > 0.2){
 

 if(totalMilliLitres>100000) {
  
  leds[3] = CRGB(0, 0, ON);
  FastLED.show();
  leds[4] = CRGB(0, 0, ON);
  FastLED.show();
  leds[5] = CRGB(0, 0, ON);
  FastLED.show();
  leds[6] = CRGB(0, 0, ON);
  FastLED.show();
  leds[7] = CRGB(0, 0, ON);
  FastLED.show();
  leds[0] = CRGB(ON, 0, 0);
  FastLED.show();
  
  delay (200);
  
  leds[3] = CRGB(0, 0, 0);
  FastLED.show();
  leds[4] = CRGB(0, 0, 0);
  FastLED.show();
  leds[5] = CRGB(0, 0, 0);
  FastLED.show();
  leds[6] = CRGB(0, 0, 0);
  FastLED.show();
  leds[7] = CRGB(0, 0, 0);
  FastLED.show();
  leds[0] = CRGB(0, 0, 0);
  FastLED.show();
  delay (200);
 }

if(totalMilliLitres>100000) {
  leds[1] = CRGB(0, 0, 0);
  FastLED.show();
  leds[2] = CRGB(0, 0, 0);
  FastLED.show();
 }

}



if((millis() - oldTime) > 300)    { 
  
    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();    
    flowMilliLitres = (flowRate / 60)*2000;   
    totalMilliLitres += flowMilliLitres;      
    unsigned int frac;
    Serial.print("Flow rate: ");
    Serial.print(int(flowRate));  
    Serial.print("L/min");
    Serial.print("\t");       
    Serial.print(totalMilliLitres/1000);
    Serial.print("L"); 
    Serial.print("\t"); 
    Serial.print("Output Liquid Quantity: ");        
    Serial.print(totalMilliLitres);
    Serial.println("mL"); 
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
    pulseCount = 0;   
}


if (flowRate < 0.5) {
  
   lastTimeFlowRateAboveZero = millis();
   
}

if (millis() - lastTimeFlowRateAboveZero >= 8000) {
  
  pinMode (7, OUTPUT);
  digitalWrite (7, LOW);
}


if (flowRate < 0.5) {
  
   delay (200);
   leds[4] = CRGB(0, 0, 0);
   FastLED.show();
   leds[3] = CRGB(0, 0, 0);
   FastLED.show();
   leds[2] = CRGB(0, 0, 0);
   FastLED.show();
   leds[1] = CRGB(0, 0, 0);
   FastLED.show();
   leds[0] = CRGB(0, 0, 0);
   FastLED.show();
   leds[5] = CRGB(0, 0, 0);
   FastLED.show();
   leds[6] = CRGB(0, 0, 0);
   FastLED.show();
   leds[7] = CRGB(0, 0, 0);
   FastLED.show();                          
   delay (300);

}


if (flowRate < 0.5  &&   totalMilliLitres < 10) {

   delay (2000);
   leds[4] = CRGB(0, 0, 0);
   FastLED.show();
   leds[3] = CRGB(0, 0, 0);
   FastLED.show();
   leds[2] = CRGB(0, 0, 0);
   FastLED.show();
   leds[1] = CRGB(0, 0, 0);
   FastLED.show();
   leds[0] = CRGB(0, 0, 0);
   FastLED.show();
   leds[5] = CRGB(0, 0, 0);
   FastLED.show();
   leds[6] = CRGB(0, 0, 0);
   FastLED.show();
   leds[7] = CRGB(0, 0, 0);
   FastLED.show();                
   delay (300);
   ADCSRA = 0;  
   set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
   sleep_enable();
   noInterrupts ();
   attachInterrupt (0, wake, HIGH);
   EIFR = bit (INTF0);
   MCUCR = bit (BODS) | bit (BODSE);
   MCUCR = bit (BODS);
   interrupts (); 
   sleep_cpu ();  
   attachInterrupt(digitalPinToInterrupt(sensorPin),pulseCounter , FALLING);    
 }

}



void pulseCounter(){
  pulseCount++; 
}

void wake (){  
  sleep_disable();
  detachInterrupt (0);
}

And you need to provide the the really key bit of information;

What current does the project use when its supposed to be in sleep mode ?

With the tester in one part negative side and the other one in positive (I think is different, I think it must be connected in parallel, but I don't know why when I do that the arduino does not power up). With that gives me arround 16 mA in sleep mode and in Active mode too. (battery has 500mAh)

when I do that the arduino does not power up

The Arduino is stuck in reset. It is difficult to use a multimeter to measure the current consumed by an Arduino while sleeping, because the meter interferes with normal operation.

The things you connected to the Arduino are consuming current. Are you planning to tell us about them at some point?

creepexthe:
With that gives me arround 16 mA in sleep mode and in Active mode too. (battery has 500mAh)

Battery mAh capacity in not really relavent.

That there is no difference in current between active mode and sleep mode does suggest that sleep mode is not working.

The current of 16mA, also suggests that there is other stuff consuming power, since the ATmega328 should only be using around 10mA of that if its active.

Is it possible for the hall sensor to be consuming about 6 mA when nothing is going on?

Measuring the low sleep currents of an Arduino is not so difficult.

A standard multimeter and a bit of wire will surfice.

Have the multimeter on say the 200uA range and short across the meter terminals with a bit of wire.

When the Arduino goes to sleep, remove the wire, and see the uA.

There are of course fancy gizmos that cost a fair but that have a very low burden voltage and consequently dont affect the circuit you are measuring.

But my bit of wire is my Goto for measuring sleep current, although I did go high tech and use a switch.

More details here;

Measuring Low Currents

That there is no difference in current between active mode and sleep mode does suggest that sleep mode is not working.

Of course it isn't.

The OP said that the Arduino does not power up while the measurement is being made, so it is stuck in reset. The ATmega328 consumes about 6 mA in reset mode.

But the OP won't tell us what else is connected, so no point in wasting any more time with this.

creepexthe:
Is it possible for the hall sensor to be consuming about 6 mA when nothing is going on?

Quite possible, but you know which device it is so check the datasheet.

There is other stuff in your circuit also.

Do remember that even if the processor does go into very low current sleep all the rest of the stuff in the circuit will not magically follow suit.

jremington:
The OP said that the Arduino does not power up while the measurement is being made, so it is stuck in reset. The ATmega328 consumes about 6 mA in reset mode.

Then clearly it is not 'active' and the OP can have no idea (that has been explained) how they can tell the difference between sleep mode and active.

Well, the not-mentioned attachments seem to be some WS2812 LEDs which draw 1 mA per LED when not illuminated. :roll_eyes:

srnet:
That there is no difference in current between active mode and sleep mode does suggest that sleep mode is not working.

Or that the meter is not connected properly.

I would like to see a schematic- not a pretty (useless) Fritzing picture.

What about the regulator on the nano ?