ARDUINO: control your gate, pump just with single power button

It is often necessary to control remotely two-state devices like entrance gate, water pump, RF switch or IR switch. My idea was to keep just single on/off button and keep smallest possible leakage current.
You can see my idea on schematic below.





C1R3 circuit defines delay befor arduino will be swtiched off. Time can be calculate as t=0.7 * C1 * R3 = 0.7 * 33μ * 330k = 70s
If you need more than 70 seconds, just increase value of C1 or R3.

Arduino sketch:
// ARDUINO: control your gate, pump just with single power button
// Description and schematic: 
//  http://randronov.blogspot.com/2016/05/arduino-control-your-gate-pump-just.html

#include 

const int interruptPin = 3;
int wakedUp = 0;

void setup() {
  // execute ON commands
  device_on();

  // and go into deep sleep
  //sleep_enable() always before attachInterrupt
  sleep_enable();
  attachInterrupt(digitalPinToInterrupt(interruptPin), wakeUp, LOW );

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  cli();
  sleep_bod_disable();
  sei();
  sleep_cpu();  
}

void loop() {
    if(wakedUp){
      device_off();
    }
     delay(1000); // just for case :)
}


// we can't do a lot in the handler, just wake up and set flag
// switchOff contains the rest
void wakeUp(){
  sleep_disable();
  wakedUp = 1;
}

void device_on(){
  //your code to switch device on
  
}


void device_off(){
  //your code to switch device off


  // keep looong delay to let arduino go off
   delay(300000); 
}

No comments:

HOWTO: Repair Logitech M325 Mouse

FixIt says that you will find single screw under CE label. It isn't always true.