Easy Bee Counter

22K15099

Intro: Easy Bee Counter

2019 Easy Bee Counter V.1

For Questions or Issues!! Please post them on the github site here!

This version of the bee counter is easy to solder and assemble (all through-hole). It's been tested and works* with sample code provided.

The current tested design is easy to program and approachable to beginner programmers. The printed circuit board accepts multiple Arduino platforms made by Adafruit including their line of Adafruit Feather type micro-controllers and Adafruit ItsyBitsy micro-controllers. The Adafruit feathers include wifi and long range radio features (esp8266*, esp32, and LoRA). All the ItsyBitsy 3V models (M0, M4, and 32u4) should work fine.

*The feather esp8266 is missing A5. If you use this uController you have to jumper to another available pin.

STEP 1: Data Analysis - Why Count Bees?

Possible Uses

  • the rate of expansion or decline of bee flights might indicate hive health
  • the expansion or decline of orientation flights over days might signal queen health
  • the time shift between peaks of bees leaving and returning might indicate number of foragers and distance to pollen/nectar source.
  • comparison between two or move hives to test for manipulations; such as,
    • adding/removing honey supers
    • internal sugar syrup feeding
    • oxalic acid mite treatments
  • introduction to electronics, soldering and micro-controller programming
  • honey bee education or museum type installation

Hive health

Equating bee flight data and orientation flights to over all hive health or queen health seems possible. Orientation flights is a behavior of 'middle aged' bees about 20 days old. Before foraging bees of this age will leave the hive as a group at around mid day resulting in an easy to see ~45min peak in data.

If there is a drop in orientation flights it might indicate a reduction in egg laying ~42 days prior (22 days hatch + 20 days till forage).

Foraging distance

It's easy to see in the data small but distinct shifts between bees OUT and bees IN. This indicates both a volume of bees that are leaving and returning together as well as a rough distance or time to the foraging location.

STEP 2: Improvements on Previous Design

  • All through-hole components for easy soldering
  • Dual footprint, socketed, off-the-shelf uControllers => Feather and ItsyBitsy
  • Program in Arduino, Lua, and microPython - A total of 24 gates, 48 sensors, 6 shift registers
  • ~14.75" long stretching the entire opening of a langstroth hive for easy placement
  • using 2 PCBs to create a sandwich is an inexpensive quick solution. The PCBs must be ordered black (see instructions) so the IR LED emitter is absorbed into the material.
  • using 6 pin headers to create the turn-styles or gates
  • N-Ch mosfet controlled IR LEDs such that LEDs can be controlled ON for short periods during while sensing (~75us). Allows for reduced power to less than 1ma (plus uController).

STEP 3: General Operation

Infrared (IR) Sensors

Honeybees are forced through 24 gates where optical sensors (48 sensors) determine whether the bee is present and determine the direction of the bee movement. Each optical sensors has an IR LED and an IR sensor. If no bee is present the IR light is absorbed into the black surface. If a bee is present the IR light reflects off the bee and triggers the sensor.

The 48 LEDs are divided into two sets of 24 with each set controlled by an N-ch mosfet. The normal forward voltage of each IR LED is 1.2V and about 20ma as shown on the data sheet. Two LEDs are connected in series with a 22ohm resistor. There are jumpers on the board that allow the LEDs to bypass the current limiting resistors. Do not solder the jumper until fully tested! Refer to assembly instructions.

Shift-in registers

There are 6 shift-in registers. Here's a great description for how to connect and program shift registers. The micro-controller's SPI pins read the shift registers. All six shift registers are read at the same time. The sensors are normally pulled low and show 3.3V or HIGH when a transistor is triggered and a bee is present.

Power
The PCB design connects the USB power pin from the micro-controller to the 3.3V regulator so that a USB cable connected to the micro-controller can power the entire project.

STEP 4: Assembly Instructions


This version of the bee counter is all through hole components. It's easy to solder and assemble. This is the 2nd version of the board (V1) completed March 2020. If you got the Version 0 board (Jan/Feb 2020) you just have to fix some of my previous mistakes including adding a jumper wire shown here.

1) Install IR sensors - QRE1113 or ITR8307

2) install shift registers qty(6), SIP 22R LED resistors and 100k pulldown resistors.

