Instructables

Honey Bee Counter

Featured
Picture of Honey Bee Counter
Where the honeybee's division of labor has stayed on a steady progression for 25 million years... our human superorganism has grown more complex and in all directions... hence the bee counter... By:  thomashudson.org

Live data from - June 25, 2012
I've moved away from live data... my version 2 has an SD card and I'm partnering with a university to do some research... feel free to make your own WIFI enabled swarm detector and I'd love to partner someone that wants to sell them to the masses.



 
 
Remove these adsRemove these ads by Signing Up

Step 1: Manifesto

Picture of Manifesto
Bee Counter - Version 2, October 14, 2012
 - micro SD datalogging
 - real time clock turns OFF the counter at night for reduced power
 - decoupled the LEDs from the microcontroller to reduce average power to 6.6 ma when not in use
 - small battery will last for months
 - solar cell power ready
 - unlimited temperature sensors
 - can perform estimates of size of the bee (worker vs drones) and therefore monitor drone/worker activity
 - 3D printed turn-styles or gates
 - for sale complete without battery $400 or make your own (see below)



Here are the specs for Version 1. This instructable details out Version 1 which is easily upgradable to version 2 though I've not provided complete plans.
-  95% Accuracy
-  Runs off USB power
- should be rain resistant with a top cover
-  bees adapt to new opening in a few minutes
- real time monitoring on google docs
- USB connection dumps data onto your laptop text file

Here's the plans to build your own. There are general instructions for prototyping or you can go to the circuit page and copy my exact board and circuit.

1. Buy a couple of infrared (IR) sensors
      - Sparkfun: http://www.sparkfun.com/products/9542
      - Get some 30K 50K and 100K resistors for testing the digital input sensitivity..
      - Get some 10 , 20, and 50 ohm resistors for powering the IR LED

2. Prototype your parts with an Arduino
      - I used a dead bee on a wire
      - its an easy circuit

3. Select a Microcontroller... I used the Teensy ++
      - same user interface as Arduino..
      - has 46 inputs/outputs,
      - its cheap, and
      - designed locally here in Portland..

4. Design your Printed Circuit Board with EAGLE for free
      - i took a 4 hour class at dorkbotpdx.org here in Portland. the software is free.
      - have it printed through dorkbot in Portland $45 for 3 boards
      
5. put everything together
      - solder your components on the board
      - calibrate your sensors
      - fine tune your programming

Rough cost and components for my board ~ $110
Printed Circuit Board $45
- qty(44) QRE1113 IR Sensors $33
- Teensy ++ $24
- resistors and pins $10
- my time $ouch!

Message me if your interested in me putting together a kit as it would probably be $130 if you want to do the soldering and hot glue gunning yourself!

Step 2: Circuit

more details to follow but its super simple...

Sparkfun sells the Infrared sensor or IR sensor. It is an LED AND a Sensor! crazy useful!.

When the bee crosses under the LED the light is reflected back to the sensor..(its a photo transistor) and triggers a digital input to the Arduino.. (or teensy in my case).

I lined up two chips right next to each other... as the bee goes through the gate if it hits the inside sensor first... its going out.. if it hits the outside sensor first its coming in. More on the programming...

See the full schematic and GERBER files attached.

- I used 4 LEDs in series with one 10 ohm resistor at the end.. that equals 1.2 volts drop per LED. 
- you can check your LED voltage drop with an online web tool like this one
- if you end up building the same set up as me you can get the IR sensors for a little cheaper through Digikey here.
- Pololu also sells the same IR sensors on a board (array) and they have code and examples here.
- per the large schematic below, I used 100k ohm resistors to ground. this increases the sensitivity. If you use a smaller resistor it becomes less sensitive. It is an NPN Phototransistor.

Rough cost and components for my board ~ $110
- Printed Circuit Board $45
- qty(44) QRE1113 IR Sensors $33
- Teensy ++ $24
- qty(11) 10 ohm 0805 resistors
- qty(44) 100k 0805 resistors
- 26 headers and 26 pins for attaching the Teensy to the board $3
- my time $ouch!

