Manual BeeHive Project

5 downloads 0 Views 2MB Size Report
This project has been completed successfully, and our goal of integrating all of the .... The 0.96 inch OLED display has 128x64 resolution, three kind of light color (blue, yellow and ..... Jumper-Wire-Ribbon-Cable-Pi-Pic-Breadboard-Hot-.

Manual BeeHive Project

ARDUINO BASED BEEHIVE MONITORING PROTOTYPE July, 2016 Antonio Cachinero Vivar [email protected] Brian Tobin [email protected] UCD FORESTRY

1

Manual BeeHive Project

Project Abstract ……………………………………………………………………………………… (pag.3) Status ……………………………………………………………………………………………………… (pag.3) Specification …………………………………………………………………………………………….. (pag.3) Hardware ……………………………………………………………………………………….. (pag.3)         

Arduino UNO R3 Microprocessor …………………………………………. (pag.4) Load cell ……………………………………………………………………………….. (pag.4) HX 711 ………………………………………………………………………………….. (pag.4) DHT 22 ………………………………………………………………………………….. (pag.5) DS18B20 ……………………………………………………………………………….. (pag.6) BH 1750 ………………………………………………………………………………… (pag.6) Oled LCD LED Display ……………………………………………………………. (pag.7) Adafruit Data Logger Shield with SD card and RTC ………………. (pag.8) Bread Board ……………………………………………………………………….. (pag.10)

Software ………………………………………………………………………………………. (pag.10) Main sketch ………………………………………………………………………… (pag.10) Scale calibration set-up ………………………………………………………. (pag.19) RTC calibration set-up ………………………………………………………… (pag.21) Breakdown of components (Links with price and technical characteristics) ………………………………………………………………………………………………………………….(pag.23) Data Processing ………………………………………………………………………………………. (pag.24) Other components and Troubleshooting ……………………………………………….. (pag.25)  Enclosure box ……………………………………………………………………… (pag.25)  Waterproof Plastic ABS ………………………………………………………. (pag.25) Images ……………………………………………………………………………………………………. (pag.26) 2

Manual BeeHive Project

Project Abstract For a while now and currently following with, I am keen in developing some sort of prototypes with different research purposes based on the Arduino microcontroller. This project is the second prototype from a series of designs which will arise up in the coming months. The goal was to develop a scale system which could be able to measure the production of honey elaborated by the bees into the hives and make it adaptable to the outside doors conditions.

Status This project has been completed successfully, and our goal of integrating all of the underlying technologies has been met. This portable prototype is able to measure weights and several climatological variables and to monitor the temperature inside the hive displaying all the values in actualized date and time, reading the data at any time without needing to plug the project into any kind of software. In addition, the installation has got a data logger which keeps the readings onto a SD card. Eventually, this will allow processing the data in order to get different estimations.

Specification Hardware This prototype has been done with a strain guage/load cell up to 120kg of weight and its correspondent HX711 based module. The machine has been enriched with the installation of DHT-22 (humidity and temperature sensor), BH-1750 (light sensor) and a DS18B20 (waterproof temperature sensor). As mentioned above, the date will be readable through an Oled LCD LED Display and kept onto an Adafruit data logger shield with a SD card and RTC. The HX711 chip is specifically designed for weighing applications. It has a 24-bit differential ADC's and it comes in a compact package with minimal supporting circuit. The chip is highly integrated with builtin PGA, regulator and oscillator circuits. The module is thus small and is easy to integrate with an Arduino. The setup is to have the load cell connected to the HX711 analog inputs and have the Arduino connect at the digital data side of the module. The load cell may be of any weight range. In the making of this prototype, I have used a 120kg load cell, however, you may use other load cells 3

Manual BeeHive Project like 5kg, 100kg or even 200kg. The unit should be calibrated to obtain and output a value with weight units.

Most strain gauge will not come with a platform so I saw myself on the need on integrating the load cell among two platforms made of polycarbonate and drill them up as the image below shows. However, the platform can be made of different material such as wood, plastic or metal.

The HX711 uses an I2C like protocol with fist data pin and clock pin. In this case, I have used the Arduino library for the HX711. It is surprisingly simple to use, just call one function and you get a reading from the chip. Install the library as per normal procedure. Close and then open your Arduino IDE for the installation to take effect. It can be noticed that the value extracted off the HX711 is just a number. It is really up to you to put a unit by converting this number into something meaningful weighing unit such as grams. The easiest way to do this is a simple calibration procedure: Place a known weight on the scale, 4

Manual BeeHive Project say 1000 grams and then record the reading from the HX711. Now edit the code so that every time you read, you multiply the value with 1000 and then divide it by the reading you recorded earlier. Note that you may be better off using a float in this operation. The result should be the reading in gram. There are several other ways to do this but this tutorial will not cover them as we focus on getting our weight sensor up and running. The tare function in setup () sets the "zero-point" of the sensor to whatever is the initial weight the Arduino detects on power up. This is useful to remove the effect of the platform and/or a container used for holding the objects to be weighed. In this prototype, the pin used in Arduino which are connected to the amplifier and loadcell are DT (3) and SCK (2). Likewise, it is fairly easy to connect up to the DHT sensors (11/22). They have four pins: VCC (3 to 5V power), data out, not connected and Ground. Simply ignore pin 3, its not used. You will want to place a 10K resistor between VCC and the data pin, to act as a medium-strength pull up on the data line. The Arduino has built in pullups you can turn on but they're very weak, about 20-50K. This diagram shows how I connected for the testing sketch. Connected data to pin 2 (the prototypes is using and programmed for pin 5), you can change it later to any pin.

The one wire Digital Temperature Sensor - DS18B20 from Maxim (formerly Dallas) is a great chip for measuring temperature in your projects. Luckily, there is a Dallas Temperature library for the Arduino which makes using this sensor very easy. 5

Manual BeeHive Project In order to have a better consistence on the connection, I have soldered the 3 pins to a socket and this one to the plug which I have wired up to our temperature sensor. The DS18B20 can be powered by between 3.0V and 5.5V so you can simply connect its GND pin to 0V and the VDD pin to +5V from the Arduino. However, the DS18B20 can also extract its power from the data line which means we only effectively need two wires to connect it up. This makes it great for use as an external sensor. Therefore, I have used the 2 wire method. Simply connect the GND and VDD to its relatives on Arduino board (Ground and 5V) and the data pin to pin 5 on the board. Note that a 4.7k ohm pullup resistor is required on the DQ pin to pull it up to 5V.

BH 1750 FVI is a digital Ambient Light Sensor IC for I2C bus interface. This IC is the most suitable to obtain the ambient light data. It is possible to detect wide range at High resolution (1 – 65535 lx). This sensor has some advantages such like:

1) Illuminance to Digital Converter 2) Wide range and High resolution (1 - 65535 lx Lux = 1Lm/m2) 6