- Shift registers, qty(6) 74HC165
- 22ohm resistors, bussed, qty(4) SIP Packaged, bussed
- 100k ohm resistors bussed, qty(6) SIP-9, 8 resistors, 9 pins

3) install power mosfets qty(2), - N-Channel Mosfet FQP30N06

4) install small capacitors

5) place/solder 3.3V power regulator

- 3.3V Regulator, (input, ground, output - IGO, pinout), qty(1)

6) install large Capacitor

- 560uF, 6.3V Capacitor

7) install green screw terminals, qty(3)

- screw terminals Two pin, 0.1", qty(3)

8) install headers for microprocessor

9) install qty(4) 10K Resistors (picture is wrong.. only shows 2 resistors) - i2c pullup resistors - pulldown resistors for power mosfets

STEP 5: Initial Testing


TEST sensors Before you go any farther, test all your LEDs/sensors! It's much easier to test these now before going further. Run the sample code Blink_IR_Leds.ino

The IR LEDs are invisible to the human eye but many phones and cameras allow you to see the IR LEDs. See picture. (unfortunately most iphones have IR filters so try another phone until you see IR leds). This step is very important so make sure you can see all the LEDs.

LEDs look good? If no LEDs are blinking? Check to make sure you have 3.3V on the 3.3V pin header. If one or two LEDs are out, reflow your pins and/or replace the LEDs until you get 100% LEDs blinking together. LEDs good, great, next test the shift registers with the sample code test_shift_registers.ino

Use a white piece of paper to trigger the sensors. If some sensors are not working, check your pins, heat up and reflow solder on pins as needed.

STEP 6: Final Assembly

Finish assembly once all sensors are tested. Install the headers that connect the top PCB to the bottom PCB. !

Ok, once everything is tested out, you can solder these jumpers.... Soldering the 24 jumpers increases the throw range of the IR sensors by increasing the forward voltage and current in the LED. This is fine to do if we keep the LEDs ON time to less than 100us. This is described in the data sheet.

Two scripts provided, both test_shift_registers.ino and bee_counting.ino satisfy this requirement by only turning the LEDs ON for 75us. This is shown on line 68 (shift register) and line 158 (bee_counting). Following the ON time there is a delay of ~15-20ms before turning them ON again which preserves the life of the LED.

Solder all 24 of the jumpers.

STEP 7: Dual Footprint Micro Controller Pinouts

The printed circuit board accepts two Adafruit style of micro-controllers. The Adafruit Feather type micro-controllers and Adafruit ItsyBitsy micro-controllers. The Adafruit feathers include wifi and long range radio features (*esp8266, esp32, and LoRA). All the ItsyBitsy 3V models (M0, M4, and 32u4) should work fine.

Unfortunately the shift registers we're using (the most popular shift register chip!) are not full SPI devices and wont share the SPI with other devices.. They're like the worst SPI devices!... therefore some boards like the Adalogger or LoRa just wont work out of the box. You can still do it by cutting some traces and patching the SPI lines to free SPI lines and bitbanging the SPI to the shift registers but that's a bit hard to explain in an instructable.

Hardware SPI

The example code is written for the Feather ESP32 and itsybitsy M0/M4 but should work fine with others. The hardware SPI pins are used for both: MISO & SCK.

Pin A5 on both the ESP32 and itsyBitsy is the Shift Register LOAD
*Pin A5 doesn't exist on the ESP8266. If you use this board, you need to jumper to another pin (say RX pin is free)

Power Mosfets

Two pins are connected to the power mosfets driving the IR LEDs

  • Feather pins
    • Pin 15 for gates 0-11
    • Pin 33 for gates 12-23
  • ItsyBitsy pins
    • Pin 10 for gates 0-11
    • Pin 11 for gates 12-23

Extra Pins

There are Screw Terminals (green) to connect additional sensors to the i2C pins (SDA and SCL)
There is also an analog pin A4 connected to one of the screw terminals.

STEP 8: Arduino Code

There are three arduino scripts attached.

  • Blink_IR_leds.ino - used to visually inspect LEDs working
  • test_shift_registers.ino - used to functionally test sensors
  • bee_counting.ino - used to count bees!

Warning

