The last one turns off the lights
- self holding circuit for Arduino's power supply

created with TinyCAD 20.80.03
If you ever operated any device with batteries it surely happened that you or someone else forgot to switch off the device after use and the batteries went dead. Most pocket calculators and mobile phones have a built-in auto switch-off to disconnect power after a certain time of inactivity.

Actually, the Atmel ATmega328P comes with a sleep mode which will reduce the power input down to only 20 μA. The sleep mode demo comes with 160 lines of code.

We wanted to do it with hardware - and we manged.
At first we found Arduino Ein-/Ausschalten mit einem Taster which obviously can not work. (Check out: to make an npn transistor conducting the base voltage must be at least 0.7 volts above the emitter voltage which is the supply for the ATmega.)
We found no way to handle it with only one transistor.

So the solution was as shown in the picture on the right. You have to press SWITCH1 shortly to power the Arduino. In the setup-routine the command
  digitalWrite(relayPin, HIGH);
will make transistor NPN1 conductive and as a result making transistor PNP1 conductive which is parallel to SWITCH1. So, when you release SWITCH1 the Arduino still is powered until

The following program activates the self holding circuit and then the LEDs blinks with increasing speed. When the delay time gets near zero the relay pin gets LOW and the complete circuit gets disconnected from the battery.

int ledPin   = 13;
int relayPin = 12;
int dt = 1000;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);     
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(dt);               // wait for a second
  digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
  delay(dt);               // wait for a second
  dt = dt - 25;
  if (dt <= 25) digitalWrite(relayPin, LOW);

When we tried to measure the remaining current it turned out that it is less than 0.01 μA (the minimum resolution of our instrument) which is much less than in sleep mode.

contact: nji(at)