Message me if your interested in me putting together a kit as it would probably be $150 if you want to do the soldering and hot glue gunning yourself!






Step 3: Programming - easy

The Teensy is programmed in Arduino... or C++ but I'm a little familiar with Arduino...

The code is attached below.


/*
This is for the first two gateways: A and B.
*/
// this constant won't change:
const int ain = 44;                   //pin 44 is the first digital input for Gate A
const int aout = 45;                 // pin 45 is the second digital input for Gate A
const int  bin = 42;                  // same for Gate B
const int  bout = 43;                // same for Gate B

// Variables will change:
int ins = 0;                                // counts ins and outs
int outs = 0;

int ai = 0;                                  // Gate A 1st pin status
int lai = 0;                                 // Gate A last status of 1st pin
int ao = 0;                                // Gate A 2nd pin status
int lao = 0;                               // Gate A last status of 2nd pin

int bi = 0;
int lbi = 0;
int bo = 0;
int lbo = 0;

int count = 0;                                   // this just tests if there has been a change in our bee count
int lcount = 0;


void setup() {                                   // initialize the button pin as a input:
  pinMode(ain, INPUT);
  pinMode(aout, INPUT);
  pinMode(bin, INPUT);
  pinMode(bout, INPUT);
 
                                                       // initialize serial communication:
  Serial.begin(38400);                     //a bit different than the Arduino here.... 38400
}

void loop() {
  // read the pushbutton input pin:
  ai = digitalRead(ain);
  ao = digitalRead(aout);

  bi = digitalRead(bin);
  bo = digitalRead(bout);
 
  if (lai != ai){               // has the status if the 1st pin changed?
  if (ai > ao) {               // if yes, is the bee going in or out?
    ins++;                     // if its going in add one bee to ins
  }}
  if (lao != ao){
   if (ao > ai) {
    outs++;
  }}
   
if (lbi != bi){
  if (bi > bo) {
    ins++;
    }}
if (lbo != bo){
  if (bo > bi) {
    outs++;
  }}
 
lai = ai;                        // updates the last status
lao = ao;
lbi = bi;
lbo = bo;

count = ins + outs;

if (lcount != count){           // if the count has changed we print the new count

      Serial.print("number In:  ");
      Serial.println(ins);
      Serial.print("number Out:  ");
      Serial.println(outs);

lcount = count;
}
}

I added a debeebouce sequence.  Here is the latest calibration video from today 06/26/12. Its 91% accurate but there is still a little room to improve:
 

Step 4: Data Logging on Google Docs

I used Processing to upload the data real time through a laptop...... Here is the first data I got... 
- Live Date from today June 25, 2012

The values are uploaded via the code attached.  The general idea is to use a 'formkey' link that is accessed when filling out a Form for Google Docs.

1) log onto google docs
2) create a new FORM with as many inputs as you have data points
3) go to the 'live form' and review the source code... look for the 'formkey' and the input identifiers... here is what I found:
4) its easy to figure out once you get the source code and start cutting and pasting values right into your browser to test your assertions... try its pretty powerful.. 

