Easy Bee Counter

16,574

136

65

Introduction: Easy Bee Counter

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

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.

PCB Design Challenge

Second Prize in the
PCB Design Challenge

1 Person Made This Project!

Recommendations

  • STEM Contest

    STEM Contest
  • Role Playing Game Challenge

    Role Playing Game Challenge
  • CNC Contest

    CNC Contest

65 Comments

0
rasmusagrolab1
rasmusagrolab1

Question 6 weeks ago

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?

1
hydronics
hydronics

Answer 5 weeks ago

- 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.

0
rasmusagrolab1
rasmusagrolab1

Reply 24 days ago

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.

0
hydronics
hydronics

Reply 22 days ago

nice job!

0
pcordier101
pcordier101

Question 6 weeks ago

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.

0
hydronics
hydronics

Answer 6 weeks ago

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.

0
pcordier101
pcordier101

Reply 6 weeks ago

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.

0
hydronics
hydronics

Reply 6 weeks ago

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.

notch.JPG
0
pcordier101
pcordier101

Reply 5 weeks ago

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.

0
hydronics
hydronics

Reply 5 weeks ago

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.

0
pcordier101
pcordier101

Reply 5 weeks ago

Got the board working... onto the shift registers test. I copied and pasted it into arduino, but the only thing I can get to show on my serial monitor is "begin switch test". Do I need to splice the blink led code into the shift register test?

0
hydronics
hydronics

Reply 5 weeks ago

Did you make the jumpers?

0
pcordier101
pcordier101

Reply 4 weeks ago

I thought that was meant to be done after the shift register test. Thank you for all the help, I clearly couldnt have done this on my own. I just need to set it up to send data over wifi and record it and I will be ready to go. I am thinking this can be used on donor hives to see how long it takes a hive to recover after a split, forager donation, or to detect a lag in numbers after transferring brood.

Why do you have the code set up to only count bees that traverse the sensored regions in under 150 ms if the average time is 180-350?

0
hydronics
hydronics

Reply 4 weeks ago

yeah it's tricky. If you make the jumpers too early you fry the LEDs!...

As far as speed goes... It's a tradeoff... during the evening and/or during bearding... you get a lot of false triggers if you just count whatever you see....

0
mikalpdx
mikalpdx

2 months ago

I'm a complete novice. Im trying to figure out a way to tell if my hives have swarmed so interested in whether this device can help. I Usually end up with about 15 hives each year and with my buddy Tim W, we end up with 30-35 hives in our apiary at Green Anchors in PDX. Others use the apiary for temporary situations and that can add another 15 to the yard at a time. Unless you watch the swarm coming out, there is no real easy way to determine where the swarm originated.....IF.... you even find or see the swarm. Does this device stay on continuously and needs power? Can you read the data in real time? Do you need a WIFI connection? Can you use an iPhone to read the data? Would this be practical to put on 15+ hives in one location (apiary)? Thanks Michael Carlson

2
hydronics
hydronics

Reply 2 months ago

hello! Yes swarm detection is super useful and a lot of people are working on it. This device could be used for swarm detection but the specific algorithms that would detect/predict and then warn you of an impending or immediate swarm have not been developed.
The current state of the bee counter is to help in data collection so that these things can be studied.
- the device is very configurable and can stay on continuously although bee counting in the evening is not very useful and you get a lot of bad data when the bees are just mulling about
- the device is configurable such that you can read data in real time
- the device can be setup with wifi if you select the uController with wifi
- it's possible to push the data to a cloud storage and then read the data over a cell phone
- there would a lot of advantages to setting up multiple bee counters in an apiary for sure.

0
hydronics
hydronics

Reply 5 months ago

yep, you can totally run the leds at 1.2V and 20ma but they won't be as bright... They arbitrarily select that voltage/ma as an example. Check out this curve that shows all the relavent voltage/ma combinations (all under 1.6V as stated as the maximum for continuous ON)... for shorter ON periods you can go up to 3 or 5V!....

led_voltage_vs_amps.PNG
0
Offthewheel
Offthewheel

Question 7 months ago on Introduction

Hi - I am up to the LED test stage but have an ESP8266 and I don't understand what the comment below from the instructions means, Can anyone assist with what I actually have to do? THanks

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

OK - now see other comments which explain it

0
hydronics
hydronics

Answer 7 months ago

nice sleuthing