Part 2 - BlueMix and the Internet of (50000 small) Things: The BeeSpi hardware
Contents
Part 1: An introduction to BeeSpiPart 2: The BeeSpi hardware
Part 3:Configuring the Pi software
Part 4: Completing the Pi software
Part 5: Finalizing the Bluemix solution
This continues from the introduction.
I decided to approach monitoring of the hives from multiple angles:
- I would like to be able to see what was happening inside the hive
- Since the temperature of the hive was important, I wanted to track the temperature
- Dampness is a major cause of problems for bees, so it would be good to know the humidity inside the hive
As a reminder, here's the current version of the site: beespi.mybluemix.net.
Visual
There's a cheap camera available for the Pi that simply plugs into a socket on the board. There's also a useful variation of the camera that has its infrared filter removed, the NoIR camera: clearly this could be used to view the bees inside the dark hive, illuminating them using infrared light.
Bee Factoid: Bees can see ultraviolet and the blue end of the spectrum, but can't see red or infrared.
Temperature
I decided to add two waterproof DS18B20 temperature sensors for each hive, in order to measure the temperature inside the brood box (where the eggs are laid) and in the super (where the honey is stored).
Bee Factoid: The beehive itself is composed of the brood box in which the bees create the brood nest, basically a sphere through the box, across the frames. Above this are the supers where they store their honey. The bees keep the eggs and young in the brood nest at a constant temperature of 34°C, and the supers are cooler although they're quite warm too.
I also wanted to track the ambient temperature outside the hive. Note that these sensors normally come with a 1m cable, but you can get them with 3m or even longer cables which makes using them that much easier.
Humidity
Finally, to track the humidity, I decided on a DHT22 sensor in each hive. This actually provides both temperature and humidity readings, so it gave me an extra temperature point in each hive.Cost
Of course, an important aspect of any project is the amount of money it involves, and the costs breakdown is below. Note that currently the Euro is worth around $1.05 or £0.72.Item | Price |
---|---|
Raspberry Pi model A+ | €29.30 |
WiFi Dongle | €6.30 |
MicroSD card 32GB, Class 10 | €15.68 |
Waterproof box | €6.94 |
2xDHT22 | €5.88 |
5x3m waterproof DS18B20 | €8.39 |
3m USB cable | €1.36 |
M-F connectors | €2.43 |
Total for 2 hives | €76.28 |
Per hive | €38.14 |
There were also minor costs of resistors, LEDs and wires, but they didn't add up to more than a couple of Euros. One thing to be careful about is the use of a long USB cable since this can cause a drop in the available power. In this case, we're using a Pi model A+ which uses very little power, but such a cable would not work for a model B+.
My costs were for devices I ordered from China which took up to 6 weeks to arrive. Using places like Adafruit will increase your costs, but the parts will arrive much more quickly.
GPIO
Before continuing, I'll
explain about the General Purpose Input/Output (GPIO) connections in
the Raspberry Pi. The block of pins exposed in the Pi consists of a
few power sources (3.3V and 5V), some ground connectors and a number of
GPIO pins, more of which have been made available as the Pi evolved
from the initial Model A to Model B and now to Model A+, B+ and version 2. These pins
have no explicit function, so we can use them as we like to extend the Pi's
functionality. They can be designated as input (read-only) or output
(read & write), and can set high or low, giving the values 1 and
0 respectively. For sensors, they are set as input, and
for things like the LEDS, they must be set to output.
The individual pins in the interface are assigned numbers from 1 to 40, but the assignment to these has varied over the versions of the Pi. To manage this inconsistency we can use the WiringPi library – it is reliable and
makes interfacing very simple indeed. WiringPi uses a
numbering system that derives from the Arduino architecture, although
the native Pi numbers can be used. This numbering system has the
great advantage that it's compatible across all versions of the
Raspberry Pi, so the software will work on all versions unchanged.
For an excellent interactive explorer of the Pi's pins, see Gadgetoid's diagram.
For an excellent interactive explorer of the Pi's pins, see Gadgetoid's diagram.
Connecting the camera
Connect the camera's
flat cable to the slot just behind the network socket: pull up the
clip at the top of the slot to open it, push the cable home with the
silver side facing towards the HDMI socket, and push the clip
down until it clicks to lock the cable in place.
To provide lighting in the dark hive, I used three InfraRed light-emitting diodes (IR LEDs) similar to this. Each LED requires a power source and a connection to ground. I soldered a 350Ω resistor to the negative side, i.e. the shorter leg, and soldered a 1m length of wire to each side, to make sure I had enough room. Then I connected all of the positive (long) ends together and connected that to a GND pin, while each of the positive ends were connected to their pins - 32, 36 and 37 or, in WiringPi terms, 26, 27 and 25 respectively. Of course, since this would be in the hive with a potential for short circuits, etc. I wrapped the LED legs and the camera in insulating tape, resulting in a little lighting package that looked like this:
To provide lighting in the dark hive, I used three InfraRed light-emitting diodes (IR LEDs) similar to this. Each LED requires a power source and a connection to ground. I soldered a 350Ω resistor to the negative side, i.e. the shorter leg, and soldered a 1m length of wire to each side, to make sure I had enough room. Then I connected all of the positive (long) ends together and connected that to a GND pin, while each of the positive ends were connected to their pins - 32, 36 and 37 or, in WiringPi terms, 26, 27 and 25 respectively. Of course, since this would be in the hive with a potential for short circuits, etc. I wrapped the LED legs and the camera in insulating tape, resulting in a little lighting package that looked like this:
Connecting the temperature sensors
The DS18B20 sensors are really simple to set up: connect all the red wires to a single red wire, all the yellow wires to a single yellow wire and all the black wires to a single black wire. You also have to connect a pull-up 4k7Ω resistor between the red and the yellow wires. If you're not comfortable soldering, you can use a connector block, but soldering makes for a nice small package:The three wires are now connected as:
Red | 3.3V | Pin 1 |
Black | GND | Pin 9 |
Yellow | Data | Pin 7 |
Connecting the DHT22 sensors
These devices have four pins, but we only want to use three of these on each sensor. The connections are:Pin 1 (Left) | 3.3v | Pi Pin 17 |
Pin 2 | Data | Pi Pins 13 and 15 (WiringPi 2 and 3) |
Pin 3 | Unused | N/A |
Pin 4 (right) | GND | Pi Pin 25 |
Once again we need a pull-up resistor between the data and 3.3v pins. I connected 1m lengths of wire to each of the three active pins, and connected the rightmost pins together to a black wire, and connected that to Pin 25 GND on the Pi. I also connected both of the leftmost pins together to a red wire and to one end of two 10K resistors, connecting this to 3.3v on Pin 17 on the Pi. Finally I connected the data pin 2 from each to the other end of one of the resistors and to a yellow wire. One of these was connected to pin 13 and the other sensor data wire was connected to pin 15 on the Pi.
When the temperature and humidity sensors are connected, they look a little like the picture below - note that this shows an extra power connector and doesn't show the DHT22 GND connection.
The next post explains the software required to make this work.
Comments
Post a Comment