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");
}
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.
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.
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?
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.