Honey Bee Counter

71,719

151

53

About: just have to figure out how all these things go together....

Intro: 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

See the improved design here: Honey Bee Counter II


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.



Step 1: 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..

Share

    Recommendations

    • Optics Contest

      Optics Contest
    • Plastics Contest

      Plastics Contest
    • Audio Contest 2018

      Audio Contest 2018

    53 Discussions

    0
    None
    diy_bloke

    2 years ago

    interesting. Just came across an article that used capacitive sensors in order to count bees with an arduino. I guess both (capacitive and optical) have their pro's and con's

    0
    None
    veggy37

    3 years ago on Introduction

    why doesn't the stl file for the turnstiles come out the size required? surely it should be the length of the pcb? whereas it is barely mm in size!

    1 reply
    0
    None
    DylanC11veggy37

    Reply 3 years ago on Introduction

    Solution: Scale every dimension by 25.4 (which is the conversion ratio for mm to in)

    0
    None
    dzikursh

    3 years ago

    Any chance you would share the version 2 schematic?

    0
    None
    zardiw1

    3 years ago on Introduction

    Wow. Great Project!!.......I wonder if you can add a wireless function.....maybe link the USB wire to a RF Transmitter away from the beehive......so you can watch the activity in your house on a monitor..........z

    0
    None
    gtoal

    3 years ago on Introduction

    This does everything my colleague wants except for one thing: he wants to be able to determine the approximate amount of pollen each bee is bringing in to the hive. Is there any tweak to your IR system that might allow that or are we definitely looking at using a camera and something like OpenCV? (I'm thinking the PiNoir and Raspberry Pi would be a suitable combination)

    0
    None
    dzanches

    4 years ago on Step 3

    Congrats on such excellent work. I also have built by own "stingless bee" counter using Arduino-based stuffs. It performs great when the traffic of bees is low, but when a food source is discovered, lots of bees exit and enter the colony, so they have to stand in line, in a snake-like fashion, waiting to pass through the counting channel so the sensor "thinks" this is one individual, and counts one, instead of 4 or 5 . Have you had the same problem? As a remark I have to add that you cant use more than 5 channels to count stingless bees given their nest entrance is just one or two centimeters in diameter. I really would love to have a foraging force in my colonies like in your video, would make things easier to my counter. cheers

    1 reply
    0
    None
    DavidP9dzanches

    Reply 4 years ago on Introduction

    I too am interested in how to discern each bee when traffic is high and they are flooding out. I want to detect swarming.

    0
    None
    msubees

    4 years ago on Introduction

    Thanks for all the instructions....I wonder if I order 6 from you, how much total it would be? thanks! Zach (bees.msu at gmail)

    0
    None
    veggy37

    4 years ago on Introduction

    Many thanks for the super quick response.

    Let me know the cost of buying a board from you.

    0
    None
    veggy37

    4 years ago on Introduction

    I am currently going through trying to build this to a certain degree and experimenting. I have however come up with a couple of issues.

    1. there is no bottom solder mask file in the gerber files! should there be one? I am being asked for one when trying to manufacture a board!?

    2. not sure if your understanding goes as far as to know if QRD 1114 would be just as good as the 1113 you use, in that I can get these with legs as opposed to the smt version the 1113 is available in?

    3. do you have the full schematic in a .sch file as opposed to the .jpg ?

    4. I am looking at running it at the hive from batteries, do you have any idea on the current draw of the whole thing?

    5. On your original build the 'gates' look like they are made from compressed foam cut into blocks am I close or is there something more suitable. am worried the bees will chew through it in time?

    Many thanks, brilliant project!!

    1 reply
    0
    None
    hydronicsveggy37

    Reply 4 years ago on Introduction

    Hi, I've shared the eagle files on Oshpark here: https://oshpark.com/shared_projects/fX1p64yL. Send me an email if you want more details/cad files, etc.

    I also have a couple of boards that I can sell you that I've been hanging on to. The power draw is about 75ma with the current code and schematic. There is a battery discussion below. There could be a lot of improvements. Pulsing it could get you down to less than a miliamp.

    The 'gates' are made from ABS. I recommend you 3d print them. You can go to your local Maker or Hacker space and they might help you out.

    Digikey has the QRE113 in stock: http://www.digikey.com/product-detail/en/QRE1113/Q... The geometry for the QRD113/114 have closer pins. You'll have to compare the electrical differences yourself.

    0
    None
    skm1099

    6 years ago on Introduction

    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?

    4 replies
    0
    None
    hydronicsskm1099

    Reply 6 years ago on Introduction

    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.

    0
    None
    skm1099hydronics

    Reply 6 years ago on Introduction

    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

    0
    None
    hydronicsskm1099

    Reply 6 years ago on Introduction

    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.

    0
    None
    twmableshydronics

    Reply 5 years ago on Introduction

    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

    0
    None
    milw

    5 years ago on Introduction

    did you or skm1099 find any collaborators? I'm getting my first bees soon and am interested in potential business development.