Friday, May 15, 2020

Filament sensor with alarm on your phone

For an index to all my stories click this text.

Long story Short: I have a new 3D printer. My Beagle broke down after 5 years of service beyond being repairable. So I got myself a new printer. It is a Creality CR20. However it uses 1.75mm filament while my Beagle used 3mm filament.

Luckily a friend of mine came to the rescue. He traded my old 3mm filament for some new 1.75 filament.
What I received was some older filament and at some places it was brittle. During printing I noticed just in time that the filament on the roll was broken. The print finished just at the right moment.

This is however something you do not want to happen during long prints. And my prints were getting longer as I was printing more earsavers for face-masks at the time.

Not a big problem when you are in the same room as where the printer is. You can check its proceedings every few minutes. However I am lazy. So I often put the printer to work and leave the room to do something really important like sitting in my garden with a good book and cold drinks.

I searched the internet for a filament sensor and found several. The idea is as ingenious as simple. Run the filament tightly along a microswitch so the switch keeps getting pressed. When the filament breaks the switch is released and sounds an alarm. And there was my problem.

The alarm these sensors use are generally piezo buzzers taken from a fire alarm. They do make a hell lot of noise. But I could not hear it when I was in my garden. So I had to find a solution.

I always carry my phone with me. Why not send a notification to my phone when broken filament is detected. That proved to be much simpler as I thought.

The setup.

The first thing is to build the filament sensor. I used Tinkercad to design it and then 3D printed it. The switch is attached to a Wemos D1 mini through a pull-up resistor. The switch is pressed all the time till the filament is broken and then the switch connects pin D1 of the Wemos D1 to GND. When this happens the Wemos D1 sends a signal to IFTTT and IFTTT sends an alert to my phone.

Filament sensor.

There are several versions of microswitches which you can use.



The one on the left has a straight lever and the one on the right has a bulge at the end. Both wil do the job and can be used with my casing. There is another version with a wheel on top of the lever and to use that you might have to alter the design of the casing.

The casing was designed in Tinkercad and I made 2 versions. First version is for 3mm filament and second version for 1.75mm filament. The lid is for both versions the same. The picures show how they look and there is a download link included.

After downloading slice them. I set my slicer to .3mm



Filamentsensor175 link:  https://www.tinkercad.com/things/1Qptw2SZne4



Filamentsensor3MM link:  https://www.tinkercad.com/things/4S6d4y6LUjC



Filamentsensor lid:  https://www.tinkercad.com/things/9F9C5g1iI2A

Maybe you need to make some adjustments if you own a different micro-switch as the one I used. To do so get yourself a free Tinkercad account at https://www.tinkercad.com/ Go to the design you need and copy and adjust it.

You can find all my public Tinkercad files by opening https://www.tinkercad.com and look for user lucvolders (no spaces).



And here is a picture of the final version.

As there is some margin in the casing I glued the switch into the casing.

You might want to design a casing for the Wemos or NodeMCU or whatever version of the ESP8266 you are going to use. I left it on the breadboard for now as I have plans for an extension.

You could use an ESP-01 for this. However as the prices of the Wemos D1 have fallen and you would need to build your own power supply for the ESP-01 it might be more expensive as the Wemos D1 version.

The electronics.

This is the easy part. I attached the microswitch to GND and with a 10K pull-up resistor to a Wemos D1. The switch was connected to pin D1 of the Wemos mini D1.



The setup is really easy and the breadboard layout shows all.

IFTTT

IFTTT is covered extensively in these stories:

IFTTT introduction - What is IFTTT and what can we do with it part 1
https://lucstechblog.blogspot.nl/2017/04/ifttt-if-this-then-that.html

IFTTT part 2 Maker Channel - Tutorial part 2
https://lucstechblog.blogspot.nl/2017/05/ifttt-part-2-maker-channel.html

IFTTT part 3 Alert over IFTTT - Tweet an alarm when your PIR has noticed motion
https://lucstechblog.blogspot.nl/2017/05/ifttt-part-3-basic-alert-over-ifttt.html

IFTTT part 4 - Send a notification to my phone
https://lucstechblog.blogspot.nl/2017/09/ifttt-4-send-notification-to-my-phone.html

IFTTT test - a simple test for IFTTT triggers from your browser
https://lucstechblog.blogspot.com/2019/02/simple-ifttt-webhook-test.html

IFTTT alarm from ESP8266 using Arduino language
http://lucstechblog.blogspot.com/2019/04/ifttt-alarm-from-esp8266-using-arduino.html

Look at this last story specifically. I am going to use that technique to send the alarm to my phone.

The program

As usual the program is written in C++ (Arduino language).

// IFTTT Webhook trigger
// Simple trigger to get a notification
// on your phone when 
// the filament on your 3D printer is broken

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "XXXXXXXXXXXXXXXX";
const char* password = "YYYYYYYYYYYYYYYYY";

int FilPin  = 5;
int IftttSend = 0;

void setup() 
  {
  pinMode(FilPin, INPUT);
      
  Serial.begin(115200);
  delay(100);
    
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
    
  WiFi.begin(ssid, password);
    
  while (WiFi.status() != WL_CONNECTED) 
    {
      delay(500);
      Serial.print(".");
    }
  
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());  

}

void loop() 
{
 if ((digitalRead(FilPin) == HIGH) && IftttSend == 0)
 {
  sendifttt();
  IftttSend = 1;
 }
}

void sendifttt()
{
  Serial.print("connecting to ");
  Serial.println("maker.ifttt.com");
  HTTPClient http; //Declare an object of class HTTPClient
  http.begin("http://maker.ifttt.com/trigger/Hey Luc/with/key/PUTYOURKEYHERE?value1=The%20filament%20is%20broken%20!!!");
  int httpCode = http.GET(); //Send the request
  if (httpCode > 0) 
    { //Check the returning code
      String payload = http.getString(); //Get the request response payload
      Serial.println(payload); //Print the response payload
    }
  http.end(); //Close connection
}


I am not going over the program as it was discussed intensively in the previous story: http://lucstechblog.blogspot.com/2019/04/ifttt-alarm-from-esp8266-using-arduino.html

The only thing you have to notice is that I canged the line which sends information to IFTTT from the previous story into this:

http.begin("http://maker.ifttt.com/trigger/Hey Luc/with/key/PUTYOURKEYHERE?value1=The%20filament%20is%20broken%20!!!");

Alter the text to your own liking but do not forget to alter spaces in your text to %20 like seen above otherwise the notification on your phone looks messy.
Naturally you must change "Hey Luc" in the trigger you are going to use with IFTTT. And exchance the tekst "PUTYOURKEYHERE" with your own IFTTT webhooks key.

Also do not forget to alter your routers credentials otherwise the ESP8266 can not connect to IFTTT

Real life use.

Put the sensor at a reasonable distance from your printer extruder. That will give you ample time to get off from your lazy chair and react.



This is how the notification looks on my phone.

If your filament has broken and you have received the notification replace the filament and press reset on the Wemos D1 to re-start the program. You could design a webpage with a button to restart the program but I did not think it's worth the trouble.

There is just one small other thing. I have to go to the printer to check whether the print has finished. Or I need to set a timer on my phone with an estimate when the print will finish. Thats the next thing I am going to automate...... Enough pins on the Wemos D1 mini to check that too.

Happy printing.
Till next time.

Luc Volders