In Processing (you can probably post it right from the Arduino but I thought I'd try in Processing ..)

String [] docs = new String[8];                                     //this 'string' just puts all the pieces of the URL together 0 through 7 or 8 total....
docs[0] = "https://docs.google.com/spreadsheet/formResponse?formkey=dHNHNWtZQ3lJSzFCZ1kyX0VVVmU0LUE6MQ&ifq&entry.0.single=";       //this is the formkey from the FORM source code
docs[1] = pairs[1];                            //this is my first data point # of bees IN.
docs[2] = "&entry.1.single=";           //this tells google doc my first my 2nd variable comes next... search the source code to figure out but it will look similar...
docs[3] = pairs[3];                           //this is the second variable # of bees OUT.
docs[4] = "&entry.2.single=";           //this tells google doc my 3rd variable comes next..
docs[5] = Delta_in;                          // # of bees in minus last number of bees in
docs[6] = "&entry.4.single=";
docs[7] = Delta_out;
String docs2 = join(docs, "");
loadStrings(docs2);                 //once you put all these bits together it posts your spreadsheet!!... test your own bits in your browser...  I have it posting every 5-10 minutes...

I attached the processing code... I still need to change the INT variables to FLOAT because after a few hours the values exceed 32,000 bees!!! woops..
hydronics (author) 1 year ago
New York Maker Faire was a blast... thanks all!
IMG_3503.JPG
skm10991 year ago
I and my son built one of these, with just 2 "gates" to try it out, and it works.

There are 2 problems with the idea of powering it from a usb cable.
1. USB cables are usually 6' long, which means your laptop for collecting the data is only 6 feet away from the hive. If you have 110v ac nearby, you can use a powered USB hub and get 12' away from the hive to collect data and for power, but that is still not very far. I've seen a lot of hives in the corners of fields that were hundreds of feet from a power source.

We did some calculations and with 22 gates (44 sensors) an 8-pack of rechargeable "c" cells will last less than 20 hours, which is not nearly enough for observing bees on a daily basis (unless you change the batteries 8 times a week).

USB works for a few sensors, but not 44 of them.
If anybody wants to know, my son (who has several degrees in engineering and related fields) can post the math involved.

putting 4 sensors with one resistor leaves you with only .2 volts of headroom above what the diodes draw at nominal values. There is a chart in the data sheet, figure 8, that shows the forward voltage vs Ambient temperature. Taking the temperature into consideration, say from 0 degrees to 100 degrees F. times 4 (for 4 sensors in series with 1 resistor) you can easily need more voltage than a USB hub can supply.

If you figure adding other things to be powered with this counter, such as temperature/humidity sensors, a readout screen, or anything else, you could be above the power available on even a USB powered hub.

We ended up with a 9v wall wart transformer capable of 1 amp. and calculated that that will work at temperatures from 0 to 100F with power to spare for an lcd screen, etc.

With the 9v wall wart, you get less than 3ma variation between 0-100F. With a 5v USB, allowing for temperature variation you can have about 100 ma variation.

But that links us to an extension cord and 110vac all the time.That may work for some Bee Hives, but probably not a lot of them.

We looked at a car battery, and it worked out to a week of life before needing recharged. Ant then you have to lug a car battery into the field with you to change it out once a week.

Also, when figuring the number of sensors needed, you would have to consider that bee hives comein 2 common widths, a ten-frame hive and an 8-frame hive. The width will be 2.5-3" different, so the maximum number of "gates" will be different.
We have 8-frame hives and using 3/8" width slots and 5/16" spacers between slots, we can get about 19 gates. Certainly enough for the bees, but it changes the power calculations as well as the size of the circuit board.

I was also thinking about the speed necessary to read 44 sensors and update the counts, but my son suggested if we use the atmel commands, instead of the arduino built in port reading, we can read 8 ports at a time, as that is the way the chip reads them--as a byte.

I have an idea for a case that I can make to take care of waterproofing everything, so that shouldn't be a problem.

We still need to find a way to get the data without going up to the hive and plugging something in or removing an sd card.

Has anybody else built one of these, even as a prototype?
hydronics (author)  skm10991 year ago
Hey SKM... nice work. I like where you are going. For my urban backyard bee hive I just leave an old laptop out next to the hive and the bees provide the security :)... The university I supplied the counters to also suggested a remote logger and external battery source. They want to use a Hobo-dattalogger as that's what they currently use though I agree with you that an SD card might do the trick just as good... we've not decided on a direction as of yet. As far as power goes, I measured the power usage around 97ma but if I turn off the USB communication it drops down to 75ma... I estimated that a 12volt 12AH battery will last 12.5 days.
Thanks,
still working on it some more.

I got the SD card modules off ebay for $2.95 each, and small sd cards are about $5 now. There is a library already for writing to an SD card with the Arduino, as well as examble code in the back of the book I bought: "Arduino Cookbook".