Manual BeeHive Project 3) Low Current by power down function 4) 50Hz / 60Hz Light noise reject-function 5) I2C bus Interface (f / s Mode Support) 6) No need any external parts 7) It is possible to select 2 type of I2C slave-address 8) It is possible to detect min. 0.11 lx.

The next figure shows how I connected the light sensor on to the Arduino board:

The 0.96 inch OLED display has 128x64 resolution, three kind of light color (blue, yellow and blue/yellow). I think the blue light has better display effect than the others. The display with a small dimension is also suitable for smart watches, function cellphones and smart portable health devices, smart car camera monitor real time display, battery capacity management, MP3 and any possible project. This display has the next specifications: 

High resolution 128x64, this OLED screen has more pixels per unit area than other 128x64 screens



Wider view angle, wider than 160 degree, this is the best in screen 7

Manual BeeHive Project 

Lower power consumption, 0.06W when working normally



Power supply AC3V-5V



Working temperature -30 degree to 70 degrees



Small size, L27.8xW27.3xH4.3mm



Support 4 lines SPI, I2C



With CS signal, support multiple SPI or IIC device working on one BUS



Compatible 3.3v and 5.0v chip I/O level



Driver IC SSD1306

The pins connection with the Arduino board is pretty simple and as follows:    

VCC: 3.3v or 5.0V power supply (In this project I have used 5V) GND: power ground SCL pin SDA pin

