ArtSuzhou
Published © CC BY-NC-SA

Smart Filament Runout Switch

This little device switch can pause the 3D printer and send you a notification when the filament ran out. No more waiting or panic!

IntermediateFull instructions provided2 hours3,562

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Micro Limit Switch
OpenBuilds Micro Limit Switch
Uses KW11-N micro limit witch (10x20mm) with roller arm.
×1
LED (generic)
LED (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 221 ohm
Resistor 221 ohm
×1

Software apps and online services

Cayenne
myDevices Cayenne
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Smart Filament Runout Switch

Schematics

Smart Filament Runout Switch

Code

Smart Filament Runout Switch

C/C++
/**The MIT License (MIT)
Copyright (c) 2017 by Bin Sun
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

For more information visit https://www.hackster.io/binsun148/smart-filament-runout-switch-e0da31
*/

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

int state=0;

#define ledPin D5 //Pin for the status LED
#define outPin D6 //Pin to control the printer
#define filaPin D2  //Pin to connect filament switch NO

// WiFi network info.
char ssid[] = " ";
char wifiPassword[] = " ";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = " ";
char password[] = " ";
char clientID[] = " ";

unsigned long lastMillis = 0;

void setup() {
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  pinMode(outPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  digitalWrite(outPin, HIGH);
  // Setup notification button on pin 2
  pinMode(filaPin, INPUT_PULLUP);
}

void loop() {
	Cayenne.loop();
  
	//Publish data every 1 seconds (1000 milliseconds). Change this value to publish at a different interval.
	if (millis() - lastMillis > 1000) {
	lastMillis = millis();
  checkFilaLow();
  Cayenne.virtualWrite(V1, state, "digital_sensor", "d");
	}
}


//fila switch 0 okay, high 1 run out  

void checkFilaLow()
{ 
  int isFilaLow = digitalRead(filaPin);
  if (isFilaLow) {
   Serial.println("Filament is out.");
   state=1;
   digitalWrite(ledPin, HIGH);  // turn on LED with voltage HIGH
   digitalWrite(outPin, LOW);  // turn on output pin with voltage LOW
     }
     else{  
   Serial.println("Filament is okay.");
   state=0;
   digitalWrite(ledPin, LOW);  // turn on LED with voltage HIGH
   digitalWrite(outPin, HIGH);  // turn on output pin with voltage LOW
     }
    }

Credits

ArtSuzhou

ArtSuzhou

8 projects • 29 followers

Comments