There are things to consider in code, what happens when it tries to write to the sd card you just pulled to exchange it, or what you do if you power down to change the sd card, etc. as well as how to make the sd card removable but watertight for during storms.

We did battery calculations too, and came up with shorter times than you did by a good bit. I don't know who is closer to actual battery life, lots of variables, but it seemed from the data sheets that your estimated battery life is close to maximum.

It also seems from the data sheet that 1 millimeter is a good sensitive range from the sensor and it looks like the bees might have more than that amount in height in the prototype, but it could be just optical illusion.

What dimensions did you use for the gates, and what width for the blocks? We figured .312 for gates and .375 for blocks for calculation purposes. And our hive is an 8-frame instead of a 10-frame, so that affects our total width. We went with 8 wide so the full supers don't approach 100 lbs in weight when full for harvesting.

How many sensors were in the unit that gave you 75ma draw?

Thanks for the link to the hobo-datalogger, I'll check it out. What University were you supplying? Do you know what they were using them to research?

If I wanted to send you a file, where would I send it?
SKM
smitchel at bnin dot net
hydronics (author)  skm10991 year ago
I think you are correct, that an SD card would be a better fit for the University. They wanted to use a HOBO but why not just incorporate the SD card into the microcontroller and call it good. Here is a link the the one that fits the Teensy++.  I might build one for my self too.

I was thinking the better option for the backyard bee keeper.. would be to incorporate a swarm alert email... for this to work I thought it would be nice to use a WIFI card... maybe something like this: https://www.sparkfun.com/products/11049

 
 The hardware is easy but the software takes a bit more thinking... I'm just not too interested in designing a complete product for sale. Sounds like a lot of work. I'd like to partner with someone who might be interested in this route.

The power measurements were done with all 44 sensors running. it measured higher amperage when the USB communication was running.
Hi Thomas,

To be honest you really have the best cool idea. I salute you creativity...

I not much a software guy. Sure like the sound of it using WIFI. Can I ask you some question as following:-

a) why you do using Arduino Mega 2560 you can pot a WIFI Shield more easy and simple?

b) Why Teensy++ it is better then Arduino.

About the partnering, I may help you. Could drop me email tsang.waimeng@gmail.com. we can further discuss from there. Hope to hear from you soon. Warmest Regard Tsang
Kelly029 months ago
Amazing! Nice work!
milw12 months ago
did you or skm1099 find any collaborators? I'm getting my first bees soon and am interested in potential business development.
milw12 months ago
did you or skm1099 find any collaborators? I'm getting my first bees soon and am interested in potential business development.
_bio1 year ago
Is there any change on the PCB / linked Gerber file in Version 2.0, I think there may be one if you talking about decoupled LEDs? Is this layout also downloadable?

Is the worker vs. drone recognition only done by the speed switching the two IR sensor? That means that the bees past the two gates by a average constant speed. Did you see this in the previous data? Interesting!

