Friday, April 24, 2020

Break to Make: CO2 Detector Take 2

As we saw last time, I made something fun, but not very useful.  So let's make something useful today.
The Problem:
My daughter is not in school right now, as you may have experienced yourself.  At her current age, she isn't supposed to have very much screen time, but almost all of her work is online now so we decided to set a limit of 30 minutes of screen time and then a break.  With me working and my spouse taking care of our other little one, who is watching the clock?  The answer turned out to be no one.  I could set a timer on my phone, but that wouldn't be my daughter taking responsibility for it so what can we do?
The Solution:
If only we had a buzzer that I could make a timer out of.  Didn't we have one by the albino the hidden alarm?  We did, what I wouldn't give for a holocaust cloak a button switch and an LED.  That's right, observant readers will remember they were both on the CO2 detector that we didn't use.
So after a quick desoldering, we have them.  But that little blue button is not very attractive, I'd rather it have a topper like these nice ones from Adafruit.  Let's check Thingiverse first, this one looks perfect, but it is for the wrong size button.  Let's print it anyway and scale it to see, nope the middle is all mushy.

Now, on to OpenSCAD! My calipers say the small blue button is 2mmx2mm and the Adafruit site lists the size as 12mm, so a big cylinder (r=6mm) for the outside minus a cube (2mmx2mmx2mm) for the inside.  Done and done.
Doh! 2mmx2mm is exactly what the button is and the actual printed size is too small.  Let's try 3mmx3mm.  Bingo (file on Thingiverse).  
Now to put it all together, a button, an LED, a buzzer and an Arduino, now we can make a timer.
So I was thinking, push the button and set a 30 minute timer.
if (buttonState==HIGH) {
    digitalWrite(ledPin,HIGH);
    delay(1000*60*30);//1000=1 sec, 60 sec in a minute, 30 minutes total
    playMelody();
    digitalWrite(ledPin,LOW);
}
And to test! 30 seconds? Let's check the math, 1000 ms in a second * 60 seconds in a minute * 30 minutes, right?  Yes.  Hmm a cryptic warning from Arduino: "More knowledgeable programmers usually avoid the use of delay() for timing of events longer than 10’s of milliseconds."
Interesting, it seems like there is an overflow problem.  So lets delay for 1000 (1 second) and count up to 1800.  And it works (code)!  So next we cram it back into the CO2 detector shell.  First, I cut all of the unnecessary plastic bits out, then I got my tiniest breadboard.

And did you notice? There are three AA batteries, 1.5*3 is 4.5V which is within the power requirements for Arduino.  So a quick solder for that and solder the wires to the buzzer to save some space and Voila!

I had to cram some thick paper in there to make the button stick out and I accidentally broke one of the clips so I had to hot glue it, but other than that we are done.  The wires are rescued from some old ethernet cable I had laying around.    

And now, we come in at 29 minutes and 59.5 seconds.  

Well this time, it is both fun and useful.  Hooray!