Please i need some helpon this

Hello hi every one...!!!!.

sorry i have the code that's working perfectly with my water meter with pulse output sensor(reed switch) with two wires black and red, but i need the system to be powered by 3.7v battery so i need to save power by applying sleep mode of controller when no water is flowing through the meter and wakeup when water flows through the meter.

below is the working code without sleep mode feature

define recieve 2
int counter=0;
int val=0;
float liter = 0.0;
int prevVal=0;
unsigned int frac;



void setup() {
pinMode(recieve, INPUT_PULLUP);
Serial.begin(9600);

Serial.println("Ready for data");
}

void loop() {

prevVal=val;
val=digitalRead(recieve);


  if(val != prevVal  && val==1){
  counter++; 
  }

liter=(float)counter/2.05;


Serial.print("Impulses: ");
Serial.print(counter);

Serial.print(" | Amount: ");    
Serial.print(liter);

Serial.println(" liter");
}

You forgot to tell us which processor you are using

am using arduino nano

later on i will design stand alone circuit with atmega328 chip

Fortunately, you are using pin 2 for your input which happens also to be an external interrupt pin on an device such as a Uno or a Nano (or, even better, a barebones ATmega328p).
My advice is to get a skeleton sleep mode sketch working (just use a button on pin 2) then, once that is all working, integrate your water meter code into it.

See https://www.gammon.com.au/power and look for "Waking from sleep with a signal"

I have tried to follow instructions on that link but i did not managed to solve my problem, sorry help me to add that feature in that code above

The document linked is the full story, and to get really good low power operation you have to mind all the details.

Did you try any of the examples he offers, without changing them, to see how sleep works and why you have to do the things he does?

Certainly at least one example will show you how to go to sleep and wake up upon a condition becoming true.

Run the examples, read the descriptions of them. There is no substitute in this case for doing a little learning. Unless you just want someone to write the sketch for you.

a7

yes i did, but how do i add that code to one of the sleep example?

hey why arent you visiting me :frowning_face:

what do you mean?

alto777 isnt replying to my post and im impatient :cry:

any help please

Post your best effort, and your observations of how it failed to meet your expectations.

if it happens that someone has come to this forum to ask for help, why should he not be helped with his problem? and instead you start giving him other useless tasks?

specify "useless tasks"

i have posted the code that am facing the problem with so that anyone on this forum can see and help me to solve the problem that am facing with

Please see reply 13.

i have seen that but i did not understood, can you help me to add that feature in my code above?

Did you read post 5?

bro why are still asking such questions as i said am not familiar with that, that's why i came here for some to help me, why don't you helps me if you know and i will learn through the modification of the code? i don't know how to add that feature into my code above.