May you post the modified code for version 2 with bee type recognition. Is there also a 3D printing file for the gates downloadable?
hydronics (author)  _bio1 year ago
I added the STL file for the 3d print. I wasn't able to upload the sketchup file but I can send it to you if you message me.
hydronics (author)  _bio1 year ago
Hey, just messaged you. the worker vs. drone recognition is definatily a good bet at this point because it is still winter and I've not fully tested the programming... you are correct they'll be a speed test. There are two sensors so I could use the distance between the sensors to measure speed or just estimate... (right now i'm just estimating)..

I can send you the 3d gate file. send me an email that I messaged you. -tom
JensonBut1 year ago
This is very interesting and a bit strange but still very interesting something worth researching guess I'm gonna need to conduct my own study
hydronics (author) 1 year ago
I was at the min-maker faire Victoria last weekend... so much fun. Have you ever brought your project to a mini-maker faire? It is so much fun!
mini Victoria 2.JPGmini Victoria1.JPG
slobak1 year ago
This is awesome! Definitely going to think about trying this. Thanks so much for doing all the research and writing it up.

Has anyone figured out a way to track where your bees are foraging?
dotbaz1 year ago
This is great!

I had a go at doing this but not so good with hardware, so now working on a version tracking bees in the vicinity of the hive with a video camera - first results here: http://www.youtube.com/watch?v=o3a1_6tIAvA.

I might just build this now....

Cheers. Barry.
beePath-0023.jpg
skm1099 dotbaz1 year ago
Hmm. We have Yellow Jackets that actually land on the front of the hive. They don't go in, but are looking for any spilled sugar-water from the quart size hive feeders that sit on the from of new hives. When I last had the suit on and was checking them, we also have a few flies buzzing around the front of the hive that would be in the field of view of a camera.

I was wondering if the video method you use has a way of checking that it is counting actual bees, or is it counting flying insects?

Great video and congratulations on getting the video counting/tracking going.

It looks like you know some about web cams, I have wanted to put one inside the hive, but the problem is the focus. It would have to focus a couple of inches in from of the lens. Do you know any way to get an ordinary webcam to focus that close?

dotbaz skm10991 year ago
Currently it only looks for objects, but part of the calculations are to work out the ovalness of each bee. I think flies would look to be round all the time so it could be modified to weed them out I guess.

Don't know much about webcams but I'd think the problem you'd have would be light levels. To focus maybe try getting some old reading glasses and use one of those lenses in front.

You might want to look at these sensors http://www.omega.co.uk/ppt/pptsc.asp?ref=OM-EL-USB-1&Nav=dase01 just drop it in the hive and leave it! I believe the internal hive temperature is supposed to be kept at about 33 degrees centigrade, so might be a boring trace!

Cheers. Barry.
hydronics (author)  dotbaz1 year ago
that's so cool... are you using computer vision? what flavor... have you tried to convert the to number? I'm sure there is a correlation between the number of bees tracked and activity... but its pretty cool weather you get any data out of it or not...
Thanks!

I wrote it from scratch in c & perl using a c jpeg library to decode each frame. Haven't yet counted them, as I'm currently debugging a bit to follow the bee traces when they overlap.

Keen to build one of your counters. Cheers. Barry.
skm10991 year ago
The queen is much larger than the drones or worker bees. So much so,that she cannot fly while she is "laying", so the only time she would leave the hive (by flying) is during swarming, which bees do on occasion and can usually be avoided by adding a super on top of the hive, if during regular inspections you find they have filled up the existing space.

The queen's size is so different from every other bee in the hive that they sell a separator, a plate with a grid of holes, which bees fit through but queens cannot, that you put between the 2-3 supers that the colony needs to have full of honey to overwinter and the upper supers, where the honey will be stored (and that you harvest), so that the queen will not be laying brood in the area that you intend to harvest honey. I mention that to point out that how predictable the size of the queen is, and so much different than the resat of the bees. They are about double the size of regular bees.

So unless you make the gates big enough that a couple of bees can fit through (messing up your count), the queen won't fit anyway!

I'm going to make a couple of these, but I want to use a stand alone Arduino board, and also hook up temperature, humidity, light level, and maybe any other sensors that will tell me about conditions in the hive. Audio would be great if someone could show me how, as the pitch of the "humming" inside a hive tells what they are doing, i.e. they make a certain sound sound a week or two before swarming. If you know, you can act to prevent swarming and add a super. This was documented in a patent application as far back as the early 1950's.

An idea for an output more useful than an external display is to make it accessible by a cellphone.
This would be more useful as you might want to observe bee activity by the hour of the day, comparing to sunlight/cloud cover patterns of that day, so you might want a simple web interface to send the data to a nearby wifi network, like your house, to collect the data. Or use an SD card (on ebay for $5 or less) and write hourly data to that.

With the wifi boards available for the arduino, you could give your counter an IP address and check in on traffic, etc from an internet-enabled phone like the Nokia N900 without ever having to approach the hive.

That will take more power, so maybe add some more (AA or 9v)batteries to keep the runtime up into weeks instead of days.

I would like to collaborate with others who are building these now. I have some ideas for a case to keep things watertight, yet well enough attached that storms or skunks won't dislodge it.

skm
smitchel@bnin.net
hydronics (author)  skm10991 year ago
nice... can't wait to see what you come up with...
I wonder if it is possible to detect if a "marked" queen leaves and returns using this system.
hydronics (author)  boggystudios1 year ago
Yes! we could probably brain storm a few options to accomplish this... maybe version 2.0... I've heard of this but just saw this article today on tagging bees... http://www.rfidjournal.com/article/view/8466
RFID Bee.jpg
The ones that come with our nucs have some white paint on their back so I figured it would reflect more IR light back to the sensor. If it does then a little bit of testing and software adjustment could possibly accomplish this.
hydronics (author)  boggystudios1 year ago
yes, the white paint would definitively increase the reflection of IR as these sensors are incredibly responsive to color... Right now I have them set up as digital inputs without the fancy response mechanism that Polulu and sparkfun have built into their DI sensor boards (extra capacitors to sense distance)....one issue is if the queen passed through the gate upside down the bit of white would be facing the wrong way...
http://ohioline.osu.edu/hyg-fact/2000/2162.html
diy_bloke1 year ago
The sparkfun circuit is inherently different fro yours as the former seems geared to measuring the RC time for response while yeras is more of a voltage divider. Might ineed need to fiddle a bit with the resistor to make a digital signal from what could be considered an analog signal.
Wondering how you dealt with bees hovering in the entry, or is that in that 5% error margin?
hydronics (author)  diy_bloke1 year ago
Yea, bees do hover a bit from time to time and I had to tweak the code to keep them from double counting... yea you're right the sparkfun DI is pretty fancy as mine is pretty dumb but super effective... I think they use these sensors a lot in copy machines to tell where the paper is...
i love to see projects that combine tech with nature :) thanks for sharing this one.
got a little suggestion here, hope you don't mind... :P
the miss-count can be a results of a bee triggering one sensor then changing it's mind and backs-up. can bees walk backwards? :)

