Viktor S
Published © CC BY-NC

Automatic 3D Printer Shutdown

Shuts down 3D printer shortly after a print completes.

IntermediateFull instructions provided6 hours3,603
Automatic 3D Printer Shutdown

Story

Read more

Custom parts and enclosures

MKS Gen L & Auto Shutdown Circuit Mount for Anet A8

Schematics

(1) Auto Shutdown Schematics

Follow the connections using the schematics. Note that it does not include connectors and terminals!

(2) AH3505 Datasheet

(3) LM2904 Datasheet

(4) Relay Datasheet

Code

Auto_Shutdown_ATtiny13A

Arduino
/*
 * Viktor Silivanov
 * 9/14/2018
 * This code is supplementary to my guide on making a automatic shutdown board for your 3D Printer.
 * https://www.hackster.io/viktorsilivanov
 *
 * ATtiny13A Pinout
 * https://bit.ly/2MrInFD
 *
 * Pin # | Assignment | PWM | Serial |
 * -----------------------------------
 *   1   |   D5/A0    |  x  |   x    |
 *   2   |   D3/A3    |  x  |   x    |
 *   3   |   D4/A2    |  x  |   x    |
 *   4   |    GND     |  x  |   x    |
 *   5   |     D0     |  Y  |  MOSI  |
 *   6   |     D1     |  Y  |  MISO  |
 *   7   |   D2/A1    |  x  |  SCK   |
 *   8   |    VCC     |  x  |   x    |
 *
*/
//******************** Global Variables ****************************************************************************

//  Pin Definitions
#define LED         1                             // D1 = Pin 6 in DIP8 package
#define RELAY       2                             // D2 = Pin 7 in DIP8 package
#define HALL        3                             // D3 = Pin 2 in DIP8 package

//  Variables
bool shutdown;
float time = 6.0;                                 // Time (in minutes) to shut down. Modify this if needed

//******************** Code Begins *********************************************************************************

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(RELAY, OUTPUT);
  pinMode(HALL, INPUT);

  digitalWrite(LED, LOW);                         // 0V turns on LED. Remains ON as long as ATtiny is powered
  digitalWrite(RELAY, LOW);                       // Initial: Printer ON (Relay Normally Closed)

  time = time * 60;                               // Converts minutes to seconds
}

void loop(){
  shutdown = false;                               // Reset shutdown
  digitalWrite(RELAY, LOW);                       // Default: Printer ON (closed circuit at relay's output)

  if(digitalRead(HALL) == HIGH){
    for(int i = 0; i < time; i++){                // Blink LED for X minutes
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(500);

      // Allows for user to abort while it's waiting X minutes
      if(digitalRead(HALL) == LOW){                             
        shutdown = false;
        break;                                    // Exits for loop
      }
      // X minutes passed. Shutdown confirmed
      else{
        shutdown = true;
      }
    }
  }

  // If sensor is triggered AND user didn't abort within X minutes, turn off printer
  while(digitalRead(HALL) == HIGH && shutdown == true){         
    digitalWrite(RELAY, HIGH);                    // Printer OFF
    digitalWrite(LED, LOW);
  }
}

Ending Script

Plain text
Add this portion of code either in your slicer or directly inject it to your gcode.
; layer end
M104 S0 				      ; turn off extruder
M140 S0 				      ; turn off bed
G1 E-1 F300				    ; retract the filament a bit
;G1 Z+2 E-5 F9000 		; move Z up a bit and retract filament even more
G28 X0					      ; home X
M84 					        ; disable all motors
M104					        ; disable extruder motor
M107 					        ; shut off fan
G1 Y210 F9000		    	; move bed forward
M84 					        ; disable all motors

Credits

Viktor S

Viktor S

7 projects • 19 followers
Electrical Engineer & Electronics Hobbyist

Comments