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!

Friday, April 17, 2020

Break to Make: CO2 Detector Take 1

Hello Friends, today we will make something new out of an expired CO2 detector.  First we take out the batteries.
Ok, now the screws, nope, no screws ok, there are little plastic tabs holding it in place.  If you can wiggle them gently and cram a little screwdriver in there we can take the bottom off and it will easier to put back together.  I also flipped the circuit board over to get a better look at the components.  Voila:

That looks like one honkin' big buzzer, lets see if it works like a regular buzzer.  It is Arduino time. First load toneMelody onto your Arduino (File -> Examples -> 02. Digital -> toneMelody) which plays the catchy jingle, "Shave and a haircut, two bits." Apologies to those who are more familiar with the inappropriate version which I will not repeat here (for the curious, the second to last word is madre and a description can be found on the Wikipedia page for "Shave and a Haircut").  Anyway, where was I, ah yes, if you have a buzzer or speaker laying around you can test to see what it sounds like by connecting pin 8 (usually) to the positive and ground to the negative.  The Arduino Tutorial page has a good description.  Next is to get two longish jumper wires, one in pin 8 and the other to ground.  We are going to have to flip the board back over to get at the pins for the buzzer:

You might have to flip it back and forth a few times before you find the right ones, they are larger than most of the pins in the area and mine had three (one is being touched by the blue wire in the above image and another is by my finger).  Pick two and apply the wires, did it work? Try flipping the wires, now? Try different pins, and? There are only six combinations with three pins (3 choose 2 = 6) to it shouldn't take too long.  Also, you might want to adapt the toneMelody code to play on loop so you don't have to keep hitting reset on the Arduino and hold the wires on the pins at the same time, but it isn't absolutely necessary.  Success!


Ok, so now we heat up the soldering iron.  I can't figure out how to hold my phone and the soldering iron and the CO2 detector all at the same time without burning myself so no action shots, but basically I took a smallish screwdriver and gently wedge it between the buzzer and the circuit board then on the bottom I put the soldering iron on the leg closest to the screwdriver until it is melty and moves.  Then I move the screwdriver to a different spot and repeat until all of the pins are out.  Got it:
Let's just double check that we didn't fry it.  Also, I switched to M-to-F jumper wires now that it is off the circuit board.


Score! Now we are ready to make something with it.  I happen to have a photoresistor in my Arduino kit and you probably do too so I thought it might be fun to make an alarm.  The photoresistor tutorial is here.  We can add that to the breadboard and set up a simple trigger.  To minimize fiddling I set the baseline value to the ambient lighting on reset and then the trigger will be when it gets at least 90% darker.  If you don't want to figure it out yourself, the code is here. Testing:


Not too shabby.  And now to cram it all back into the base and test. 



Well that was fun and a little silly, but not very useful...  

New Chapter

Hello out there my faithful and few readers, I am now at Sacramento City College.  Because of the social distancing, I'll put some Maker Friday posts as part of Sac City's Makerspace.  Which I am the co-co-coordinator of.  More to come soon, including Fix-it Friday, Break to Make, and more!

I have been working on these for a few weeks now, yet you see nothing here.  While you wait patiently, check out these Arduino projects I made for our "Pathways to Paychecks" events for High School students: djArduino, moodLight, and the ever popular arduinoTwitterBot