Deep sleep with analog pin wake-up trigger?

Hi all,

I'm working on a fairly simple little device that will listen to an analog pressure sensor, and when the sensor picks up anything above 0, it will delay, then move a linear actuator (which will drop the pressure to 0 eventually), then standby for the next pressure reading. I've never worked with any of the various sleep modes with arduino but I'd like to have the arduino go to the deepest possible sleep as long as the pressure is at 0, and let that analog sensor act as the "wake-up switch" when pressure is detected again. Any tips on the best way to code this? Here is my code so far with no sleep code written yet.

const int dir = 5;             //direction pin on motor control board
const int pwm = 6;         //motor enable pin

int potPin = A1;            //potentiometer inside linear actuator
int potVal = 0;

int wlsPin = A2;            //pressure sensor
int wlsVal = 0;



void setup() {
 pinMode(pwm, OUTPUT);
 pinMode(dir, OUTPUT);
 pinMode(wlsPin, INPUT);
 pinMode(potPin, INPUT);

Serial.begin(9600);
  }

///////////////////////////Arm Movement Protocols/////////////////////////////////////////

void extendArm(){                //protocol for extending arm
  
  digitalWrite(pwm, HIGH);
  digitalWrite (dir, LOW);                        
  while(potVal > 15){
    digitalWrite (pwm, HIGH);
    digitalWrite (dir, LOW);

    if((potVal < 20) && (potVal > 10)){
      digitalWrite (pwm, LOW);  
    }
  }
  Serial.print("Extending Arm");
}
void retractArm(){                 //protocol for retracting Arm
  
   digitalWrite(pwm, HIGH);
  digitalWrite(dir, HIGH);
  while(potVal < 1005){
      digitalWrite(pwm, HIGH);
      digitalWrite(dir, HIGH);      

        if((potVal > 1000) && (potVal < 1010)){
          digitalWrite(pwm, LOW);  
    }
  }
  Serial.print("Retracting Arm");
}




void loop() {

potVal = analogRead(potPin);
wlsVal = analogRead(wlsPin);

/////////////////////////Boolean Definitions////////////////////////////////////////

boolean armIsRetracted;
if((potVal < 1010) && (potVal > 1000)){
  armIsRetracted = true;                       //boolean function for armIsRetracted
  Serial.print("Arm is Retracted");
   }
   else{
    armIsRetracted = false;

}
boolean armIsExtended;
if((potVal < 20) && (potVal > 10)){
  armIsExtended = true;                     //boolean function for armIsExtended
  Serial.print("armIsExtended");
    }
    else{
    armIsExtended = false;

}
boolean pressureIsPresent;
if(wlsVal > 0){
  pressureIsPresent = true;                    //boolean function for pressureIsPresent
  Serial.println("Pressure is Present");
   }
   else{
    pressureIsPresent = false;

}
boolean pressureNotPresent;
if(wlsVal<=0){                            
  pressureNotPresent = true;                   //boolean function for pressureNotPresent
  Serial.println("pressure not Present");
    }
    else{
    pressureNotPresent = false;
   }



//////////////////////////Hardware control loop////////////////////////////////////////////


if((pressureNotPresent) && (armIsExtended)) {}             //if no pressure, do nothing

if(pressureIsPresent){        
  delay (15000);                        
  retractArm();                   //if pressure is present, delay x time then retract arm
        }
    
  
 if(armIsRetracted){
      while (pressureIsPresent){}     //if arm is retracted and pressure still present, do nothing
}

if((armIsRetracted) && (pressureNotPresent)){
  delay (5000);                                    
  extendArm();                    //if arm is retracted and pressure goes below 1, delay x time then extend arm
    }
  }

This may help:
https://playground.arduino.cc/Learning/ArduinoSleepCode

Why? What is the power budget that requires the "deepest sleep"?

The analog subsystem is the biggest single power consumer in sleep mode. Like a hundred times more than the rest of the chip combined. It is usually the first thing you turn off. But we're talking micro-amps. Maybe your power budget can support that?

Since the power consumption is so high, it may be better to "sleep deepest" for a few seconds then wake up for a millisecond and take a reading. So there's no analog interrupt required.

That's an idea, microamps should definitely be acceptable. Like I said I'm new to any sleep code functions but this is a standalone device that will have a midsize 12v battery and small solar panel and it needs to be able to stay out in the field indefinitely. I'd like it to be able to run 10-14 days with no solar recharge.

So, like a 7Ah battery?

Over 14 days that's an average of 20mA.

Nick Gammon's power page says an UNO in sleep mode draws about 35mA. So you can't use an UNO. His next step is a bare-bones Arduino chip on perf board. That draws 15mA when it's running at full speed - no sleep mode.

A more practical approach is to use a Pro Micro, which has no USB interface but does have a voltage regulator. That would fall somewhere between those two options above, but it will get under 20mA with very little work on selecting a sleep mode.