2015-August-03– I wrote up this Cricket article for a Maker Camp project I created for the Novato library, July 2015.
What we’re building
A “cricket”! It’s all digital, using an 8-pin microcontroller and just a few other components. A “microcontroller” is like a tiny computer, complete with processor controleld by a program, some memory, and peripherals like timers and inputs and outputs.
I wrote a program for the microcontroller to make it act like a cricket. That means it will chirp when the lights go down. When it gets really dark it chirps louder and faster. If the lights come on, it gets scared so it stops. If it’s been chirping for a few minutes and the lighting has not changed at all it will fall asleep.
Before we start: How solder joints should look.
These were done by someone (Julie, my wife) who practiced soldering for about 20 minutes. They are not perfect but they work. Your solder joints need to have a smooth shiny appearance. If they are dull grey or rough, they might not work. You can reflow the joint by heating it again and applying a little more solder.
You need ENOUGH solder but not big massive blobs.
We’re using “dead bug” style construction. We turn the PIC upside down so its legs stick up in the air like a dead bug.
Bill of materials
- Microchip 10LF322 microcontroller in the 8-pin DIP package
- 1/4 watt carbon film resistors: 1K and 10K
- Piezo buzzer
- CR2032 button battery and holder
- Four pieces of hookup wire, about an inch long each. I used 24 gauge solid conductor.
- Something to hold all the parts; I used an Altoids tin, it’s sort of traditional
PIC 10LF322 is an 8-bit microcontroller made by Microchip.
The piezo speaker bends when voltage is applied to it, bend it fast enough and it makes a sound.
Resistors are devices that limit current.
A photoresistor is a special resistor that can detect light and varies its resistance.
Each resistor has a color code to tell you what its value is in ohms. For the cricket we need two, 1K = 1000 ohms and 22K = 22,000 ohms.
For Maker Camp, I preloaded a program into the PIC microcontroller that makes everything work. If you are reading this on the web site, I would be happy to provide more information on the program and how it gets loaded, or to send you a pre-programmed PIC. The program is written entirely in the C language and it’s maybe a hundred lines of code.
We’re using “dead bug” construction. It’s called that because when you flip the PIC upside down with its legs sticking up in the air, it looks like a dead bug.
Using dead bug construction will make this project cheap and quick to build. The downside is, it’s also easier to break pins off the PIC and harder to reuse parts.
To reduce the chances of messing up, we will build parts first into 2 subassemblies, then attach those subassemblies to the PIC.
The first subassembly is the speaker.
We have to attach a wire to one lead of the speaker and the 1K (RED-BLACK-BROWN-GOLD) resistor to the other lead.
It’s easiest to solder the resistor to the speaker and then the wire to the speaker as two steps.
Step 1: attach resistor to speaker; use either pin on the speaker.
Step 2. Attach a wire to the other speaker lead.
The second subassembly is the light sensor.
Together, the photoresistor and the 22K resistor form a circuit known as a “voltage divider”.
When we’re done, the photoresistor goes to the + side of the battery and the resistor to the – side.
The wire lead goes to the input on the PIC controller. Put the three parts together like this then solder. That is, attach a wire and the 22K resistor to one of the leads on the photoresistor by crimping them with needle nose pliers, then solder the joint in one step, this is better than trying to solder one part, adding the second and soldering it, because the first joint will fall apart when you heat it the second time.
Next The sensor gets attached to the battery. DON’T SOLDER YET. There are more wires to add.
Add a wire to each terminal on the battery holder. Use a light color (I used yellow) for “+” and a dark (purple) for “-“. The standard is to use red for “+” and black for “-” but I did not have red and black.
The battery holder has a little “-” in a circle near the “-” terminal. Of course, if you get the wires backwards, nothing will work.
After connecting the resistors and wires your battery should look something like this.
If the wires don’t fit through the battery tab holes then just attach them onto the resistor leads, near the battery holder tabs.
Now solder everything. Solder should flow over the whole joint, you need more here than anywhere else in the project.
Here is the back of the battery holder. Solder flowed down over the whole tab.
Now onto the heart of the project. The controoler. The PIC controller has eight pins. Pin 1 is marked by a little dimple.
From the top… (I need to add a diagram here.)
As a dead bug… upside down
You HAVE to keep track of pin 1 once you turn things upside down else NOTHING WILL WORK!!!
The way I did this was by putting a DOT on the can with a Sharpie marker, then gluing the PIC down so that PIN 1 is NEAR the DOT. Another way is to actually color pin one with the Sharpie– we won’t be soldering anything to it anyway. Here’s how I marked my tin can.
Next you need to glue the PIC into the can. Use hot melt glue, and do this QUICKLY — the cold metal can will cause the glue to glob up and harden fast. If that happens just peel off the glue and try again. You DON’T want the PIC to fall off in the next step, so use a good size blob.
Now attach the leads for the speaker assembly to the PIC.
6 3 ———– speaker
5 4 ———– 1k resistor
After soldering, carefully bend leads to position the speaker inside the lid. It has to be far enough inside so the lid can still close.
Then glue the speaker down. This will just help keep everything together so it won’t get broken as easily.
Don’t short out the metal connections to the can.
Mount the battery in the can.
Some of these cans have paint on them but to be on the safe side, I put a piece of tape down to insulate the battery terminals from the metal. If you short the battery terminals together, the battery will go dead in about a second.
So first put down a piece of tape and then glue the battery to the tape. Pin 2 on the PIC gets the “-” wire and pin 7 gets “+” so position the battery / sensor assembly to make it
convenient to hook the wires up.
After the glue has set, carefully bend each wire around and attach them to the PIC. Solder.
Again that’s PIN 7 = YELLOW (“+”)
and PIN 2 = PURPLE (“-“)
As I said earlier, normally RED = “+” and BLACK = “-” but I did not have red and black. The electrons only care if the wires are hooked up correctly.
All the wiring is now done. The battery looks like this.
Pop in the battery with the “+” side UP (visible when in the holder).
The cricket will make a beep as soon as the battery is plugged in. Then it will start chirping. The cricket wants to be in dark places, so if it does not start chirping try closing the lid on the tin or turn out the lights in the room.
To make the battery last longer (and to be less annoying!) if the
lighting is not changing then the cricket will stop in a few
minutes. Waving a flashlight at it or shading the sensor (any significant change in lighting) will wake it up and it will start chirping again.
That’s it, we’re done!
This device is a “cricket” only because of the program loaded into it. With this hardware, it has the ability to sense light and temperature and to make simple sounds. (I did not use the temperature sensor in the final version of the cricket program.)
What else could this hardware do?
Example: it could be an alarm for an open door on a refrigerator. It would sense light when the door has been open for say 5 minutes and then start beeping. Then when you close the door and it’s dark, it would stop.
All you’d need to do to make the cricket into a refrigerator alarm would be to write and load a new program into it.
What is your idea? Leave me a comment.