millerman4487
Published © CC BY-NC-SA

3D Printer Filament Sensor and Alarm

Ever run out of filament in the middle of a huge 3D printing job?

IntermediateFull instructions provided2 hours2,655

Things used in this project

Hardware components

Microchip ATtiny85
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
This is a great first 3D printer: https://amzn.to/2Ja0C2x
Soldering iron (generic)
Soldering iron (generic)
Try this one: https://amzn.to/2RxmDfw

Story

Read more

Custom parts and enclosures

Sensor Enclosure

Schematics

Schematic

Layout

Fritzing File

Code

Code

Arduino
Upload to ATtiny85
#define speaker 4
#define red 0
#define yellow 1
#define sensor 2
#define button 3

int buttonState;
int Mode = 0;
int i = 1000;
void setup() {
  pinMode(speaker, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);

  pinMode(button, OUTPUT);
  pinMode(sensor, INPUT);

  digitalWrite(button, HIGH);
  buttonState = digitalRead(button);
}

void loop() {
  //switch modes:
  int val = digitalRead(button);
  delay(10);
  int val2 = digitalRead(button);
  if (val == val2) {
    if (val != buttonState) {
      if (val == LOW) {
        if (Mode == 0) {
          Mode = 1;
        } else {
          if (Mode == 1) {
            Mode = 0;
          }
        }
      }
    }
    buttonState = val;
  }
  if (Mode == 0) { // buzzer off
    digitalWrite(yellow, LOW);
  }
  if (Mode == 1) {//buzzer on
    digitalWrite(yellow, HIGH);
  }
  //========================

  int filament = digitalRead(sensor);

  if (filament == 1) { //filament is good
    digitalWrite(red, LOW);
    i=0;
  }
  else {
    if (Mode == 0) { // buzzer off
      digitalWrite(speaker, LOW);
      digitalWrite(red, HIGH);
      delay(250);
      digitalWrite(red, LOW);
      delay(250);
    }
    if (Mode == 1) {//buzzer on
      digitalWrite(red, HIGH);
      if (i <= 10) {
        digitalWrite(speaker, HIGH);
        delay(500);
        digitalWrite(speaker, LOW);
        delay(500);
        i++;
      }
      else {
        digitalWrite(speaker, LOW);
      }
    }
  }
}

Credits

millerman4487

millerman4487

10 projects • 82 followers

Comments