Philip Tabone
Published © GPL3+

Safe Shutdown and Auto Bootup for Raspberry Pi

Have someone pulling the plug on your project, or perhaps an unstable or unreliable power supply? Here is the fix!

AdvancedFull instructions provided3.5 hours22,625
Safe Shutdown and Auto Bootup for Raspberry Pi

Things used in this project

Hardware components

ATtiny85
Microchip ATtiny85
×1
Resistor 10k ohm
Resistor 10k ohm
×2
Resistor 1k ohm
Resistor 1k ohm
×2
5V Step Up Voltage Regulator
×1
P-Ch Mosfet IRF 5210
×1
IC Base
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×2
Super Capacitor 40F
×1
Resistor 221k ohm
Resistor 221k ohm
×1
PCB
×1
Resistor 47.5k ohm
Resistor 47.5k ohm
×2
Resistor 10 ohm 1W
×1
MBR360G –  3A Schottky Barrier Rectifier
MBR360G – 3A Schottky Barrier Rectifier
×2
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×2
Female Header 20 Position 2 Row (0.1")
Female Header 20 Position 2 Row (0.1")
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Circuit Schematic

Use as reference. For building and testing.

Fritzing file

Use this to make PCBs

Code

ATTiny ups logic code

Arduino
Code for the ATTiny, refer to flow chart at ATTiny logic
int voltagepin = A1;
int powerswitch = 1;
int mains = 0;
int shutmedown = 4;

void setup() {
  // put your setup code here, to run once:
  //Set Pin In/Out
  pinMode(powerswitch, OUTPUT);
  pinMode(shutmedown, OUTPUT);
  pinMode(voltagepin, INPUT);
  pinMode(mains, INPUT);
  delay(5000);
  bootup();

}

void loop() {
  // put your main code here, to run repeatedly:
  if (!digitalRead(mains) && digitalRead(powerswitch) && analogRead(voltagepin)<390 ){
    digitalWrite(shutmedown,HIGH);
    delay(25000);
    digitalWrite(powerswitch,LOW);
    digitalWrite(shutmedown,LOW); 
    delay(5000);  
  }

  if(!digitalRead(powerswitch) && analogRead(voltagepin)>400 && digitalRead(mains)){
    digitalWrite(powerswitch,HIGH);
  }

  delay(10);

}

void bootup()
{
  //bool flag = false;
  
  while( !(digitalRead(mains) && analogRead(voltagepin)>400) ) //while charging lock in loop till voltage is above ref and mains is on
     
    {
      delay(500);//little wait
    }
  //Once Flag true Power On
  digitalWrite(powerswitch,HIGH);
  delay(10000); //bootup time

Credits

Philip Tabone

Philip Tabone

3 projects • 14 followers
If I need, it I'll build it.

Comments