The next figure shows how I connected the Oled LCD display on to the Arduino board (please note that Analog pins 4 and 5 are swapped to pins SCL and SDA respectively):

The Adafruit Data Logger Shield which I have chosen is the latest version that keeps all the features of the popular original, but comes pre-assembled so I needed to solder the headers 8

Manual BeeHive Project pins and these ones to the Arduino board. It can be up and running in less than 15 minutes saving data to files on any FAT16 or FAT32 formatted SD card, to be read by any plotting, spreadsheet or analysis program. The included Real Time Clock timestamps all your data with the current time, so that you know precisely what happened and when. The data logger is a reliable, well-rounded and versatile design. It is easily expanded or modified and come well supported with online documentation and libraries. Features: 

SD card interface works with FAT16 or FAT32 formatted cards. 3.3v level shifter circuitry prevents damage to your SD card



Real time clock (RTC) keeps the time going even when the Arduino is unplugged. The battery backup lasts for years. The battery may drift a couple of minutes in a period of 1 year-time



Included libraries and example code for both SD and RTC mean you can get going quickly



Prototyping area for soldering connectors, circuitry or sensors



Configurable indicator leds



Onboard 3.3v regulator is both a reliable reference voltage and also reliably runs SD cards that require a lot of power to run

9

Manual BeeHive Project There are many reasons to build your own Arduino circuit on a breadboard or PCB. It takes less space, projects do not always require every pin to be used on the I/O headers, or maybe you will not be using a shield but you still want Arduino as the brain of your project. The following pic shows how a bread board has to be physically:

Software A sketch is the name that Arduino uses for a program. It is the unit of a code that is uploaded to and run on an Arduino board. In order to make all this work hardware together, I wrote 9 libraries plus 2 extra which are added as parallel sketch and make the HX 711 work. All these libraries can be downloaded from https://github.com/ . Wherever prudent, each library has #include statements for various configurations elements. This makes the library easily reusable. The library names are articulated onto the main sketch. Main Sketch This is the main code which makes the software talk to the hardware doing what I have finally intended in the Project. /*-----( Libraries )-----*/ #include "DHT.h" 10

Manual BeeHive Project #include #include #include #include #include "HX711.h" #include #include "RTClib.h" #include /*-----( Declare Constants and Pin Numbers )-----*/ File logfile; #define DHTPIN 4 #define SYNC_INTERVAL 1800 // 30 minutes or 1800 seconds #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 #define ONE_WIRE_BUS_PIN 5 // DS18B20 uint32_t syncTime = 0; const int ChipSelect = 10;

/*-----( Declare Objects and Variables )-----*/ U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); RTC_DS1307 rtc; DHT dht(DHTPIN, DHTTYPE); OneWire oneWire(ONE_WIRE_BUS_PIN); DallasTemperature sensors(&oneWire);// Pass the oneWire reference to Dallas Temperature. DeviceAddress Probe01 = { 0x28, 0xB2, 0xCB, 0x5E, 0x06, 0x00, 0x00, 0x39 }; BH1750 lightMeter; HX711 cell(3, 2); long val = 0; int count = 0; char buf1[20]; char floatStr[9]; float humidity; float tempC; float tempF;

11

Manual BeeHive Project float tempOutC; uint16_t lightLevel;

