The sensorbox is used to measure the temperature, the humidity, and the sunlight. It can also take images using a webcam. It actually has two temperature and humidity sensors, one for inside the greenhouse and one for outside. The box' design is fairly generic, meaning that you could plug in other sensors as well and use it for puposes other then the P2P Food Lab greenhouse.
What's specific about the P2P Food Lab sensorbox is that it was designed to be autonomous. We made it to be self-sufficient in terms of energy. It doesn't need a wall plug to power it, but runs of a solar panel plus battery. Also, you can use GSM, or the mobile phone network, to upload the data when there is no WiFi signal available (often the case in the back of the yard). Thanks to these features, you can use the box in remote areas.
Another feature is that we tried to build the box using reusable components, such as USB modules, so that it can be dissassembled and the components used for something else.
The P2P Food Organisation makes a sensorbox kit available to make it easier for people who want to use the P2P Food Lab greenhouse to get starter. You can purchase the kit from the P2P Food Organisation. The price is roughly the cost of the components plus 10€ to support our organisation.
Note that the sensorbox is currently at version 0.4 and is still experimental. It requires some technical skills to build, though anyone who enjoys making stuff should manage. The box comes "as is", without any warranty. Also the P2P Food Organisation cannot be held liable for any damage the sensorbox may cause. Just so you know!
- 1 Major components of the box and how they fit together
- 2 Detailed list of the contents of the kit
- 3 Overview of the steps to build the kit's hardware
- 4 Solder the connector board and sensor boards
- 4.1 Cutting the PCB board in pieces
- 4.2 Building the temperature and humidity sensor
- 4.3 Build the Arduino connector board
- 5 Upload the software to the Arduino
- 6 Install the disk image for the Raspberry Pi
- 7 Create an online account
- 8 Configure and test the box
- 9 Build the plexiglass box for the solar panel
- 10 Install the box outside
- 11 NOTES on making the wires
Major components of the box and how they fit together
So what are the major components? First, there is the Arduino. Arduino is a popular micro-controller board. We use the Arduino Pro Mini from produced by Sparkfun, which looks like this:
A micro-controller is like a tiny computer inside a single chip. It can perform basic computation. It has a small amount of internal memory to store data. And it has a series of input and output pins to communicate with sensors or other devices. There are two types of pins: digital and analogue pins. In electronics, all exchange of data happens through the use of voltage levels. In digital communication, a series of zero's and one's are transmitted. A high voltage level (in this case something like over 3V), means the transmission of the symbolic value '1'. Alternatively, a low voltage level (close to zero), the symblic value of '0' is transmitted. So by sequentially setting the voltage level of a digital pin high and low, the microcontroller transmits series of 0's and 1's to the sensors, which is enough to establish communication and transmit data.
The output of analogue pins can be any value between zero and 3.3V (the Arduino Pro Mini that we use runs at 3.3V, which is different from most Arduino's which run at 5V). We'll use the analogy of the light switch: a digital pin corresponds to a on-off switch, while the analog pin corresponds to a light dimmer where you have control of the amount of light you want.
Both analog and digital pins can be used to output values or to read values in.
Back to the Arduino. Arduino is basically a very convenient package to start playing with micro-controllers, sensors, and actuators. The Arduino framework consists of a Arduino-compatible board and a software package to develop software for that board. There's a whole series of Arduino-compatible boards in different shapes and capabilities. Micro-controllers, like any computer, run software to tell them what to do. The Arduino software package makes it easy to develop this software and run it on the boards. The sensorbox also requires software to be run on the Arduino, and you will see how to install and run it. Last, I want to mention that the Arduino is Open Hardware, which means that the designs of the circuits are freely accessible and that you can use them to make your own designs.
External links with more info: Arduino web site Getting Started with Arduino Getting Started with the Arduino Pro Mini About Open Hardware
The second major component is the Raspberry Pi. It is a small computer and looks like this:
It has video output, so you can connect it to a monitor or TV screen. It has USB input for a keyboard and mouse. It doesn't have a hard disk, but a SD card, similar to those that are used in photo cameras. It used a similar processor that those you can find in mobile phone: the ARM processor.
The Raspberry Pi doesn't run Windows or MacOS but Linux, a free and very reliable operating system. Because it is free (both free as in "free beer" and free as in "free speech"), you can distribute the operating system to whom ever you want, or study how it works and modify to suit your purposes. We have prepared a "disk image" for you. A disk image is a computer file that contains a complete copy of the operating system and of all the software. We will copy this file directly onto the SD card, which then allows us to start up the Raspberry Pi and use it. Our Raspberry Pi disk image contains a software package to manage the sensorbox. It uses a configuration file - also on the SD card - that heps the software decide what to do when. We will show how to change this file to adapt the box to your needs.
External links with more info: About Free Software More on Linux Raspberry Pi web site Getting Started with Raspberry Pi
The next component is a small printed circuit that we designed that is used to connect the Arduino and the Raspberry together and to plug in the sensors. The board allows the Raspberry Pi to communicate with the Arduino, and allows to plug in the sensors and connect them to the Arduino. The Raspberry Pi and Arduino talk to each other over the red and green wire in the image below. They use digital communication (series of 0's and 1's) according to a well-defined standard, called "I2C". The schematics of the connection board is available and can be downloaded below.
External links with more info: Designed and producing boards (TODO) I2C
One of the important aspects of the sensorbox is the energy management. In fact, the energy required for the Raspberry Pi is provided by the connection board. To provide energy to the sensorbox, we plug in a USB cable to the USB connector. The wires go over the board and power the Raspberry Pi through the header that connects them together. However, the wires pass first through a MOSFET:
This MOSFET acts as a switch that is controlled by the Arduino. By setting one of the pins on the Arduino to high, the Raspberry Pi will get current and will start up. By setting the pin low, the current will be cut and the Raspberry Pi is completely turned off.
We added this feature because the Raspberry Pi consumes too much energy to run continuously. So with the intervention of the Arduino, we turn it on and off at specific moments during the day.
Then there are the sensors. First those that are connected to the Arduino: two temperature and humidity sensors, and one light sensor. Then there is the camera, which is connected to the USB port of the Raspberry Pi.
External links with more info: Adafruit's GA1A12S202 sensor board The RHT03 sensor
The solar battery is an important component of the box as it captures and stores the energy. We had to test several batteries before we found one that works. We are still testing it in winter conditions but last summer (summer 2014) it did the job.
Of course, it is also possible to power the box directly from a USB charger.
Lastly, for network connectivity there are three options. You can use the ethernet plug to connect the box to a wired network. Otherwise, you can use a USB WiFi dongle or a USB GSM modem to establish a wireless connection. The GSM modem connects to the Internet over a mobile phone network. You can use it in most remote location but does require a valid SIM card and mobile phone subscription.
The sensorbox uploads all the data and images to the OpenSensorData web site. OpenSensorData.net is a web site we developed specifically to store sensor data. If you want to use the box for another project and send the data elsewhere, this is entirely possible of course. If you want to use the P2P Food Lab and OpenSensorData web sites, you will have to make an account first. Once the box is up and running, you will be able to visualise your data online, like this:
External links with more info: OpenSensorData.net
Detailed list of the contents of the kit
The kit contains all the components you need to build the sensorbox and to develop/debug its software. The picture above gives you I quick idea of the contents. The detailed list of components can be found below. It is important to note that the photo above shows an already mounted the circuit board. The kit, however, contains only loose components and requires additional work (soldering, software installation, ...) in order to function. This page provides instructions on how to build it.
|Name||Reference||Quantity||Approx. unit price (€)||Total price (€)|
|Printed Circuit Board||ND||1||10.00||10.00|
|Arduino Pro Mini 328 3.3V 8MHz||Arduino Pro Mini 328 3.3V 8mHz||1||12.00||12.00|
|Raspberry Pi Model B||Raspberry Pi||1||28.00||28.00|
|4GB SD Card||RASPBERRY-PI / PROG-4GB-SDCARD||1||4.00||4.00|
|Solar panel/battery||Opteka Solar Charger BP-SC4000 (4000 mAh, 1.0A, 11.4 x 8.4 x 1.4 cm)||1||28.00||28.00|
|Network option 1: USB WiFi Dongle||Ralink RT5370||1||8.00||8.00|
|Network option 2: USB GSM Dongle (without SIM Card)||Huawei E169||1||15.00||15.00|
|Water-proof box for R'Pi & Arduino||1||13.00||13.00|
|Laser-cut, plexiglass box for solar panel||1||10.00||10.00|
|USB-to-Serial interface (FTDI Basic Breakout 3.3V)||Sparkfun Basic Breakout 3.3V||1||11.00||11.00|
|USB cable, M/F, 25cm||||1||1.10||1.10|
|USB mini cable||1||1.00||2.00|
|USB Connector||USB2066-05-RBHM-15-STB-00-00-A / To connect the solar panel||1||1.05||1.05|
|AAA battery pack||1|
|26-way female board-to-board connector||SAMTEC - BCS-113-L-D-TE||1||5.90||5.90|
|JST-4 plugs (plug + female + connectors)||3|
|JST-3 plugs (plug + female + connectors)||B3B-PH-K-S, JST-3 header plug / Used to connect the sensors to the main board||6|
|JST-2 plugs (male + female + connectors)||Used to connect the Arduino to the R'Pi and to connect the battery||2|
|Resistance 100 MOhms||||4||1.00||4.00|
|Humidity and Temperature Sensor||RHT03 / DHT-22||2||13.00||26.00|
|4k7 resistance||RESISTANCE 0805 4K7||2|
|Male breakable header, 0.1", 36-way||2||1.27||2.54|
|Female header, 1x12 way, 0.1"||2|
|1-way wire (red, green & blue)||50cm|
Overview of the steps to build the kit's hardware
Major steps to build the sensorbox:
- Solder the connector board and sensor boards
- Upload the software to the Arduino
- Install the disk image for the Raspberry Pi
- Create an online account
- Configure and test the box
- Build the plexiglass box for the solar panel
- Install the box outside
Solder the connector board and sensor boards
After you cut the PCB board, start by soldering the temperature/humidity break-out board. It's a good way to warm up. Then move on to soldering the connector board.
Cutting the PCB board in pieces
The PCB board has a weird shape. It contains the Arduino connector board but also different break-out boards. The strange form is because we can only submit single board designs to Express PCB, the service we still use to produce them. So you'll have to pull out a saw (a small metal saw is best) and cut the pieces apart.
Not all of the smaller parts are use, yet. Some are there because we're still experimenting with new sensors. Here's the list of pieces and what they are used for:
Building the temperature and humidity sensor
The temperature and humidity sensor break-out board is the easiest. It just requires a 3-way plug, a pull-up resistor, and the RHT03 sensor. We purchase the sensor for Sparkfun, where you can find more information about it.
Before you solder the 3-way plug, make sure that the small slit is facing downwards.
Build the Arduino connector board
The Arduino connector board sits between the Raspberry Pi and the Arduino Pro Mini. It also has the sockets to plug in the sensors.
The Raspberry Pi communcates with the Arduino over I2C. The Arduino also manages the powerline that goes from the USB connector on the board to the header of the R'Pi. A MOSFET is used to cut of the power supply or to let it through.
All the components to be soldered are shown below.
- Solder the 4x 100 MOhm resistors
- Solder the USB connector
- Solder the JST-2 plug
- Solder the two wires with the JST-2 plug to the Arduino
- Solder the Arduino
- Solder the R'Pi header
- Solder the remaining plugs and headers
Solder the 4x 100 MOhm resistors
Solder the two 100 MOhms resistors. This part of the circuit is a voltage divider to measure the solar panel input. As the Arduino works on on 3.3V, it can't measure 5V. The voltage divider reduce the 5V power issued by the USB plug down to 2.5V. We use big resistors in order to reduce energy losses.
It's important to solder these surface-mounted devices before installing the Arduino.
Nota: This part of the circuit is still work in progress
Solder the USB connector
The USB connector is used to supply the power to the sensorbox. Of the five pins, only the left- and right-most pins are used. The three pins inbetween do not have to be soldered.
Tip: to solder the plug, I first flow some solder onto one of the square pads on the board. I then position the plug on top and heat up the leg until the solder underneath melts. Once that one leg is fixed, the three others and the two pins are easy to solder.
It's used to connect the solar panel battery.
Thus, we just need to connect the power pins. Behind the USB connector, we have five pins. From left to right, we have VCC +5V connection, D- (Data -), D+ (Data +), ID (Mode Detect) and Ground. We only connect VCC and Ground to get power.
For additional information, Micro USB Connector Pinout diagram
Solder the wires for the I2C bus
Two wires are is used to connect the I2C lines from the Arduino to the header of the R'Pi. Check the figure below for the required length of the wires, which wire goes where, and also for the orientation of the plug.
Further down on this page, you can find some tips about soldering the connectors.
Solder the Arduino
On the Arduibo: Solder the pins that connect the Arduino Mini Pro to the board. On the connector board: Solder the headers that will receive the Arduino. Tip: Put the headers on the board, the pins in the headers, and the Arduino on the pins when soldering. This will make sure that the headers and pins are ligned up correctly.
Solder the R'Pi header
This is the connector that connect the Main PCB to the Raspberry Pi.
Solder the remaining plugs and headers
Solder this additionnal 2-way header pin
Solder these 4 plugs that are made to simply connect sensors
Solder MOSFET and respect the direction of its pins (see picture).
Upload the software to the Arduino
The Arduino board in the sensorbox must have some software installed on it, to tell it what it should do, like when it should read the sensors, and what sensors are connected to it, and how to talk to them. This software is also sometimes called firmware.
Get all the software
This firmware has to be copied from your computer to the memory of the micro-controller. In order to do that, you will need another piece of software that runs on your computer. That second piece of software is the Arduino development enviroment, also called Arduino IDE, for Integrated Development Environement. You can download it from the Arduino web site. You must select version 1.5.x of the software for our purposes.
The second thing you will need is the source code of the software that will run on the Arduino. This is the code that we wrote for the project. The code is available at GitHub, which is a specialised web site for developers for hosting software projects.
You can get it by downloading the ZIP file. Extract all the contents to a folder of your choice.
Alternatively, if you are familiar with development tools, you can get the code using git:
Install the software libraries
Our software uses functionnalities that were developed by other people. These functionnalities are grouped into what we call software libraries. We use two of those libraries:
- DHT22: functions to communicate with the temperature/humidity sensor.
- Narcoleptic: functions to put the Arduino in deep sleep and save energy.
These libraries are included in the ZIP file that you just downloaded but still have to be installed so that the Arduino development software can find them.
Do the following:
- Start the Arduino IDE.
- Click from the 'Sketch' menu, then select the following menus: 'Import Libray', 'Add Library' (first line in sub-menu).
- In the file selection dialog, navigate to the directory <where-your-extracted-the-zip-file>/p2pfoodlad/arduino/. Then select DHT22.zip.
- Do the same for the Narcoleptic.zip file.
Upload the software
- Connect the Arduino to your laptop using a FTDI serial-to-USB cable.
- Start the Arduino IDE.
- Select the correct serial port in the Tools -> Serial Port menu.
- Select the "Arduino Pro or Pro Mini (3.3V, 8MHz) w/ ATmega328" in the Tools -> Board menu.
- Open the file p2pfoodlab/arduino/p2pfoodlab/p2pfoodlab.ino
- Click "Upload" to transfer the code to the Arduino.
Testing the sensors
- Start the Arduino IDE.
- Connect the FTDI serial-to-USB cable to the Arduino debug pins
- In the Arduino IDE, start the serial monitor
- Plug in the USB cable to power the connector board
Install the disk image for the Raspberry Pi
- Download the disk image from https://p2pfoodlab.net/wiki/big-files/p2pfl-2014-06-13.img.zip (900 Mo)
- Unzip the file
- Copy the image on your SD Card (Minimal size: 4GB)
When the disk is mounted, do
to get the name of the device of the SD card. It my case, it was the last line that was printed out:
/dev/mmcblk0p1 /media/toto/2896-6041 vfat rw,nosuid,nodev,relatime,uid=1000,gid=1000,...
Note that mmcbkl0p1 stands for the first partition (p1) and that mmcbkl0 is the name of the whole (unpartitioned) card.
Unmount the SD card:
sudo umount /dev/mmcblk0p1
and copy the disk image file to the card:
sudo dd if=p2pfl-2014-06-13.img.backup of=/dev/mmcblk0 bs=4M
Taking the card out and pushing it in again should mount it autimatically. There are two partitions, the first is called 'boot' and contains the Linux kernel. The second partition contains the home directories and all other files.
- Copy boot/p2pfoodlab-backup.json to boot/p2pfoodlab.json and open /boot/p2pfoodlab.json in your preferred editor.
TODO: explain options
- Insert SD Card in RPi and boot, login (username:pi, password:raspberry)
- If SD Card is bigger than 4GB, increase image disk by doing
$ sudo raspi-config
and then select the first menu item
Create an online account
- Go to https://p2pfoodlab.net/community/createaccount, and fill the form. Click 'create account'.
- Check for the confirmation email. Click on the link in the email.
- You should see you home page on the P2P Food Lab web site.
- Click on the 'account' menu in the top-right corner.
- In the 'OpenSensorData.net' panel, you will find your OpenSensorData key. You will need it in the next section, to configure the sensorbox.