Easy Bee Counter

by hydronics in Circuits > Arduino

23346 Views, 150 Favorites, 0 Comments

Easy Bee Counter

Easy Bee Counter
itsy_bitsy_finish.PNG
feather_finish.PNG
finished2.jpg
bee_counter_data.jpg
gerber_feather_2.PNG
bee_intro.jpg

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.

Data Analysis - Why Count Bees?

forage.PNG
orientation_flights.PNG

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.

Improvements on Previous Design

pcb_notes_.PNG
  • 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).

General Operation

IR_photo_diode.PNG

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.

Assembly Instructions

ir_sensors2.PNG
ir_sensors.PNG
registers.PNG
PowerMosfets.PNG
headers.PNG
3vRegulator.PNG
10kPullup.PNG
small_capacitors.PNG
uHeaders.PNG
ucontroller_w_headers.PNG
Easy Bee Counter - Assembly

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

Initial Testing

serial_output.PNG
Test IR LEDs

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.

Final Assembly

headers_bottom.PNG
finished2.jpg
jumpers.PNG

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.

Dual Footprint Micro Controller Pinouts

feather_pinout3.PNG
itsy_pinout2.PNG

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.

Arduino Code

jumpers.PNG

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)

Bill of Materials

capacitor.PNG

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.

Printed Circuit Board Ordering

download_from_git.PNG
JLCPCB_order2.PNG
JLCPCB_order.PNG
gerber_feather_2.PNG

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.