Soldering the 24 jumpers increases the throw range of the IR sensors by increasing the forward voltage and current in the LED. This is fine if we keep the LEDs ON time to less than 100us.

Two scripts above, both test_shift_registers.ino and bee_counting.ino satisfy this requirement by only turning the LEDs ON for 75us. This is shown on line 68 (shift register) and line 158 (bee_counting).

Calibrating the Bee Counter

I've captured some amazing data over the years. It's possible to calibrate the bee counter to achieve the required repeatability. There are different ways to calibrate the bee counter depending on the desired effect. One method is to measure the speed of the bees movement and only count known movements and throwing out all false triggers. This method misses a lot of bees but can give consistent values. It takes a bee about 180-350ms to traverse the sensor region.

The example code bee_counting.ino measures the speed of the bees through the sensor and counts bees moving faster than 650ms and demands the time between finishing one sensor and finishing the 2nd sensor is less than 150ms.

Some of the obstacles to calibrate for include:

  • although bees don't add propolis to sensors they will spend several days filling voids with propolis upon initial installation
  • bearding in the summer evenings and general guard bees mulling about give false triggers
  • direct sun light at a low angle will false trigger sensors (this can be mitigated pretty easily)

STEP 9: Bill of Materials

Micro-Controller

The code was tested with the feather esp32 Huzzah and itsyBitsy M0 but will work with all these boards.

Printed Circuit Board from JLCPCB ~$16-25 with shipping.

Order the PCBs Black. See PCB ordering instructions.

Parts and Pieces

Here is summary pricing list from mouser. See alternative pricing below for cheaper options specifically for the reflectance sensors.

QRE1113 Reflective Sensors qty(48)

6 pin female headers 7mm high, 0.1" spacing, qty(~36)

22ohm resistors, bussed, qty(4) SIP Packaged, 9 resistors, 10 pins

100k ohm resistors bussed, qty(6) SIP-9, 8 resistors, 9 pins

Shift registers, qty(6) 74HC165

3.3V Regulator, (input, ground, output - IGO, pinout), qty(1)

screw terminals Two pin, 0.1", qty(3)

0.1 uF Ceramic Capacitor, through hole, qty(6)

1 uF Ceramic Capacitor, through hole, qty(1)

560uF, 6.3V Capacitor low esr, 3.5mm lead spacing, 8mm diameter

N-Channel Mosfet FQP30N06, qty(2)

10k Resistors, qty(4), generic 1/4 watt

male headers 6 pin, ~qty(32) or... 12pin qty(17) and break apart as needed

Alternative pricing from Chinese distributor LCSC

Someone pointed out some alternative pricing that can really bring the cost down.

STEP 10: Printed Circuit Board Ordering

There are a lot of different PCB manufacturers to choose from. These instructions show JLCPCB. You need a manufacturer that can make black PCBs. The IR LEDs/sensors need to point to a black surface to prevent false triggers, so the bottom PCB has to be black. Minimum JLCPCB is qty(5) boards and you'll need 2 boards to sandwich together to complete one bee counter.

1. Download the entire repo... hit the large green button that says "clone or download" github... navigate to the "gerbers.zip" file under the PCB folder.

2. Go to JLCPCB.com, create an account and click the ORDER NOW button.

3. Click on the "Add Your Gerber File" and upload the ziped files

4. Select 'Black' as the PCB color. Also for "Remove Order Number", select YES

The cost is about $8 for a minimum order of qty(5) PCBs plus $9-16 shipping depending on method.

75 Comments

Can I still buy it?
I wonder if you are still selling it.
I live in Korea and want to buy this product.
What should I do if it's defective or not working?
The budget is fixed because it will be used for the lab project.
Hi everyone, I now have installed the counter for a week. There have been a few days with temps higher than 9°C and the counting works well (still under test). I am impressed of how well it works. If you want to see the results you can look here https://thingspeak.com/channels/1625705