//*-----PROGRAM SET-UP-----*// void setup() //SET-UP: RUNS ONCE { Serial.begin(9600); // Initialize the serial monitor if (!SD.begin(ChipSelect)) // Initialize the SD card and set up the file on the SD card { Serial.println(F("Card failed, or not present")); } char filename[] = "LOGGER00.CSV";

// Open the output file on the SD card

for (uint8_t i = 0; i < 200; i++) { filename[6] = i/10 + '0'; filename[7] = i%10 + '0'; if (! SD.exists(filename)) { logfile = SD.open(filename, FILE_WRITE); // only open a new file if it doesn't exist break; // leave the loop! } } rtc.begin();// Set the clock. This string has been reduced as a single code because the RTC has been previously programmed with the sketch RTC-Check and RTC-Set which are explained after the main one.

dht.begin();// Initialize the sensors sensors.begin(); sensors.setResolution(Probe01, 10); lightMeter.begin();

// Write the column headers to the CSV file logfile.println(F("Date/Time,Temp (box),Humidity (box),Temp.(hive),Light (box),Weight (Kg)")); u8g.setFont(u8g_font_fixed_v0); // Set the font for the OLED display

12

Manual BeeHive Project } //*-----END PROGRAM SET-UP-----*//

//*-----PROGRAM LOOP-----*// void loop() //LOOP: RUNS CONSTANTLY { DateTime now = rtc.now(); // Get the current date/time sprintf(buf1, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year()); Serial.print(F("Date/Time: ")); Serial.println(buf1);

val = cell.read(); // Get Load cell reading Serial.print(F("Weight: ")); Serial.println ((val-131575)/(34500.5714f)); //Calibration code for the load cell. Equation obtained after having calibrated the load cell as described below in the next point.

lightLevel = lightMeter.readLightLevel(); // Read the light level Serial.print(F("Lux: ")); Serial.println(lightLevel);

humidity = dht.readHumidity(); // Get temperature and humidity readings tempC = dht.readTemperature(); // Read temperature as Celsius (the default) tempF = dht.readTemperature(true);// Read temperature as Fahrenheit (it is Fahrenheit = true)

Serial.print(F("Humidity: ")); Serial.println(humidity); Serial.print(F("tempC: ")); Serial.println(tempC); Serial.print(F("tempF: ")); Serial.println(tempF);

sensors.requestTemperatures(); // Command all devices on bus to read temperature DS18B20 sensor

13

Manual BeeHive Project tempOutC = sensors.getTempC(Probe01); Serial.print(F("tempOutC: ")); Serial.println(tempOutC);

if (isnan(humidity) || isnan(tempC) || isnan(tempF) || // Check if any reads failed and exit early (to try again) isnan(lightLevel) || isnan(val) || isnan(tempOutC)) { Serial.println("Error reading sensor value"); return; } u8g.firstPage(); // Output data to the Oled do { draw(); } while( u8g.nextPage() ); if((count % SYNC_INTERVAL) ==0) //Output data to the log file { outputLog(); } delay(1000);

count = count + 1; // Increments the loop counter if(count > SYNC_INTERVAL) { count = 1; } } void draw() //Setting code to get the readings on the LED { u8g.setPrintPos(1,7); u8g.print(F("Temp (box): ")); u8g.print(ftoa(floatStr, tempC, 2));

14

Manual BeeHive Project u8g.setPrintPos(1,15); u8g.print(F("Humidity (box): ")); u8g.print(ftoa(floatStr, humidity, 2));

u8g.setPrintPos(1,23); u8g.print(F("Temp (Hive): ")); u8g.print(ftoa(floatStr, tempOutC, 2));

u8g.setPrintPos(1,31); u8g.print(F("Lux (box): ")); u8g.print(lightLevel);

u8g.setPrintPos(1,39); u8g.print(F("Weight(Kg): ")); u8g.print((val-131575)/(34500.5714f)); //Displays the weight

u8g.setPrintPos(1,55); u8g.print(buf1); }

void outputLog() { // Date/Time,Temp Inside,Humidity Inside,Temp. Outside,Light,Weight in kg logfile.print(buf1); // Writes the Date/Time logfile.print(F(","));

logfile.print(ftoa(floatStr, tempC, 2)); // Writes the inside temperature logfile.print(F(","));

logfile.print(ftoa(floatStr, humidity, 2)); // Writes the humidity logfile.print(F(","));

logfile.print(ftoa(floatStr, tempOutC, 2)); // Writes the outside temperature logfile.print(F(",")); 15

Manual BeeHive Project

logfile.print(lightLevel); // Writes the light value logfile.print(F(","));

logfile.println((val-131575)/(34500.5714f)); // Write the weight logfile.flush(); } char *ftoa(char *a, double f, int precision) // Converts floating point real numbers to ASCII string equivalent { for(byte i=0; i= 100 #include "Arduino.h" #else

16

Manual BeeHive Project #include "WProgram.h" #endif

pinMode(PD_SCK, OUTPUT); pinMode(DOUT, INPUT);

class HX711 { private:

set_gain(gain); }

byte PD_SCK; // Power Down and Serial Clock Input Pin byte DOUT; // Serial Data Output Pin byte GAIN; // amplification factor long OFFSET; // used for tare weight float SCALE; // used to return weight in grams, kg, ounces, whatever

HX711::~HX711() { } bool HX711::is_ready() { return digitalRead(DOUT) == LOW; } void HX711::set_gain(byte gain) { switch (gain) { case 128: // channel A, gain factor 128 GAIN = 1; break; case 64: // channel A, gain factor 64 GAIN = 3; break; case 32: // channel B, gain factor 32 GAIN = 2; break; } digitalWrite(PD_SCK, LOW); read(); } long HX711::read() { // wait for the chip to become ready while (!is_ready());

public: // define clock and data pin, channel, and gain factor // channel selection is made by passing the appropriate gain: 128 or 64 for channel A, 32 for channel B // gain: 128 or 64 for channel A; channel B works with 32 gain factor only HX711(byte dout, byte pd_sck, byte gain = 128); virtual ~HX711(); // check if HX711 is ready // from the datasheet: When output data is not ready for retrieval, digital output pin DOUT is high. Serial clock // input PD_SCK should be low. When DOUT goes to low, it indicates data is ready for retrieval. bool is_ready(); // set the gain factor; takes effect only after a call to read() // channel A can be set for a 128 or 64 gain; channel B has a fixed 32 gain // depending on the parameter, the channel is also set to either A or B void set_gain(byte gain = 128);

unsigned long value = 0; byte data[3] = { 0 }; byte filler = 0x00; // pulse the clock pin 24 times to read the data data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST); data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST); data[0] = shiftIn(DOUT, PD_SCK, MSBFIRST);

// waits for the chip to be ready and returns a reading long read();

// set the channel and the gain factor for the next reading using the clock pin for (unsigned int i = 0; i < GAIN; i++) { digitalWrite(PD_SCK, HIGH); digitalWrite(PD_SCK, LOW); }

// returns an average reading; times = how many times to read long read_average(byte times = 10);

// Datasheet indicates the value is returned as a two's complement value // Flip all the bits

// returns (read_average() - OFFSET), that is the current value without the tare weight; times = how many readings to do double get_value(byte times = 1);

17

Manual BeeHive Project data[2] = ~data[2]; data[1] = ~data[1]; data[0] = ~data[0]; // Replicate the most significant bit to pad out a 32-bit signed integer if ( data[2] & 0x80 ) { filler = 0xFF; } else if ((0x7F == data[2]) && (0xFF == data[1]) && (0xFF == data[0])) { filler = 0xFF; } else { filler = 0x00; } // Construct a 32-bit signed integer value = ( static_cast(filler)