Page 1 of 1

3D Printer-mounted Smoke Detector

Posted: Thu Jun 28, 2018 7:47 pm
by Athakaspen
So, after spending weeks trying to come up with a useful project to make, I think I've finally got a good one. I have an Anet A8 3D printer, which is a cheap Prusa i3 clone from GearBest. I haven't had any major problems with it yet, but... from what I've read I'm pretty lucky in that regard. My plan for this project is to mount a smoke sensor above the terminals for the extruder and heated bed, since these are where I've heard of fires starting (if this project works I might get another sensor to put above the power supply, too). When the ESP32 detects smoke in the air, I'll have it do a few things:
  • Trip a relay to cut power to the printer, and turn on an indicator LED
  • Make a loud beeping noise for a minute or so
  • Send me a text (hopefully)
I say hopefully on that last point because I'm not totally sure how to make that work yet, but I'm fairly confident I can figure it out. That's probably what I'll work on while I wait for parts to arrive (ordered from Ebay with free shipping from China to the US, so it could be awhile). This is my first time working with an arduino so I'm trying not to too bite off too much more than I can chew :D .
I might not have any updates for awhile, since the parts are a long way away, but once they arrive I'll be sure to post something. Hopefully making this project public will keep it from being abandoned like so many before it. Wish me luck!

Re: 3D Printer-mounted Smoke Detector

Posted: Fri Jun 29, 2018 9:05 am
by wermy
Nice. I got about 80% of the way there with mine, and then got distracted with other things. :D

Re: 3D Printer-mounted Smoke Detector

Posted: Sun Jul 08, 2018 2:08 pm
by davmar
For the text message part Twilio (http://www.twilio.com) is a nice solution. I've used it for other projects in the past. Very simple to send a message: https://www.twilio.com/docs/sms/quickstart/python

Re: 3D Printer-mounted Smoke Detector

Posted: Sun Jul 08, 2018 5:07 pm
by Athakaspen
davmar wrote:
Sun Jul 08, 2018 2:08 pm
For the text message part Twilio (http://www.twilio.com) is a nice solution. I've used it for other projects in the past. Very simple to send a message: https://www.twilio.com/docs/sms/quickstart/python
Cool, thanks for the info. I'll have a look at that when I get home in a couple days. There should be some more updates coming soon as I get started!

Re: 3D Printer-mounted Smoke Detector

Posted: Sat Jul 14, 2018 12:58 pm
by Athakaspen
Progress! :D
IMAG0836.jpg
IMAG0836.jpg (575.49 KiB) Viewed 11325 times
The MQ-2 smoke sensor came in the mail a couple days ago, so I finally got started on the main part of the programming - getting the smoke detector to trigger an event. This, naturally, turned out to be far more complicated than it should have been. I'll try to break this down in the order that the problems arose.

The output of the MQ-2 sensor is an analog pin, with the voltage increasing when smoke is in the air. Simple enough, except that the reading tends to float a bit depending on the air quality. This meant that if I set a hard threshold value, the sensor output could slowly climb until it triggered a false alarm. Alternatively, if the reading floated too low, actual smoke might not kick it up high enough to trigger the alarm. To solve this, I created an array of integers to hold the previous 50 readings and set a baseline value at the average of those values. This way the baseline would naturally update as the sensor readings floated, and I could detect rapid changes in the sensor by comparing to this baseline.

This seemed to be working alright, so I linked it up to the SMS program I found online, which I had already tested. (I looked into using Twilio, but as I got started it seemed like it was overkill for what I was trying to do. I decided to use IFTTT instead since I already had their service hooked up to my phone.) When I merged the two programs, I had a very strange issue: After initializing the array of 50 readings and setting a baseline, the input from the sensor consistently gave a value of exactly 4073, well above the normal range. It worked perfectly while collecting those first 50 values, but after that it just... gave up. After about an hour of rereading the code, printing all sorts of values to the serial console, and commenting out other parts, I realized that the sensor worked fine until I connected to WiFi. After some googling, I found out that lots of analog pins on the ESP32 simply don't work once you're connected to WiFi. Once I moved it to a pin that wasn't affected by this problem, everything worked fine again. Until...
Screenshot_20180714-115907.png
Screenshot_20180714-115907.png (214.38 KiB) Viewed 11325 times
Occasionally, the sensor will spike for a single reading, for no reason. This meant that I would get a text every couple minutes about a false alarm, which wasn't going to fly. To solve this, I just made sure the alarm wouldn't trigger unless there were 3 consecutive high readings. And with that, it seems to be working perfectly, and I'm just waiting on the other parts to arrive in the mail. Here's the loop function after all the changes listed above:
code1.PNG
code1.PNG (33.04 KiB) Viewed 11325 times

Re: 3D Printer-mounted Smoke Detector

Posted: Fri Aug 24, 2018 7:43 pm
by Athakaspen
Update: The rest of the parts FINALLY arrived a couple days ago, and with the deadline closing in, I'll have to finish everything up pretty quick. Wish me luck!