if a bee can trigger both sensor simultaneously, you might like to wait for this state, before increasing the ins/outs. something like:
if(lai=1 && lao=1)
{
if(ai=0 && ao=1)
ins++;
if(ai=1 && ao=0)
outs++;
}
can't test it but in theory it may offer a greater accuracy.
hydronics (author)  axodus1 year ago
They don't actually simultaneously trigger.. That said the loop is so fast.... I need to de-bounce the trigger a bit but it works pretty darn good as is... I'm pretty sure we'll be better than 95%... The guard bees do wonder but they're so over shadowed by the volume... Data is comming soon!
omnibot1 year ago
This is really cool!
If you could weigh the hive at the same time you could graph almost every aspect of the bees work and even predict production and determine health and activity of the hive over a year. This could be seriously scientific.
hydronics (author)  omnibot1 year ago
Sounds good... Go ahead... Version 2.0 is all you!
Foxtrot701 year ago
Excellent Work! Great idea forcing the bees to pass thru a divider gate system with IR sensors at both ends to track departure and arrivals. Hmmm...sounds like an airport concourse! LOL.
hydronics (author)  Foxtrot701 year ago
yea my buddy Mykle Hansen calls it a bee turnstyle.... thanks, tom
This will be a great way to help me keep track of my bees
This is just genius! Great work. :D
hydronics (author)  jessyratfink1 year ago
thanks :)
petrolhead1 year ago
I think bee keepers would actually buy this if you made them commercially.
If you put on a alphanumeric LCD display and make it completely stand alone. Could always power it via solar and this would be the greenest tech going!
hydronics (author)  petrolhead1 year ago
That would be cool... I'm putting all my energy working on a real time digital display of some sorts for the faire... I think you're right though.... there's a lot of interest in bee keepers having one themselves... I'm thinking about putting together a little kit for ~$150... I got a couple people interested... cheers, -tom

I like the solar idea for sure...
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!