A lot of thx to those who designed it and wrote the code.
Regards
Paul
Hello, I made the bee counter in order to install it on my connected hive.
I can not understand the code and use the data received.
Can you explain to me the significance of the values obtained?
Thanks in advance
Hi! I'm considering building this project, but the electronics seems to not be protected from the forces of weather. In my city it rains and snows a lot. How could one make improvements to shield the components? Or would you rather be using the Honey Bee Counter II instead? Thanks in advance
One easy way to to keep moisture or at least direct moisture off the electronics is just build a
Little shed on the front of the hive... Or put a larger roof on the hive that extends out a foot or two... But depending on how many deeps and supers you have it might be better to just build a shed..
Thanks for the quick answer! I've got one more question, do you believe this will work on the feather nrf52840 express?
Hi, I'm interested in trying this on some bumblebee hives. Could you tell me what the dimensions of the channels are so I can work out if the fat gals will fit through please! Also the hives would only need 2, maybe 3 channels- could I use shorter PCBs? Would everything else remain the same (novice!). Thank you!
They're probably not going to fit... But you could just 3D print a new gate system that only uses some of the sensors.
Thanks. If I did that, and also required a larger space gap between the 2 pcbs would the sensors still work? Have you found there to be a maximum distance for them to work reliably?
You can import the eagle file into eagle and then measure distances from there between the pins... But it's definitely too small for a bumblebee
Thank you for posting this bee counter it looks very fun and well-made!

I am trying to get this to work with the ESP8266 Feather HUZZAH and have made the following adjustments to the code and board:
- Jumped RX to A5
- Changed const int LATCH from A5 to 3 (RX); (line 42)
- Changed const byte powerGates2 from 33 to 0; (line 46)
The LED and Test shift register tests have been passed using these changes.

- What about const int testLed = 13; //onboard LED (line 41)
I am not sure which pin should be assigned to this on the ESP8266?

Also when verifying the code I get the error that chipSelect1 and 2 are not declared in this scope.
I have used the following code to solve this:
#define chipSelect1 12
#define chipSelect2 14
However I do not get any counts in the serial monitor, as much as I try.

Any idea what I have done wrong?
- yea, chipSelect1 and chipSelect2 are left over from the old code. You can comment those out.
- the onboard LED for the esp8266 huzzah is GPIO 0. see this for reference: https://learn.adafruit.com/adafruit-feather-huzzah...
- Seems like you've done everything correct at this point. Did you use a little piece of white paper to move under the gates? You have to move the paper very fast to simulate a bees movement.
Hello,
Thank you very much for your answer.

I commented out the "chipselects" and changed LED to GPIO 0, and now everything works.

Also I made the mistake of moving the paper to slow, apparently.

Currently my first counter is hooked up to a TP4056 solar controller, a 6V 0.75W solar panel and a 18650 2600mAh battery. Hopefully this can get it through the season without running dry.
I am about to start this project as soon as I teach myself to solder. I got the feather MO Adalogger in the hopes that I could use the SD card to store data. Not realizing that the hole placement appears to be different. Can I make this card work, or will I need to switch to a different one?
I am 17 with 3 beehives. Thank you for posting your work; this looks like an interesting project, and a fun challenge. Hopefully I can get it to work.
Hey... unfortunately it wont work... here's why:

... the shift registers we're using (the most popular shift register chip!) are not full SPI devices and wont share the SPI with other devices.. They're like the worst SPI devices!... therefore some boards like the Adalogger or LoRa just wont work out of the box. You can still do it by cutting some traces and patching the SPI lines to free pins and bitbanging the SPI to the shift registers but that's a bit hard to explain in an instructable.
Just got the ESP32 and only have gates 7, 10, 13, and 22 are blinking. was there a specific way I was supposed to put the IR sensors in? I am guessing I will just have to replace and re solder the ones that dont work.
Hey, It's likely that if you put them into the correct orientation and soldered each pin, that they will work correctly. Yes there is specific orientation to the sensors... You can follow the silkscreen. There is a small notch (to right) that should match the notch in the silksreen.
Thank you for the help. I got all the gates except 0 and 21 to work (because I wrecked some of the holes de soldering). I am guessing it can work without these gates if I just block them off. Is it possible to put the esp32 into programming mode manually? Everything I have found requires manipulation of pins, or is for the wrong model.
Yes for sure... you don't need all the gates!.... The esp32 should go into programming mode automatically... Hit up the Adafruit forums if you're having weird problems. They're pretty responsive... but let me know if you can't figure it out.
More Comments