Introduction: Laser Operated Nest Box Visit Counter
We have a bird nest box close to our terrace which has been used by a Great Tit (Parus major) couple during the recent years and we hope to have them back breeding this year. However, the box is in a bad condition and hast to be replaced sooner or later. As a scientist I couldn't resist having a box with a counter measuring the activity of the birds at their nest. Although it is located close to our house, I would not like to have a cable connected to the counter and thus decided on a battery powered device. As I do not want to disturb breeding, the device has to run on a single pack of batteries throughout the season and thus has to be limited in power drain. So it's an ATTiny85 processor instead or a full grown ARDUINO.
I thought of a method to switch the display on and off without going too close to the box - that is where the laser comes into play...
The video shows the box in action. The rightmost LED shows when the lightbarrier was triggerd. The LEDs have different colors with different colors and position representing different digits. When the laser hits the sensor all LEDs blink three times indicating that the actual number of visits will be shown shortly. Each of the first five LEDs represents a digit, so 99999 visits can be counted. In the video you see LED 3 blinking once, LED 4 blinking twice and LED 5 blinking four times - that is 124 visits.
For parts list see Appendix (Step 7)
Step 1: Building an IR Light Barrier
IR light barriers are cheap and fairly easy to build. You'll find great tutorials here:
Here are my two cents on what to keep in mind building a IR-light barrier: First of all, you can not see IR light but your camera can. The image above was shot with my mobile phone, I use the non-filtered camera to check if my IR-diode is working. Second, IR is all around you. So while building and breadbording the light barrier, your sensor will most likely be hit by other sources of IR light than your IR-LED! Some time ago, I spent hours debugging a circuit over and over again until I finally realized that the sun was shining on my IR sensor...
I here used a matched pair of emitter and detector (Temic K153P), a 220 Ohm resistor for the emitter, and a 10k resistor for the detector. Other brands will work, too.But you have to figure out the right resistors for your setup, depending on the diode and sensor you have. Of course, you can read the manual of the sensor (well, who reads manuals?) or you might just play with different resistors for finding a good threshold for the sensor. Keep in mind to shield the detector from other IR light sources - this will save you so much time!
The second picture above shows a simple circuit connected to an ARDUINO. Here is a simple test sketch for reading the IR sensor:
//connect an IR LED via a matching resistor (usually ~220 Ohm will work) to 5v and GND
//check with an unfiltered camera (e.g., mobile phone) if it shines
//connect the IR sensor to 5v and via a resistor (e.g. 10k) to GND
//connect the second leg of the sensor also to A0 of the ARDUINO
Serial.begin(9600); // open serial
IRVal = analogRead(A0);
Load this sketch to your ARDUINO and open the serial monitor as shown in the third picture above.
When everything works, the lightbarrier should be protected from other light sources, e.g., by mounting them into such aluminum tubes as shown in the last two pictures.
Step 2: Preparing the Laser Operated Switch
A photoresistor is a light-sensitive resistor, i.e., the resistance changes according to the intensity of light. The difference to the IR-sensor is that the latter is specific to the wavelength in the Infra-Red spectrum of the light while the photoresistor is sensitive to a broader band width. Of course you can use a specific sensor for the wavelength of your laser pointer - I just used what I had at hand... The idea is, that we will hit the photoresistor with a laser, detect the rise in resistance, and use this signal as a switch.
The first picture shows the resistor on a breadbord, connected to 5v and to ground via a 330k resistor. The latter leg is in addition attached to the Arduino A0 for testing light and resistor values using the same sketch as in the last step.
The second picture shows a piece of tube that will cover the photoresistor in order to prevent daylight from triggering. As this tube will be mounted on the outside of the box, I recommend using a longer tube. I drilled two holes for the legs and stuffed the backside with aluminum foil and sealed it with polymorph (the white globuli in Pic 2; if you don't know polymorph, google it (or see DIY Material Guide), and buy at least 250g of it - it will change your workshop life!). The last picture shows the testing sketch using an Arduino. The low values are from the covered photoresistor, the high values were recorded directly facing the light.
Step 3: Building a Box
I will not go into too much detail on how to build a nest box in general. Please see
for some good examples. However, there were a few special features that I liked my nest box to have. So I will run through building the box quickly with emphasising the fancy details.
It all starts with a pile of wood (Pic 1). Having a good saw helps. Mine is a little bit weak, so I used thin plywood. In order to stabilize, I glued square shaped bars to the corners (Pic 2) and drilled in some screws (Pic 3) in addition. The front should be completely removeable because it will hold the electronics that might need maintanance later on. I use magnets to hold it in place. Therefore I drilled four 6mm holes into the box and four into the front plate and glued in neodymium magnets.
Next step was to drill the entrance. I use a 4cm drill/cutter (whatever the English word is, see Pic 5).
On the inside of the front plate I glued the IR light barrier (Pic 6). I had to cut in two slots to the bars in order to get the box closed. On the front plate I built a case for the electronics by cutting out the inside of 4 plywood squares (Pic 7, 8, 9). The first one has holes on top where the cables from the IR light barrier will go in.
at the time I build the case for the electronics I did no decide where to put the laser-operated light sensor. I attached it to the bottom of the case later by carving of some of the material with a Dremel and drilling two small holes into the bottom for the cables.
Step 4: Building a Charlieplexed Display
The ATTiny85 that will run the counter has 8 pins. One is for VCC, one for GND and one is a RST (reset). The RST can be made available as a usable pin, but at the cost of the ATTiny not being easily re-programmable. This leaves us with five pins for input or output. We need two pins to read the IR light barrier and the light resistor for the laser switch. So how can 6 LEDs be powered with 3 legs? The answer is Charlieplexing. Basically it takes advantage of the possibility to change not only between high and low OUTPUT state but also to use the INPUT state of each pin. Every single LED can be accessed by putting its anode to high and its cathode to low and turning off the third line completely by setting it to INPUT. Since a LED only work in one direction another LED can be soldered to the same pins in opposite direction without being lit. So, you cannot have both LEDs on at the very same time but you can change the HIGH/LOW states of the pins so fast that the human eye will perceive it as if both were lit at the same time. The same applies for lighting all six LEDs at (almost) the same time. That's it for the theory from my part. You'll find better info following these links:
Figure 1 shows the scheme you'll need to solder the "display". The table explains how to set the pins in order to power each LED. Soldering such a display is a mess. I started with soldering the LEDs and the resistors (I used 220 Ohm, but it depends on the type of LED). The status LED (number 6) is a little bit more to the right.
I then wired from leg to resistor following the scheme above. I added two pictures of the wires andg the soldered backside but you'll probably don't find this too easy to follow. Following the scheme worked fine for me.
The display will sit on the backside of the front cover, inside the case with LEDs facing to the outside. I measured the center of the coverplate and of the display and drilled six holes (3mm) where the LEDs shine through. I realized that the wire and resistors were in the way. I thus used a Dremel tool to carve out a recess.
Update: While considering the power consumption, I realized that the IR-light barriere will be the most demanding consumer if it were powered on constantly. Actually, the light barrier will only be checked every 250ms - so there is no need to have the IR LED running all the time. Therefore I decided to discard the leftmost digit of the display and use the free virtual LED pin to turn the IR LED on and off.
Step 5: Soldering the Mainboard
The "mainboard" holds the ATTiny85, the resistors for the IR light sensor and the photoresistor and connects everything with the battery pack. I highly recommend using an IC socket for ease in reprogramming! I also included a DIP switch to turn the board on and off. You might want to use a battery pack with a switch instead. The figure above shows the connections. The real product looks less impressive owing to my limited soldering skills...
Step 6: Programming the ATTiny85
I did all the prototyping on a ARDUINO board. The final project, however, should be on a ATTiny85 in order to reduce power consumption, size (well, a ARDUINOmini board would also fit), and costs (< 1 Euro for the processor). Programming an ATTiny85 is quite easy using the ARDUINO environment and an ARDUINO as ISP. There are a lot of good tutorials following the links below, so I will not elaborate on this part.
The power consumption of the ATTiny85 is already quite low (~0.8mA running at 4.5V at a clock speed of 1MHz). However, if it has to run for months without draining the battery too fast we should save some more energy. In idle mode the ATTiny85 uses only about 0.18mA. Therefore, we will send it to sleep for most of the time and just wake it up for checking the sensors every 250 milliseconds. In addition I soldered the IR sender to the charlieplexed display replacing LED 1. By this means, I can turn on the IR LED (~20mA) for only a few ms (8ms per second). A rough estimate of a mean consumption of 0.25mA per hour will result in 250 days using a battery pack with 3 AAA batteries at 1500mAh.
I attached the current version of the software running the nest box counter. I will probably update this after testing the box for a few days and probably again after one season in real life. The sketch is richly commented - any comments, suggestion, and improvements are welcome!
Finally I painted it several times using clear coat. I also used the clear coat on the backside of the mainboard and the display in order to prevent short-circuits in case of water inleakage. I'll keep you updated if anyone moves in...
Step 7: Appendix
Here is a list of parts I used for electronics:
- IR sender and receiver-LEDs (different colors)
- Resistors (e.g. 330 Ohm for the charlieplexed display, 330k for photoresistor, IR receiver)
- 5 (was 6 before I moved one port for the IR sender) LEDs (differnt colors)
- Shrinking tube
- Socket holder
- Battery pack to hold 3 AAA batteries
For the nest box I used
- Plywood (<1m^2)
- Square shaped bars (~80 cm)
- Aluminum (or other meterial) tube to cover light sensitive parts (<20 cm)
- 8 Neodyme magnets
The total costs of material used was below 7 Euro/10 USD.