My Cart

Open Aquarium - Aquaponics and Fish Tank Monitoring for Arduino

Difficulty Level: Expert -


Open Aquarium has been designed to help you to take care of your fish by automating the control and maintenance tasks that take place in the fish tanks and ponds. Open Aquarium consists of two different and complementary kits: Basic and Aquaponics, and many several extra accessories.

There are 5 sensors available in the platform to measure the key parameters in the fish tank such as temperature, pH or Conductivity and then some others to control the correct state of the fish tank (level and leakages). In addition, there are 4 different actuators to automate tasks such as heating or cooling the water, feeding the fish, activating the pumps for water change or medicines administration, and controlling the intensity of the light to simulate the day/night cicles.

A complete Open Source API is included to easily control the board through Arduino. And we have also designed a web application that allows to store in a data base the information gathered and visualize it from a browser and from iPhone / Android devices. We have released it as Open Source code too, so that you can improve it and make it personal for your own product!

Open Aquarium has been designed to work with both 220V (Europe) & 110V (US). For more info go to the "Electrical Features section"

Basic Kit: Buy now

Aquaponics Kit: Buy now

Article Index

  1. Features
  2. The shield
  3. The library
  4. Open Aquarium Basic
  5. Open Aquarium Aquaponics
  6. Extra accesories
  7. Sending the data to a Web Server
  8. Visualizing the data
  9. Device Compatibility
  10. Forum
  11. Get the shields and kits

DISCLAIMER: A bad use or failure of the elements of Open Aquarium (heaters, fan cooler, etc) may vary the ideal living conditions of the fish risking their lives. Please have this into account when setting the system in your fish tank. Open Aquarium is an educational and experimentation platform. Try the system on a fish tank with no fish in it until you get the right conditions and check the system stability during some weeks.

1. Features

The pack we are going to use in this tutorial is the Open Aquarium platform from Cooking Hacks. Open Aquarium is fully compatible with Arduino UNO.

Electrical Features

Open Aquarium must be powered by an external power supply (12V - 2A).

Open Aquarium has been designed to work with both 220V (Europe) & 110V (US). To use the RF Power Strip in 110V power setups you just need to use this 110-220V Power Converter.

Wireless communication

Open Aquarium gateway communicates with the RF power strip with FSK modulation (Frequency-shift keying) at 433MHz.

Can I use the 433MHz radios included in Open Aquarium in the US?

Yes. The US Federal Communications Commission (FCC) regulates operation at 433 MHz under Regulation 10CFR47 Part 15.231. This frequency band is intended for remote control, although some other usages are possible with some restrictions:

  • The duration of each transmission shall not be greater than one second and the silent period between transmissions shall be at least 30 times the duration of the transmission but in no case less than 10 seconds.
  • Transmissions may last 300mSec every 10 seconds.
  • Data transmissions can not exceed 2000ms per hour. This means we can send data intervals of at least 10 seconds from each node to the gateway.
  • Transmission Power must be at maximum 10,000uV/meter at 3 meters. The radio and antennas provided with open Aquarium have less power than the maximum permitted.

References:

http://www.ti.com/lit/an/swra090/swra090.pdf

Steve Montgomery, General Manager, Digital Six Laboratories, LLC, 11/26/2013

Can I use the 433MHz radios included in Open Aquarium in Europe?

Yes. The 433MHz band is unlicensed and free of use in Europe. For extra information about the R&TTE / CEPT / ETSI directive read the next document.

http://www.ti.com/lit/an/swra090/swra090.pdf

2. The Shield

2.1 Open Aquarium Shield

2.2 Open Aquarium Aquaponics

2.3 Open Aquarium over Arduino

3. The Library

Open Aquarium counts with a C++ library that lets you read easily all the sensors and send the information by using any of the available radio interfaces. This library offers an simple-to-use open source system.

3.1 Using the library with Arduino

Open Aquarium includes a high level library functions for a easy manage of the board. Before start using this functions you should download the files from this link. This zip includes all the files needed in one folder, "OpenAquarium". Copy this folder in the arduino IDE folder "libraries". Don't forget include these libraries in your codes.

Download the Open Aquarium Libraries for Arduino.

Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of the library. Inside the folder will be the .cpp files, .h files and often a keywords.txt file, examples folder, and other files required by the library.

To install the library, first quit the Arduino application. Then uncompress the ZIP file containing the library. For installing Open Aquarium library , uncompress OpenAquarium.zip. It should contain a folder called "Open Aquarium", with files like OpenAquarium.cpp and OpenAquarium.h inside. Drag the Open Aquarium folder into this folder (your libraries folder). Under Windows, it will likely be called "My Documents\Arduino\libraries". For Mac users, it will likely be called "Documents/Arduino/libraries". On Linux, it will be the "libraries" folder in your sketchbook.

The library won't work if you put the .cpp and .h files directly into the libraries folder or if they're nested in an extra folder. Restart the Arduino application. Make sure the new library appears in the Sketch->Import Library menu item of the software.

That's it! You've installed a library!

3.2 General Open Aquarium functions

Open Aquarium Gateway functions

Sensor initializing functions:

init()	  		  //Include: initports(), welcome(),initDS18B20() and initRTC()
initports()     	  //Initialize all ports
welcome()	  	  //Print a welcome message
            

Lighting program:

lighting()          	  //Give necessary day light for fish depending on time
fadelight()        	  //Fading light
lightON()         	  //Turn ON the light
lightOFF()	   	  //Turn OFF the light
            

Leak functions:

leak() 			  //If water leakage detected, turn off all pumps and an alarm sounds
            

Delete variable function:

newday() 		  //Delete all variables
            

Feed fish functions:

feedfish() 		  //Makes a rotation of the automatic fish feeder
readyforfeeding()	  //Prepare feeder for feeding
            

Water change functions:

empty() 		  //Empty aquarium, turns ON pump1 until level2 detected and dosing drops
fill()			  //Fill aquarium after empty turning ON pump2 until level1 detected
            

Water level functions:

waterlevel1() 		  //Get the status of the water level 1 and print a message
waterlevel2() 		  //Get the status of the water level 2 and print a message
readwaterlevel(out)	  //Get  the status of the water level 1 or 2
            

Pumps functions:

pumpON(out) 		  //Turn ON the water pump with the number "out"
pumpOFF(out) 		  //Turn OFF the water pump with the number "out"
perpumpON(out)		  //Turn ON the peristaltic pump with the number "out"
perpumpOFF(out)		  //Turn OFF the peristaltic pump with the number "out"
            

Buzzer functions:

alarm() 		  //Alarm sound
playTone() 		  //Makes song sound
openingsong()		  //Makes a melody with buzzer
            

RTC functions:

initRTC()       	  //Initializing necessary for the RTC
setTime()       	  //Get the computer's time and date
getTime()       	  //Get a struct with current time and date
printTime(now)  	  //Serial print the struct obtained with getTime
            

Power strip functions:

sendPowerStrip(plug)      //Send a signal to turn on or off a plug
            

DS18B20 functions:

initDS18B20() 		  //Initializing necessary for sensor DS18B20
readtemperature()  	  //Return the value of the DS18B20  sensor
tempcontrol(temperature)  //Temperature control with Power strip (25-27┬░C).Heater in socket 5 and
 			  //fan cooler in 4. An alarm sounds if temperature is higher than 30┬░C
            

Aquaponics functions:

calibratepH(calibration_point_4,calibration_point_7,calibration_point_10) //pH sensor calibration
readpH()   	  		//Return  pH value in mV
pHConversion(mvpH)		//Returns the value of the pH sensor
calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal) 	//EC sensor calibration
readResistanceEC()   	  	//Returns EC Value in resistance
ECConversion(_resistanceEC)	//Returns EC Value in ┬ÁS/cm
            

4. Open Aquarium Basic

The complete kit can be found here.

The parts of this kit are:

  • 1x Gateway Shield for Arduino
  • 1x Aquarium Automatic Feeder
  • 1x DS18B20
  • 1x Water level
  • 1x 12V Power Supply
  • 2x Flange
  • 2x Suction cups
  • 1x Fish Feeder Cable
  • 1x Fish Feeder Connector
  • 1x OpenAquarium box
  • 1x Big Enclosure for gateway
  • 3x 20mm Cable Glands
  • 1x Vent Plug
  • 4x M3 Metal Nuts
  • 4x M3 x 10mm Metal Screws

4.1 DS18B20 - Water temperature sensor

Sensor Features

This sealed digital temperature probe lets you precisely measure temperatures in wet environments with a simple 1-Wire interface. The DS18B20 sensor provides 9 to 12-bit (configurable) temperature readings over a 1-Wire interface, so that only one wire (and ground) needs to be connected from a central microprocessor.

Features:

  • 3.0-5.5V input voltage
  • Waterproof
  • -55°C to+125°C temperature range
  • ±0.5°C accuracy from -10°C to +85°C
  • 1 Wire interface
  • Connecting the sensor

    The DS18B20 sensor has three connections (positive, negative and data).

    Gateway connection

    Connect the red wire with the positive terminal (marked as "VCC" in the board), the black wire with the negative terminal (marked as "GND" in the board) and the white wire with the Data terminal (marked as "DATA" in the board).

    After connecting the cables, tighten the screws.

    Library Functions

    Getting data:

    The water temperature can be read with a simple function. This function return a float with the value.

    Example:

    {
          temperature = OpenAquarium.readtemperature();
    }
                

    Example

    Upload the next code for seeing water temperature in the serial monitor:

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    float temperature;
    
    void setup() {
      OpenAquarium.init();   //Initialize
      Serial.begin(115200);
    }
    
    void loop() {
    
      temperature = OpenAquarium.readtemperature(); //Read the sensor
      
      Serial.print("Temperature: ");
      Serial.print(temperature);
      Serial.println("'C");
      delay(2000); //Wait 2 seconds
    
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    4.2 RTC - DS1307

    Features

    The Open Aquarium gateway has a built in Real Time Clock (RTC), which keeps it informed of the time. This allows Open Aquarium to be programmed to perform time-related actions.

    Features:

    • Based on the clock chip DS1307
    • I2C Serial Interface
    • Needs a lithium cell battery (CR1225)
    • Provides seconds, minutes, hours, date of the month, day of the week,month, and year information with Leap-Year Compensation
    • The end of the month date is automatically adjusted for months with fewer than 31 days
    • 56-Byte, Battery-Backed, Nonvolatile (NV)RAM for Data Storage
    • 5V DC supply
    • Programmable Square-Wave Output Signal
    • Automatic Power-Fail Detect and Switch Circuitry
    • Consumes Less than 500nA in Battery-Backup Mode with Oscillator Running

    Library Functions

    Setting the time:

    The RTC can be synchronized with the computer with this function in the setup()

    {
          OpenAquarium.setTime(); //write time to the RTC chip
    }
            

    Getting the time:

    You can read the date and time with this function

    {
          now = OpenAquarium.getTime(); //Get date and time
    }
            

    Example

    Setting the time:

    Upload the next code to set the time:

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    
    DateTime now;
    
    void setup() {
      Serial.begin(115200);
      OpenAquarium.initRTC(); //Initialize RTC
      OpenAquarium.setTime(); //write time to the RTC chip
    }
    
    void loop() {
      delay(1000);
    }			
    		

    Getting the time:

    Upload the next code to get the time:

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    
    DateTime now;
    
    void setup() {
      Serial.begin(115200);
      OpenAquarium.initRTC();  
    }
    
    void loop() {
        now = OpenAquarium.getTime(); //Get date and time
        
        //First way: Print date and time at once
        Serial.print("1er way: ");
        OpenAquarium.printTime(now);  
        
        
        //Second way: separate variables
        Serial.print("2nd way: ");
        Serial.print(now.month(), DEC);
        Serial.print("/");
        Serial.print(now.day(), DEC);
        Serial.print("/");
        Serial.print(now.year(), DEC);
        Serial.print(" ");
        
         switch (now.dayOfWeek()) // Friendly printout the weekday
        {
    		case 1:
    		  Serial.print("MON");
    		  break;
    		case 2:
    		  Serial.print("TUE");
    		  break;
    		case 3:
    		  Serial.print("WED");
    		  break;
    		case 4:
    		  Serial.print("THU");
    		  break;
    		case 5:
    		  Serial.print("FRI");
    		  break;
    		case 6:
    		  Serial.print("SAT");
    		  break;
    		case 7:
    		  Serial.print("SUN");
    		  break;
    	}
    	Serial.print(" ");
    
        Serial.print(now.hour(), DEC);
        Serial.print(":");
        Serial.print(now.minute(), DEC);
        Serial.print(":");
        Serial.println(now.second(), DEC);
         
         
        delay(1000);
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    4.3 Water level

    Sensor features

    Freatures:

    • Max power: 10W
    • Max switching voltage: 100V
    • Max switching current: 0,5A
    • Max breakdown voltage: 220V
    • Max load current: 1A
    • Max contact resistance: 100mΩ
    • Temperature range: -10 ~ +85 Degree

    Connecting the sensor

    Water level has two connections. Connect the wires in the water level connector. The contacts have not polarization.

    Gateway connection

    Connect two wires into the terminal. Wires position doesn't matter.

    After connecting the cables, tighten the screws.

    Library Functions

    Getting data:

    The water level switch can be read with two simple functions and you can also choose the number of water level to read.

    Example:

    {
              OpenAquarium.waterlevel1();
              OpenAquarium.readwaterlevel(2);
    }
            

    Example

    Upload the next code for seeing data in the serial monitor:

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    int status=0;
    
    void setup() {
      OpenAquarium.init();   //Initialize
      Serial.begin(115200);
    }
    
    void loop() {
      Serial.println("1st way");
      OpenAquarium.waterlevel1();
      delay(1000); //Wait 2 seconds
      Serial.println("2nd way");
       status = OpenAquarium.readwaterlevel(1);
      if (status==HIGH){
        Serial.println("Aquarium full");
      }
      if (status==LOW){
        Serial.println("Aquarium empty");
      }
      Serial.println("");
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    4.4 Fish feeder

    Actuator Features

    Features:

    • Programmable feeder
    • Powered by: 3,3 V
    • Size:11 x 6.5x 10.7 cm

    Connecting the actuator

    The Automatic Fish Feeder has only one connector.

    Gateway connection

    Bend the connector and insert it into the bigger gland.

    Connect it into the "FEEDER" connector.

    Library Functions

    Actuating:

    Makes a rotation of the fish feeder.

    Example:

    {
               OpenAquarium.feedfish();
               OpenAquarium.readyforfeeding();
    }
            

    Example

    Upload the next code for feeding fish at 11:30 and at 23:30:

    NOTE: If you want to feed your fish more than one time a day you have to use readyforfeeding() function one minute before feed them..

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    #include "OpenAquarium.h"
    #include "Wire.h"
    DateTime now;
    
    void setup(){
      Serial.begin(115200);
      OpenAquarium.init();
    }
    
    void loop(){
      
      now =OpenAquarium.getTime();
      OpenAquarium.printTime(now);
        	   
      if (now.hour() == 11 && now.minute() == 30){
      OpenAquarium.feedfish(); 
      }
     if (now.hour() == 23 && now.minute() == 29){
      OpenAquarium.readyforfeeding(); 
      }
     if (now.hour() == 23 && now.minute() == 30){
      OpenAquarium.feedfish(); 
      }
    if (now.hour() == 23 && now.minute() == 59){
      OpenAquarium.newday(); 
      }
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    4.5 Full example

    Upload the next code for a full example of Open Aquarium Basic.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    #include "OpenAquarium.h"
    #include "Wire.h"
    float temperature;
    DateTime now;
    void setup(){
    Serial.begin(115200);
    OpenAquarium.init();
    }
      
    void loop(){
      
      now =OpenAquarium.getTime();
      OpenAquarium.printTime(now);
      
      temperature=OpenAquarium.readtemperature();
      Serial.println(temperature);
       
      OpenAquarium.waterlevel1();
       
      if (now.hour() == 11 && now.minute() == 30){
      OpenAquarium.feedfish(); 
      }
      
      if (now.hour() == 23 && now.minute() == 59){
      OpenAquarium.newday();
      }
      delay(500);
    }
    		
    		

    Step 1:

    Insert a flange on a suction cup.

    Step 2:

    Put the suction cup arround the water level and tight it right.

    Step 3:

    Insert the water level into your aquarium. Water level must be completely submerged.

    Step 4:

    Take another flange with a suction cup and hold the DS18B20 cable.

    Step 5:

    Place the temperature sensor into your aquarium and sitck it to the wall. The sensor must be inserted at least 4 cm in water.

    Step 6:

    Hang the fish feeder on the edge of your aquarium.

    Step 7:

    Screw it right to the wall.

    Step 8:

    Power OpenAquarium.

    5. Open Aquarium Aquaponics

    The complete kit can be found here.

    The parts of this kit are:

    • 1x Aquaponics extension
    • 1x Electro-conductivity sensor
    • 1x pH sensor
    • 1x SMA-BNC pigtail
    • 2x Flange
    • 2x Suction cups

    NOTE: Aquaponics extension needs Open Aquarium shield in order to work.

    5.1 pH sensor

    Sensor Features

    Features:

    • Measure range: 0~14pH
    • Applicable temperature: 0~60°C
    • BNC connector
    • Cable: 2.9 meter
    • Analogic output

    Connecting the sensor

    The pH sensor probe has only one connector which integrates all the different wires of the sensor. It is a BNC connector.

    You can connect it directly to the Open Aquarium Aquaponics board.

    After connecting the cable, tighten the connector.

    Library functions

    Getting data

    With this functions we can read the value of the sensor.

    Example:

    {
    	OpenAquarium.calibratepH(calibration_point_4,calibration_point_7,calibration_point_10);
    	int mvpH = OpenAquarium.readpH(); //Value in mV of pH
    	float pH = OpenAquarium.pHConversion(mvpH); //Calculate pH value
    }
    			

    Calibrating the sensor

    In order to calibrate the pH sensor you can buy the pH calibration kit calibration kit and obtain the pH values in mV (millivolts) with the function OpenAquarium.readpH() for the three values of pH. Now you must change the #defines in the top of the sketch.

    #define calibration_point_4 2153  //Write here your measured value in mV of pH 4
    #define calibration_point_7 1972  //Write here your measured value in mV of pH 7
    #define calibration_point_10 1816 //Write here your measured value in mV of pH 10
    			

    Example

    Upload the next code for seeing data in the serial monitor.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    
    #define calibration_point_4 2221  //Write here your measured value in mV of pH 4
    #define calibration_point_7 2104  //Write here your measured value in mV of pH 7
    #define calibration_point_10 2031 //Write here your measured value in mV of pH 10
    
    
    void setup() {
      Serial.begin(115200);
      OpenAquarium.init();
      OpenAquarium.calibratepH(calibration_point_4,calibration_point_7,calibration_point_10);
      delay(1000);
    }
    
    void loop() {
    
      int mvpH = OpenAquarium.readpH(); //Value in mV of pH
      Serial.print(F("pH Value in mV = "));
      Serial.print(mvpH);
    
      Serial.print(F(" // pH = "));
      float pH = OpenAquarium.pHConversion(mvpH); //Calculate pH value
      Serial.println(pH);
    
      delay(2000);  //Wait two seconds
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    NOTE: When you use the pH sensor you can't use the level number 2. However you can still using level 1.

    5.2 Electro-conductivity sensor

    Sensor Features

    Features:

    • Applicable temperature: 0~60°C
    • BNC connector
    • Cable: 2.9 meter
    • Analogic output

    Connecting the sensor

    The electro-conductivity sensor probe has two connections. Connect the wires in the EC connector. The contacts have not polarization.

    After connecting the cable, tighten the connector.

    Library functions

    Getting data

    With this simple function we can read the value of the sensor.

    Example:

    {
    	OpenAquarium.calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal);
    	float resistanceEC = OpenAquarium.readResistanceEC(); //EC Value in resistance
    	float EC = OpenAquarium.ECConversion(resistanceEC); //EC Value in ┬ÁS/cm
    }
    			

    Calibrating the sensor

    In order to calibrate the electro-conductivity sensor you can buy the conductivity calibration kit and obtain the EC values in resistance with the function OpenAquarium.readResistanceEC() for two values of EC. Now you must change the #defines in the top of the sketch. For example if you use the calibration kit with 10500 ┬ÁS/cm and 40000 ┬ÁS/cm you will need to write something like this:

    #define point_1_cond 40000   // Write here your EC calibration value of the solution 1 in µS/cm
    #define point_1_cal 40       // Write here your EC value measured in resistance with solution 1
    #define point_2_cond 10500   // Write here your EC calibration value of the solution 2 in µS/cm
    #define point_2_cal 120      // Write here your EC value measured in resistance with solution 2
                    

    Example

    Upload the next code for seeing data in the serial monitor.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    
    #define point_1_cond 40000   // Write here your EC calibration value of the solution 1 in µS/cm
    #define point_1_cal 40       // Write here your EC value measured in resistance with solution 1
    #define point_2_cond 10500   // Write here your EC calibration value of the solution 2 in µS/cm
    #define point_2_cal 120      // Write here your EC value measured in resistance with solution 2
    
    
    void setup() {
      Serial.begin(115200);
      OpenAquarium.init(); 
      OpenAquarium.calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal);
      delay(500);
    }
    
    void loop() {
    
      float resistanceEC = OpenAquarium.readResistanceEC(); //EC Value in resistance
      Serial.print(F("EC Value in resistance = "));
      Serial.print(resistanceEC);  
    
      Serial.print(F(" // EC Value = "));
      float EC = OpenAquarium.ECConversion(resistanceEC); //EC Value in µS/cm
      Serial.print(EC);
      Serial.println(F(" uS/cm"));
    
    
    
      delay(2000);   //Wait 2 seconds
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    NOTE: When you use the electro-conductivity sensor you can't use the dosing pump number 3. However you can still using dosing pumps number 1 and 2.

    5.3 Full example

    Upload the next code for a full example of Open Aquarium Aquaponics.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    
    #define point_1_cond 40000   // Write here your EC calibration value of the solution 1 in ┬ÁS/cm
    #define point_1_cal 40       // Write here your EC value measured in resistance with solution 1
    #define point_2_cond 10500   // Write here your EC calibration value of the solution 2 in ┬ÁS/cm
    #define point_2_cal 120      // Write here your EC value measured in resistance with solution 2
    
    
    #define calibration_point_4 2221  //Write here your measured value in mV of pH 4
    #define calibration_point_7 2104  //Write here your measured value in mV of pH 7
    #define calibration_point_10 2031 //Write here your measured value in mV of pH 10
    
    void setup(){
      Serial.begin(115200);
      OpenAquarium.init(); 
      OpenAquarium.calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal);
      OpenAquarium.calibratepH(calibration_point_4,calibration_point_7,calibration_point_10);
      delay(500);
    }
    
    void loop(){
    
      float resistanceEC = OpenAquarium.readResistanceEC(); //EC Value in resistance
      Serial.print(F("EC Value in resistance = "));
      Serial.print(resistanceEC);  
    
      Serial.print(F(" // EC Value = "));
      float EC = OpenAquarium.ECConversion(resistanceEC); //EC Value in ┬ÁS/cm
      Serial.print(EC);
      Serial.println(F(" uS/cm"));
      
      int mvpH = OpenAquarium.readpH(); //Value in mV of pH
      Serial.print(F("pH Value in mV = "));
      Serial.print(mvpH);
    
      Serial.print(F(" // pH = "));
      float pH = OpenAquarium.pHConversion(mvpH); //Calculate pH value
      Serial.println(pH);
      
      delay(2000);
      }			
    		

    Step 1:

    Insert a flange on a suction cup.

    Step 2:

    Fix the pH sensor with the flange.

    Step 3:

    Insert the pH sensor into the water. The sensor must be inserted at least 4 cm in water.

    Step 4:

    Insert another flange on a suction cup and fix the electroconductivity sensor.

    Step 5:

    Insert the electroconductivity sensor in the water. The sensor must be inserted at least 4 cm in water.

    Step 6:

    Power OpenAquarium.

    6. Extra accesories

    6.1 Gateway box

    To facilitate the installation of Open Aquarium, the kits include different types of boxes. In this step, we will explain you a way to mount the box but it is only an example. You can set the box as you want depending on the number of sensors, the type of power supply, the number of actuators or the place where you are going to place the box.

    You can differentiate between two types of boxes.

    To mount this box, you will need the following material.

    First, you have to put the glands and the vent plug in the different holes of the box.

    You have to tight the nuts.

    Once the glands are fixed, you need to fix the Arduino to the internal plate with four M3 screws and nuts.

    Then, you have to fix the plate to the box.

    Now you have to take the Open Aquarium Gateway and screw the sensor and actuators in the correct position.

    Mind the wires position.

    You can choose the nearest gland to screw the sensor easily.

    After that tighten all the glands, put on the Open Aquarium Gateway over the Arduino.

    Finally, you can close the box.

    And you have got the gateway box ready to use.

    6.2 Gateway with Aquaponics box

    To mount this box, you will need the following material.

    First, you have to put the glands in the different holes of the box and tight their nuts.

    Once the glands are fixed, you need to fix the Arduino to the internal plate with four M3 screws and nuts.

    Then, you have to fix the plate to the box.

    Then, you have to take the Open Aquarium Gateway and screw the sensor and actuators in the correct position.

    Now take the Aquaponics extension board and put it over Open Aquarium shield.

    Screw the EC sensor

    Now put the BNC pigtail in the box.

    Connect the pH sensor to the external BNC connector.

    Connect the BNC pigtail to the Aquaponics extension.

    Now put the Open Aquarium Gateway over the Arduino and the RF communication module.

    Finally you can close the box. You have got the gateway box with Aquaponics ready to use.

    6.3 RF Power Strip

    Open Aquarium has been designed to work with both 220V (Europe) & 110V (US). To use the RF Power Strip in 110V power setups you just need to use this 110-220V Power Converter.

    RF Power Strip Features

    Features:

    • Working voltage: 240V, 50Hz
    • Max. Load Power: 2400W
    • Transmission frequency: 433,92MHz
    • Standby power consumption: 0,3W

    RF link Features

    Features:

    • Frequency: 433Mhz
    • Modulation: ASK

    Connecting the actuator

    To use this actuator you will need the following materials:

    • RF Power strip and remote control
    • Arduino
    • Open Aquarium shield
    • Antenna
    • RF receiver
    • RF transmitter
    • Cable USB Arduino

    First, you need to power the RF Power Strip.

    Then, connect the shield to the computer with the USB cable, put the antenna and put the jumpers in the correct position (RX, at the right).

    Connect the RX module to the Open Aquarium gateway.

    Once you have got the device ready for reading the values of the remote control, you need to upload the reading RF code to your Arduino.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
     
    #include "OpenAquarium.h"
    #include "Wire.h"
    
    void setup() {
      Serial.begin(115200);
      RemoteReceiver::init(0, 2, readCodes);
    }
    
    
    void loop() {
    }
    
    
    void readCodes(unsigned long receivedCode, unsigned int period) { 
      RemoteReceiver::disable();
      interrupts();
      unsigned long code=receivedCode;
      code = code & 0xFFFFF;
      code |= (unsigned long)period << 23;  
      code |= 3L << 20; 
      Serial.println(code);
      RemoteReceiver::enable();
    }			
    		

    Now, open the serial monitor and press the different buttons of the remote control to a distance of 10 centimeters from the antenna and you will see the codes of each button.

    For example these are the received codes when you press the button 1 ON:

        1580367986
        1605533810
        1597145202
        1613922418
        1588756594
    			

    And these are the received codes when you press the button 1 OFF:

        1580367988
        1605533812
        1597145204
        1613922420
        1588756596
    			

    Please, note you receive multiple codes for a single button, all of them are valid, but we recommend choosing the value fixed when holding down the button for 2 seconds. You can also observe that both are often consecutive and have a difference of 2.

    For example we have choose these two codes:

      on1: 1613922418

      off1: 1613922420

    Save all your chosen codes for all the buttons in a .txt file.

    If you want to use tempcontrol(temperature) function in order to control your aquarium temperature you have to modify the library.

    Put your codes at the beginning of the OpenAquarium.h file and connect the heater in socket 5 and the fan cooler in socket 4.

    NOTE: You can also change temperature range in tempcontrol(temperature) function to adecuate it for your fish species.

    After that, put the jumpers in the correct position (TX, at the left).

    Now, change the RX module to the TX module.

    Once you have got the device ready for sending the values of the remote control, you need to put the saved codes of each button in the code and upload it to your Arduino.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    
    //Power strip codes. Please insert here your own codes generated with 
    //RF_Receive_remoteControl_codes
    unsigned long on1 = 1613922418;   
    unsigned long off1 = 1613922420;
    unsigned long on2 = 1597145220;
    unsigned long off2 = 1597145222;
    unsigned long on3 = 1597145112;
    unsigned long off3 = 1597145114;
    unsigned long on4 = 1597144950;
    unsigned long off4 = 1597144952;
    unsigned long on5 = 1597144464;
    unsigned long off5 = 1597144466;
    
    void setup() {
      Serial.begin(115200); 
    }
    
    
    void loop() {
       OpenAquarium.sendPowerStrip(on1); //Turn ON plug 1
       Serial.println("Plug 1: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off1);//Turn OFF plug 1
       Serial.println("Plug 1: OFF");
       delay(3000); //Wait five seconds
       
       
       OpenAquarium.sendPowerStrip(on2); //Turn ON plug 2
       Serial.println("Plug 2: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off2);//Turn OFF plug 2
       Serial.println("Plug 2: OFF");
       delay(3000); //Wait five seconds
    
    
       OpenAquarium.sendPowerStrip(on3); //Turn ON plug 3
       Serial.println("Plug 3: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off3);//Turn OFF plug 3
       Serial.println("Plug 3: OFF");
       delay(3000); //Wait five seconds
    
    
       OpenAquarium.sendPowerStrip(on4); //Turn ON plug 4
       Serial.println("Plug 4: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off4);//Turn OFF plug 4
       Serial.println("Plug 4: OFF");
       delay(3000); //Wait five seconds
    
    
       OpenAquarium.sendPowerStrip(on5); //Turn ON plug 5
       Serial.println("Plug 5: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off5);//Turn OFF plug 5
       Serial.println("Plug 5: OFF");
       delay(3000); //Wait five seconds
    }			
    			

    You will be able to see how it turns on and off all the plugs in your RF power strip.

    NOTE: When sending RF codes It's important that there is a minimum distance of 1 meter between the Open Aquarium antenna and the RF power strip. With smaller distances you can lose some pulses. Please check that you don't lose any pulse when your Open Aquarium is installed in the final place.

    Library Functions

    Actuating:

    The RF power strip can be activated with a simple function which must include the code of the plug that we want to actuate.

    Example:

    {
          OpenAquarium.sendPowerStrip(on1);  //Turn ON the plug number 1 
          OpenAquarium.sendPowerStrip(off3); //Turn OFF the plug number 3
    }
    			

    Example

    Upload the next code to turn on and off all the plugs in your RF power strip:

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include <OpenAquarium.h>
    #include <Wire.h>
    
    //Power strip codes. Please insert here your own codes generated with 
    //RF_Receive_remoteControl_codes
    unsigned long on1 = 1613922418;   
    unsigned long off1 = 1613922420;
    unsigned long on2 = 1597145220;
    unsigned long off2 = 1597145222;
    unsigned long on3 = 1597145112;
    unsigned long off3 = 1597145114;
    unsigned long on4 = 1597144950;
    unsigned long off4 = 1597144952;
    unsigned long on5 = 1597144464;
    unsigned long off5 = 1597144466;
    
    void setup() {
      Serial.begin(115200); 
    }
    
    
    void loop() {
       OpenAquarium.sendPowerStrip(on1); //Turn ON plug 1
       Serial.println("Plug 1: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off1);//Turn OFF plug 1
       Serial.println("Plug 1: OFF");
       delay(3000); //Wait five seconds
       
       
       OpenAquarium.sendPowerStrip(on2); //Turn ON plug 2
       Serial.println("Plug 2: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off2);//Turn OFF plug 2
       Serial.println("Plug 2: OFF");
       delay(3000); //Wait five seconds
    
    
       OpenAquarium.sendPowerStrip(on3); //Turn ON plug 3
       Serial.println("Plug 3: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off3);//Turn OFF plug 3
       Serial.println("Plug 3: OFF");
       delay(3000); //Wait five seconds
    
    
       OpenAquarium.sendPowerStrip(on4); //Turn ON plug 4
       Serial.println("Plug 4: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off4);//Turn OFF plug 4
       Serial.println("Plug 4: OFF");
       delay(3000); //Wait five seconds
    
    
       OpenAquarium.sendPowerStrip(on5); //Turn ON plug 5
       Serial.println("Plug 5: ON");
       delay(3000); //Wait five seconds
       OpenAquarium.sendPowerStrip(off5);//Turn OFF plug 5
       Serial.println("Plug 5: OFF");
       delay(3000); //Wait five seconds
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    6.4 Water leak sensor

    Sensor features

    Features:

    • Material: PE + alloy lead
    • Pull force limit : 60Kg
    • Core resistance : 3ohm/100 meters
    • Maximum exposed temperature: 75°C

    Connecting the sensor

    The water leak sensor has two connections. Connect the wires in the water leak connector. The contacts have not polarization

    Gateway connection

    Connect two wires into the terminal. Wires position doesn't matter.

    After connecting the cables, tighten the screws.

    Library Functions

    Read values:

    Leak sensor reads an analog value and makes alarm sound if it detects water presence.

    Example:

    {
          OpenAquarium.leak(); //Reads value of the leak sensor and make alarm sound
    }
    			

    Example

    Upload the next code for seeing data in the serial monitor. If there is water leakage, an alarm sound.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    
    void setup() {
      OpenAquarium.init();   //Initialize
      Serial.begin(115200);
    }
    
    void loop() {
      OpenAquarium.leak();
      delay(2000); //Wait 2 seconds
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    6.5 Fan Cooler

    Actuator Features

    Features:

    • Rated Voltage: DC12V
    • Rated Current: 0.43A
    • Max Air Flow: 13.6CFM
    • Max Air Pressure: 15.7mmAg
    • Acoustical Noise: <39dB
    • Operating Temperature -10~60°C

    Connecting the actuator

    You can connect the fan cooler in any of the available sockets in the RF power strip. If you are going to use tempcontrol(temperature) function you have to connect it in socket 4.

    Library functions

    Actuating:

    The RF power strip can be activated with a simple function which must include the code of the plug that we want to actuate.

    Example:

    {
          OpenAquarium.sendPowerStrip(on1);  //Turn ON the plug number 1 
          OpenAquarium.sendPowerStrip(off3); //Turn OFF the plug number 3
    }
    			

    Example

    Upload the next code to control the temperature between 26 and 28°C

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    float temperature;
    
    //Power strip codes
    unsigned long on1 = 1597145202;
    unsigned long off1 = 1597145204;
    unsigned long on2 = 1597145220;
    unsigned long off2 = 1597145222;
    unsigned long on3 = 1597145112;
    unsigned long off3 = 1597145114;
    unsigned long on4 = 1597144950;
    unsigned long off4 = 1597144952;
    unsigned long on5 = 1597144464;
    unsigned long off5 = 1597144466;
    
    void setup() {
      Serial.begin(115200); 
      OpenAquarium.init();
    }
    
    void loop() {
      
      temperature=OpenAquarium.readtemperature();
      Serial.println(temperature);
            
      if(temperature>28){ 
        OpenAquarium.sendPowerStrip(on4); //Turn ON plug 4
        Serial.println("Fan ON");
      }
      if(temperature<26){ 
        OpenAquarium.sendPowerStrip(off4); //Turn OFF plug 4
        Serial.println("Fan OFF");
      }
      delay(500);
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    6.6 Heater

    Actuator features

    Features:

    • Power: 100W
    • Voltage: 220/240V 50/60Hz
    • Length: 22cm
    • Diameter: 2.2cm
    • Length of power cord: 85cm
    • Recommended Tank Size: 20 to 33 gallon
    • Temperature range between 65┬░F and 93┬░F(17┬░C-35┬░C).
    • Fully submersible heaters work in any position (horizontal or vertical) to provide optimum aquarium water temperature.
    • Shatterproof glass.

    Connecting the actuator

    You can connect the heater in any of the available sockets in the RF power strip. If you are going to use tempcontrol(temperature) function you have to connect it in socket 5.

    Library Functions

    Actuating:

    The RF power strip can be activated with a simple function which must include the code of the plug that we want to actuate.

    Example

    {
          OpenAquarium.sendPowerStrip(on1);  //Turn ON the plug number 1 
          OpenAquarium.sendPowerStrip(off3); //Turn OFF the plug number 3
    }
    			

    Example

    Upload the next code to control the temperature between 25 and 27°C

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    float temperature;
    
    //Power strip codes
    unsigned long on1 = 1597145202;
    unsigned long off1 = 1597145204;
    unsigned long on2 = 1597145220;
    unsigned long off2 = 1597145222;
    unsigned long on3 = 1597145112;
    unsigned long off3 = 1597145114;
    unsigned long on4 = 1597144950;
    unsigned long off4 = 1597144952;
    unsigned long on5 = 1597144464;
    unsigned long off5 = 1597144466;
    
    void setup() {
      Serial.begin(115200); 
      OpenAquarium.init();
    }
    
    void loop() {
      
      temperature=OpenAquarium.readtemperature();
      Serial.println(temperature);
            
      if(temperature<25){ 
        OpenAquarium.sendPowerStrip(on5); //Turn ON plug 5
        Serial.println("Heater ON");
      }
      if(temperature>27){ 
        OpenAquarium.sendPowerStrip(off5); //Turn OFF plug 5
        Serial.println("Heater OFF");
      }
      delay(500);
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    6.7 Water pump

    Actuator features

    Features:

    • Flow: 100-350 L/H
    • 3.5-12 DC input voltage
    • Power range: 0.5W-5W
    • Submersible pump
    • Water output hole: 8 mm

    Connecting the actuator

    The water pump has two connections (positive and negative).

    Gateway connection

    Connect the brown wire with the positive terminal (marked with a "+"" in the board), the blue wire with the negative terminal. As you can see, you can connect this actuator in two different positions. Or, if you want, you can connect two different actuators.

    After connecting the cables, tighten the screws.

    Library Functions

    Actuating:

    The pump can be activated with a simple function which must include the number of pump (1 or 2)

    Example:

    After connecting the cables, tighten the screws.

    {
          OpenAquarium.pumpON(1);      //Turn ON the pump number 1 
          OpenAquarium.pumpOFF(2);     //Turn OFF the pump number 2
    }
    			

    Example

    Upload the next code to activate/deactivate the pump each five seconds:

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h" 
    
    void setup() {
      Serial.begin(115200);
      OpenAquarium.init();
    }
    
    void loop() {
      OpenAquarium.pumpON(1); //Turn ON the pump number 1 (insert 1 or 2)
      Serial.println("Pump 1: ON");
      delay (5000); //Wait five seconds
      
      OpenAquarium.pumpOFF(1); //Turn OFF the pump number 1 (insert 1 or 2)
      Serial.println("Pump 1: OFF");
      delay (5000); //Wait five seconds
    }			
    		

    6.8 Peristaltic pump

    Actuator features

    Features:

    • 12V DC input voltage
    • Flow: 20-60 ml/min
    • Working condition: 0-40°C
    • Relative humidity: <80%
    • Driver size(Ø x H):Dia.27.6 x Height 37.9 (mm)
    • Pump head size(Ø x H):Dia. 31.7 x Height 20.1(mm)
    • Pump tube size(ID x OD) :2.5*4.7mm

    Connecting the actuator

    The peristaltic pump has two connections (positive and negative).

    Gateway connection

    Connect the red wire with the positive terminal (marked with a "+"" in the board), connect the black wire with the remaining terminal. As you can see, you can connect this actuator in three different positions. Or, if you want, you can connect three different actuators.

    After connecting the cables, tighten the screws.

    Library Functions

    Actuating:

    The pump can be activated with a simple function which must include the number of pump (1, 2 or 3)

    Example:

    After connecting the cables, tighten the screws.

    {
          OpenAquarium.perpumpON(1);      //Turn ON the pump number 1 
          OpenAquarium.perpumpOFF(3);     //Turn OFF the pump number 3
    }
    			

    NOTE: If you want to use empty() function, you can choose number of drops changing it in OpenAquarium.h file

    Example

    Upload the next code to activate/deactivate the peristaltic pump each five seconds:

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h" 
    
    void setup() {
      Serial.begin(115200);
      OpenAquarium.init();
    }
    
    void loop() {
      OpenAquarium.perpumpON(1); //Turn ON the peristaltic pump number 1 (insert 1 or 2)
      Serial.println("Peristaltic pump 1: ON");
      delay (5000); //Wait five seconds
      
      OpenAquarium.perpumpOFF(1); //Turn OFF the peristaltic pump number 1 (insert 1 or 2)
      Serial.println("Peristaltic pump 1: OFF");
      delay (5000); //Wait five seconds
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    6.9 LED Lamp

    Actuator features

    Features:

    • Dimensions: 41 x 9 x 2cm (L x W x T)
    • Brackets add 4.5cm in height
    • Extendable brackets: 46.5~67cm
    • 72 LEDs
    • Color of LED: 60White + 12Blue)
    • Luminous Flux: 500 Lumen
    • 60 x 10000K LEDs
    • Uses 5.5 watts

    Connecting the actuator

    LED lamp has a mini jack connection - two connections (positive and negative)

    Gateway connection

    Connect the brown wire with the positive terminal (marked with a "VCC" in the board), the blue wire with the negative terminal (marked with a "GND" in the board).

    After connecting the cables, tighten the screws.

    Library Functions

    Actuating:

    Light intensity changes in order to simulate daylight

    Example:

    After connecting the cables, tighten the screws.

    {
          OpenAquarium.lighting(now);
    }
    		

    Example

    Upload the next code for lighting program:

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    DateTime now;
    
    void setup(){
      Serial.begin(115200);
      OpenAquarium.init();
    }
    
    void loop(){
      
      now =OpenAquarium.getTime();
      OpenAquarium.printTime(now);
      
      OpenAquarium.lighting(now);
    }			
    		

    6.10 RGB LED Waterproof

    Actuator features

    Features:

    • 10.0mm wide, 3.2mm thick, 50mm long per segment (3 LEDs)
    • Clear waterproof molded (IP65)
    • 3M adhesive strip on back
    • Maximum 12V per strip segment
    • Max 1.2 Amps per meter (all LEDs lit full brightness)
    • 3 common-anode RGB LEDs per segment, 20 segments per meter
    • No microcontroller or chip controller ('analog' only!)

    Connecting the actuator

    You can connect the RGB LED waterproof with the RGB controller in any of the available sockets in the RF power strip.

    Library Functions

    Actuating:

    The RF power strip can be activated with a simple function which must include the code of the plug that we want to actuate.

    Example:

    {
          OpenAquarium.sendPowerStrip(on1);  //Turn ON the plug number 1 
          OpenAquarium.sendPowerStrip(off3); //Turn OFF the plug number 3
    }
    		

    Example

    Upload the next code to turn LED ON at 22:15 and OFF at 23:59

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    DateTime now;
    
    //Power strip codes
    unsigned long on1 = 1597145202;
    unsigned long off1 = 1597145204;
    unsigned long on2 = 1597145220;
    unsigned long off2 = 1597145222;
    unsigned long on3 = 1597145112;
    unsigned long off3 = 1597145114;
    unsigned long on4 = 1597144950;
    unsigned long off4 = 1597144952;
    unsigned long on5 = 1597144464;
    unsigned long off5 = 1597144466;
    
    void setup() {
      Serial.begin(115200); 
      OpenAquarium.init();
      OpenAquarium.setTime();
    }
    
    void loop() {
       now =OpenAquarium.getTime();
       OpenAquarium.printTime(now);
       if (now.hour() == 22 && now.minute() == 15){
       OpenAquarium.sendPowerStrip(on1); //Turn ON plug 1
       Serial.println("RGB ON");
       }
       if (now.hour() == 23 && now.minute() == 59){
       OpenAquarium.sendPowerStrip(off1); //Turn OFF plug 1
       Serial.println("RGB OFF");
       }
    }			
    		

    Here is the USB output using the Arduino IDE serial port terminal:

    6.11 Full example

    Upload the next code for a full example of Open Aquarium Extra accesories.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include "OpenAquarium.h"
    #include "Wire.h"
    float temperature;
    DateTime now;
    
    //Power strip codes
    unsigned long on1 = 1597145202;
    unsigned long off1 = 1597145204;
    unsigned long on2 = 1597145220;
    unsigned long off2 = 1597145222;
    unsigned long on3 = 1597145112;
    unsigned long off3 = 1597145114;
    unsigned long on4 = 1597144950;
    unsigned long off4 = 1597144952;
    unsigned long on5 = 1597144464;
    unsigned long off5 = 1597144466;
    
    void setup() {
      Serial.begin(115200); 
      OpenAquarium.init();
    }
      
    void loop() {
      
      now =OpenAquarium.getTime();
      OpenAquarium.printTime(now);
      
      temperature=OpenAquarium.readtemperature();
      Serial.println(temperature);
       
      OpenAquarium.lighting(now);
      	
      OpenAquarium.tempcontrol(temperature);
       
      OpenAquarium.waterlevel1();
      OpenAquarium.waterlevel2();
       
      if (now.hour() == 8 && now.minute() == 30){
      OpenAquarium.feedfish(); 
      }
      if (now.hour() == 22 && now.minute() == 29){
      OpenAquarium.readyforfeeding(); 
      }
      if (now.hour() == 22 && now.minute() == 30){
      OpenAquarium.feedfish(); 
      }
      if (now.hour() == 12 && now.dayOfWeek()==7){
      OpenAquarium.empty(); 
      OpenAquarium.fill();
      }
      
      OpenAquarium.leak();
      
      if (now.hour() == 22 && now.minute() == 15){
       OpenAquarium.sendPowerStrip(on1); //Turn ON plug 1
       Serial.println("RGB ON");
    	}
       if (now.hour() == 23 && now.minute() == 59){
       OpenAquarium.sendPowerStrip(off1); //Turn OFF plug 1
       Serial.println("RGB OFF");
       OpenAquarium.newday(); 
    	}
      delay(500);
    }			
    		

    Step 1:

    Before filling your aquarium, remove plastic protection from LED Strip.

    Then glue RGB LED Strip at the bottom of the aquarium wall.

    Take out cables and connect it to the RF Power Strip.

    Step 2:

    Insert rubber hose into the pump.

    Step 3:

    Insert first pump into your aquarium.

    Step 4:

    Carry rubber hose to a bucket for empty aquarium water (water changes function).

    Step 5:

    Repeat same process for the other pump and place it into a bucket.

    Step 6:

    Carry rubber hose to the aquarium for refill it with clean water.

    Step 7:

    Places peristaltic pumps togheter near to the bucket with clean water.

    Step 8:

    Carry rubber hose to the bucket with clean water to drop medicine.

    Step 9:

    Place water leak sensor arround the aquarium and the buckets.

    Stick it straight to the table without too many loops.

    Step 10:

    Put the LED Lamp on the top of your aquarium.

    Adapt it to the lenght of your aquarium with the extendable brackets.

    Step 11:

    Place the aquarium heater inside of your tank and hang the aquarium fan cooler on the edge of the wall.

    Connect them to the RF Power Strip.

    NOTE: If you are going to use tempcontrol(temperature) function, you have to connect fan cooler in socket 4 and aquarium heater in socket 5 of the Power Strip.

    Step 12:

    Finally, power OpenAquarium.

    7. Sending the data to a Web Server

    Web Server

    OpenAquarium gateway communicates sending all data to the server to save it by Wi-Fi, GPRS or 3G technology. (see figure 1)

    Figure 1. Communication schema

    In this server, you should install Apache with PHP module and MySQL database, and configure it. You can see the following tutorial and complete all the instructions to make it possible.

    Ubuntu: https://help.ubuntu.com/community/ApacheMySQLPHP

    Windows: http://www.ampsoft.net/webdesign-l/how-to-install-apache-php-mysql.html

    Mac: http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/

    Once finished it, you should create a MySQL database with the following tables to save all sensors data.

    Code:
    CREATE DATABASE  IF NOT EXISTS `openaquarium`; 
    USE `openaquarium`; 
    
    
    -- 
    -- Table structure for table `measurements` 
    -- 
    
    DROP TABLE IF EXISTS `measurements`; 
    CREATE TABLE `measurements` ( 
      `_id` int(11) NOT NULL AUTO_INCREMENT, 
      `node_id` int(11) NOT NULL, 
      `sensor_type` varchar(45) NOT NULL, 
      `value` varchar(45) NOT NULL, 
      `date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, 
      `unit` varchar(45) NOT NULL, 
      `node_type` varchar(45) NOT NULL, 
      PRIMARY KEY (`_id`), 
      KEY `fk_node_id_idx` (`node_id`) 
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- 
    -- Table structure for table `actuators` 
    -- 
    
    DROP TABLE IF EXISTS `actuators`; 
    CREATE TABLE `actuators` ( 
      `_id` int(11) NOT NULL AUTO_INCREMENT, 
      `type` varchar(45) DEFAULT NULL, 
      `state` tinyint(4) DEFAULT NULL, 
      PRIMARY KEY (`_id`) 
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
    
    INSERT INTO actuators VALUES (1, 'pump1', 0);
    INSERT INTO actuators VALUES (2, 'pump2', 0);
    INSERT INTO actuators VALUES (3, 'peristalticPump1', 0);
    INSERT INTO actuators VALUES (4, 'peristalticPump2', 0);
    INSERT INTO actuators VALUES (5, 'peristalticPump3', 0);
    INSERT INTO actuators VALUES (6, 'socket1', 0);
    INSERT INTO actuators VALUES (7, 'socket2', 0);
    INSERT INTO actuators VALUES (8, 'socket3', 0);
    INSERT INTO actuators VALUES (9, 'socket4', 0);
    INSERT INTO actuators VALUES (10, 'socket5', 0);
    INSERT INTO actuators VALUES (11, 'feederFish', 0);
    INSERT INTO actuators VALUES (12, 'ledLight', 0);			
    		

    We have released the source code of the web application with an open source license! The idea is you can use it as a "proof of concept" and then modify it and build over it your desired final application. Download here!

    Download the source code

    To finish the system configuration, you should extract the zip file inside Apache server folder (usually /var/www).

    oppenaquarium-app folder

    Includes all the files needed to work perfectly the web application.

    config.php

    Configuration file. This file is very important because here you should set the database parameters, to connect it and make all necessary operations and the user authentication values, used in the web application to make login.

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Diego Becerrica
     */
    
    	//Database connection
    	DB::$user = 'YOUR USER'; 
    	DB::$password = 'YOUR PASSWORD'; 
    	DB::$dbName = 'YOUR DATABASE NAME'; 
    	DB::$host = 'YOUR HOST'; 
    	DB::$encoding = 'utf8';
    
    	//Web application connection
    	$user_login = "admin";
    	$user_passw = "3627909a29c31381a071ec27f7c9ca97726182aed29a7ddd2e54353322cfb30abb9e3a6df2ac2c20fe23436311d678564d0c8d305930575f60e2d3d048184d79"; //12345			
    		

    The first five parameters that begin with DB::, are for establishing the database connection. You should edit it for a correct connection.

      DB::$user Database user

      DB::$password Database password

      DB::$dbName Database name. If you have copied the code of this tutorial, the name is openAquarium.

      DB::$host Database host

      DB::$encoding Database encoding. The database encoding is utf8.

    Finally, the last two parameters, are used for authenticating user in the web application.

      $user_login User name for login. By default "admin" but you can change it.

      $user_passw Password used in login. This password are encrypted by SHA512. By default "12345" but is highly recommended that you change it. You can use this web to make your own SHA512 password: http://www.convertstring.com/Hash/SHA512

    get_actuators.php

    File used by the gateway to know how turn on or turn off the different actuators.

    meekrodb.2.2.class.php

    File used to manage the database.

    openaquarium.php

    File that centralize all the operations used in web application.

    set_sensors.php

    File used by the gateway to save the values of all sensors in the database.

    stop_feeder.php

    File used by the node to stop fish feeder in database.

    Please make sure that all these files have the correct permissions (at least read and execute).

    Connecting the gateway to the Web Server

    We will use the wifi module Roving RN-171. This module fits in the XBee socket of our Communication Shield and allows to connect your Arduino/RasberryPi shield to a WiFi network.

    Example codes

    This example sends all the sensor data info to a web server

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    
    #include <OpenAquarium.h>
    #include <Wire.h>
    
    #define point_1_cond 40000   // Write here your EC calibration value of the solution 1 in µS/cm
    #define point_1_cal 40       // Write here your EC value measured in resistance with solution 1
    #define point_2_cond 10500   // Write here your EC calibration value of the solution 2 in µS/cm
    #define point_2_cal 120      // Write here your EC value measured in resistance with solution 2
    
    
    #define calibration_point_4 2221  //Write here your measured value in mV of pH 4
    #define calibration_point_7 2104  //Write here your measured value in mV of pH 7
    #define calibration_point_10 2031 //Write here your measured value in mV of pH 10
    
    
    String wifiString;
    char buffer[20];
    int flag = 0; // auxiliar variable
    DateTime now;
    String levelstatus1;
    String levelstatus2;
    String waterleakstatus;
    
    void setup() {
      Serial.begin(115200);
      OpenAquarium.init();    //Initialize sensors power 
      OpenAquarium.calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal);
      OpenAquarium.calibratepH(calibration_point_4,calibration_point_7,calibration_point_10);
     
      wificonfig(); 
      
      
    }
    
    
    void loop() {
    
    
      now =OpenAquarium.getTime();
      OpenAquarium.printTime(now);
      
      if ( now.second() == 0 && flag == 0  ){ //Only enter 1 time each hour 
    
        //Get Gateway Sensors
        
        float temperature = OpenAquarium.readtemperature();
        
        
        float resistanceEC = OpenAquarium.readResistanceEC(); //EC Value in resistance
        float EC2 = OpenAquarium.ECConversion(resistanceEC); //EC Value in µS/cm
        
        
        int mvpH = OpenAquarium.readpH(); //Value in mV of pH
        float pH2 = OpenAquarium.pHConversion(mvpH); //Calculate pH value
        
        
        int status1 = OpenAquarium.readwaterlevel(1);
        if(status1==HIGH){
          levelstatus1= "Full";
          
        }
        else if (status1==LOW){
          levelstatus1= "Empty";
          
        }
        int status2 = OpenAquarium.readwaterlevel(2);
        if(status2==HIGH){
          levelstatus2= "Full";
          
        }
        else if (status2==LOW){
          levelstatus2= "Empty";
          
        }
        
        int waterleak = analogRead(3);
        
        if (waterleak>1020){
          waterleakstatus="No";
          
        }
        else if (waterleak<=1020){
          waterleakstatus="Si";
        }
    
        
    
    
        //Create string of the floats to send it
        
        dtostrf(temperature,2,2,buffer);
        String temperature_wf = String (buffer);
        
        dtostrf(EC2,2,2,buffer);
        String EC_wf = String (buffer);
        
        dtostrf(pH2,2,2,buffer);
        String pH_wf = String (buffer);
    
        /*
       You must create strings with this structure: "sensor_type:value;sensor_type2:value2;...." 
         Note the ";" between different structures
              
         And where sensor_type:
         0 - Temperature 
         1 - EC
         2 - pH
         3 - Waterlevel1
         4 - Waterlevel2 
         5 - waterleak 
              
         For example: "0:26.94;1:2300.16;2:7.15;"
         This means that you send data of the gateway: Temperature=26.94, EC=2300.16 and pH=7.15
         
         */
    
        //Cut data in several string because the wifi module have problems with longer strings
        wifiString= "0:" + temperature_wf + ";1:" + EC_wf + ";2:" + pH_wf; 
        sendwifi();
        enterCMD();
       
            
        wifiString= "3:" + levelstatus1 + ";4:"  + levelstatus2 + ";5:"  + waterleakstatus; 
        sendwifi();
        enterCMD();
    
    
    
        flag = 1;  
    
      }
    
      else if (now.second() == 30 && flag == 1){
        flag = 0;
      } 
    
    }
    
    
    
    void check(){
      delay(1000);
      autoflush(); 
    }
    
    
    void wificonfig(){
      while (Serial.available()>0){
      }
    
      enterCMD();
      // Sets DHCP and TCP protocol
      Serial.print(F("set ip dhcp 1\r")); 
      check();
      Serial.print(F("set ip protocol 18\r"));
      check();
    
      // Configures the way to join the network AP, sets the encryption of the
      // network and joins it
      Serial.print(F("set wlan join 0\r")); //The auto-join feature is disabled 
      check(); 
      Serial.print(F("set wlan phrase YOUR_PASSWORD\r")); //Insert here the password of the WLAN
      check(); 
      Serial.print(F("join YOUR_WLAN_NAME\r")); //Insert here the name of the WLAN
      check(); 
    }
    
    
    void enterCMD(){
      Serial.println(""); //To see clearer when debugging
      // Enters in command mode
      Serial.print(F("$$$")); 
      delay(100);
      check();
      Serial.flush();
    }
    
    void sendwifi(){
      Serial.print(F("set i h 0\r"));
      check();
      Serial.print(F("set d n 192.168.1.64\r"));
      check(); //Insert here your IP
    
      //Configures HTTP connection
      Serial.print(F("set i r 80\r")); 
      check();
    
      Serial.print(F("set o f 1\r")); 
      check();
    
      Serial.print(F("set c r GET$/OpenAquarium/set_sensors.php?data="));
      Serial.print(wifiString);
      Serial.print(F("\r"));
      check();
    
      // Calls open to launch the configured connection.
      Serial.print(F("open\r")); 
      check();
    }
    
    
    void autoflush()
    {
      while (Serial.available()>0)
      {
        Serial.read(); 
      }
    }			
    		

    This example gets all actuators state from a web server

    Code:
    /*  
     *  OpenAquarium sensor platform for Arduino from Cooking-hacks.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  a
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details.
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see http://www.gnu.org/licenses/. 
     *  
     *  Version:           1.0
     *  Design:            David Gasc├│n 
     *  Implementation:    Marcos Martinez, Luis Martin & Jorge Casanova
     */
    
    #include <OpenAquarium.h>
    #include <Wire.h>
    
    char recv[512];
    int cont;
    
    char pump1_wf;
    char pump2_wf;
    
    char peristalticPump1_wf;
    char peristalticPump2_wf;
    char peristalticPump3_wf;
    
    char socket1_wf;
    char socket2_wf;
    char socket3_wf;
    char socket4_wf;
    char socket5_wf;
    
    char feederFish_wf;
    
    char ledLight_wf;
    
    
    unsigned long on1 = 1597145202;
    unsigned long off1 = 1597145204;
    unsigned long on2 = 1597145220;
    unsigned long off2 = 1597145222;
    unsigned long on3 = 1597145112;
    unsigned long off3 = 1597145114;
    unsigned long on4 = 1597144950;
    unsigned long off4 = 1597144952;
    unsigned long on5 = 1597144464;
    unsigned long off5 = 1597144466;
    
    
    void setup() {
      Serial.begin(115200);
      OpenAquarium.init();    //Initialize sensors power 
      cleanVector();
      wificonfig();
    
    }
    
    void loop() {
      
     
      getActuators();
    
      Serial.println();
      
       if (pump1_wf == '0'){
        OpenAquarium.pumpOFF(1); //Turn OFF the pump number 1
        Serial.print(F("Pump 1: OFF"));
      }
      else if (pump1_wf == '1'){
        OpenAquarium.pumpON(1); //Turn ON the pump number 1
        Serial.print(F("Pump 1: ON"));
      }
      else{
        Serial.print(F("Pump 1 BAD DATA"));
      }
      
      if (pump2_wf == '0'){
        OpenAquarium.pumpOFF(1); //Turn OFF the pump number 2
        Serial.print(F("Pump 2: OFF"));
      }
      else if (pump2_wf == '1'){
        OpenAquarium.pumpON(2); //Turn ON the pump number 2
       Serial.print(F("Pump 2: ON"));
      }
      else{
        Serial.print(F("Pump 2 BAD DATA"));
      }
        
      if (peristalticPump1_wf == '0'){
        OpenAquarium.perpumpOFF(1); //Turn OFF the peristaltic pump number 1 
        Serial.print(F("Peristaltic pump 1: OFF"));
      }
      else if (peristalticPump1_wf == '1'){
        OpenAquarium.perpumpON(1); //Turn ON the peristaltic pump number 1 
        Serial.print(F("Peristaltic pump 1: ON"));
      }
      else{
        Serial.print(F("Peristaltic pump 1 BAD DATA"));
      }
    
    
      if (peristalticPump2_wf == '0'){
        OpenAquarium.perpumpOFF(2); //Turn OFF the peristaltic pump number 2
        Serial.print(F("Peristaltic pump 2: OFF"));
      }
      else if (peristalticPump2_wf == '1'){
        OpenAquarium.perpumpON(2); //Turn ON the peristaltic pump number 2
       Serial.print(F("Peristaltic pump 2: ON"));
      }
      else{
        Serial.print(F("Peristaltic pump 2 BAD DATA"));
      }
    
    
      if (peristalticPump3_wf == '0'){
        OpenAquarium.perpumpOFF(3); //Turn OFF the peristaltic pump number 3
         Serial.print(F("Peristaltic pump 3: OFF"));
      }
      else if (peristalticPump3_wf == '1'){
        OpenAquarium.perpumpON(3); //Turn ON the peristaltic pump number 3
        Serial.print(F("Peristaltic pump 3: ON"));
      }
      else{
        Serial.print(F("Peristaltic pump 3 BAD DATA"));
      }
      
      if (socket1_wf == '0'){
        OpenAquarium.sendPowerStrip(off1); //Turn OFF plug 1
        Serial.print(F("Socket 1: OFF"));
      }
      else if (socket1_wf == '1'){
        OpenAquarium.sendPowerStrip(on1); //Turn ON plug 1
       Serial.print(F("Socket 1: ON"));
      }
      else{
        Serial.print(F("Socket 1 BAD DATA"));
      }
      
      if (socket2_wf == '0'){
        OpenAquarium.sendPowerStrip(off2); //Turn OFF plug 2
        Serial.print(F("Socket 2: OFF"));
      }
      else if (socket2_wf == '1'){
        OpenAquarium.sendPowerStrip(on2); //Turn ON plug 2
        Serial.print(F("Socket 2: ON"));
      }
      else{
       Serial.print(F("Socket 2 BAD DATA"));
      }
      
      if (socket3_wf == '0'){
        OpenAquarium.sendPowerStrip(off3); //Turn OFF plug 3
        Serial.print(F("Socket 3: OFF"));
      }
      else if (socket3_wf == '1'){
        OpenAquarium.sendPowerStrip(on3); //Turn ON plug 3
        Serial.print(F("Socket 3: ON"));
      }
      else{
        Serial.print(F("Socket 3 BAD DATA"));
      }
      
      if (socket4_wf == '0'){
        OpenAquarium.sendPowerStrip(off4); //Turn OFF plug 4
        Serial.print(F("Socket 4: OFF"));
      }
      else if (socket4_wf == '1'){
        OpenAquarium.sendPowerStrip(on4); //Turn ON plug 4
        Serial.print(F("Socket 4: ON"));
      }
      else{
        Serial.print(F("Socket 4 BAD DATA"));
      }
      
      if (socket5_wf == '0'){
        OpenAquarium.sendPowerStrip(off5); //Turn OFF plug 5
        Serial.print(F("Socket 5: OFF"));
      }
      else if (socket5_wf == '1'){
        OpenAquarium.sendPowerStrip(on5); //Turn ON plug 5
        Serial.print(F("Socket 5: ON"));
      }
      else{
        Serial.print(F("Socket 5 BAD DATA"));
      }
      
      
      
      if (ledLight_wf == '0'){
        OpenAquarium.lightOFF(); //Turn OFF plug 5
        Serial.print(F("Light: OFF"));
      }
      else if (ledLight_wf == '1'){
        OpenAquarium.lightON(); //Turn ON plug 5
        Serial.print(F("Light: ON"));
      }
      else{
        Serial.print(F("Led Light BAD DATA"));
      }
      
      if (feederFish_wf == '1'){
        OpenAquarium.feedfish();
        Serial.print(F("Feeding fish"));
        enterCMD();
        sendfeederstatus();
        delay(500);
      }
      else if (feederFish_wf == '0'){
        OpenAquarium.readyforfeeding();    
        Serial.print(F("Feeder OFF"));
      }
      else{
        Serial.print(F("Fish Feeder BAD DATA"));
      }
        
      
      cleanVector();
      enterCMD();
    
      delay(5000);
    }
    
    void cleanVector(){
      recv[0] = 0; 
      recv[1] = 0;
      recv[2] = 0;
      recv[3] = 0; 
      recv[4] = 0;
      recv[5] = 0;
      recv[6] = 0;
      recv[7] = 0;
      recv[8] = 0;
      recv[9] = 0;
      recv[10] = 0;
      recv[11] = 0;
     
     
      
    }
    
    
    void wificonfig(){
      while (Serial.available()>0){
      }
    
      enterCMD();
      // Sets DHCP and TCP protocol
      Serial.print(F("set ip dhcp 1\r")); 
      check();
      Serial.print(F("set ip protocol 18\r"));
      check();
    
      // Configures the way to join the network AP, sets the encryption of the
      // network and joins it
      Serial.print(F("set wlan join 0\r")); //The auto-join feature is disabled 
      check(); 
      Serial.print(F("set wlan phrase YOUR_PASSWORD\r")); //Insert here the password of the WLAN
      check(); 
      Serial.print(F("join YOUR_WLAN_NAME\r")); //Insert here the name of the WLAN
      check(); 
    }
    
    void getActuators(){
      Serial.print("set dns name 192.168.1.64\r");
      check(); //Insert here your IP
      //Configures HTTP connection
      Serial.print("set ip adress 0\r"); 
      check();
    
      Serial.print("set i r 80\r"); 
      check();
      Serial.print("set com remote 0\r"); 
      check();
      Serial.print("open\r"); 
      check();
      Serial.flush(); 
      Serial.print("GET /OpenAquarium/get_actuators.php\r"); 
      checkData();
    
    
    }
    
    void enterCMD(){
      Serial.println(""); //To see clearer when debugging
      // Enters in command mode
      Serial.print(F("$$$")); 
      delay(100);
      check();
      Serial.flush();
    }
    
    void check(){
      delay(1000);
      autoflush(); 
    }
    
    
    void checkData(){
      cont=0;   
      delay(3000);
      while (Serial.available()>0)
      {
        recv[cont]=Serial.read(); 
        delay(10);
        cont++;
      }
      recv[cont]='\0';
    
      pump1_wf= recv[0]; 
      pump2_wf= recv[1];
      peristalticPump1_wf= recv[2];
      peristalticPump2_wf= recv[3]; 
      peristalticPump3_wf= recv[4];
      socket1_wf= recv[5];
      socket2_wf= recv[6];
      socket3_wf= recv[7];
      socket4_wf= recv[8];
      socket5_wf= recv[9];
      feederFish_wf= recv[10]; 
      ledLight_wf= recv[11];
    
      
      
    
      //Serial.print("Received:");
      //Serial.print(recv);
    
      autoflush(); 
      delay(100);
    }
    
    
    void autoflush()
    {
      while (Serial.available()>0)
      {
        Serial.read(); 
      }
    }
    
    void sendfeederstatus(){
      Serial.print(F(" set i h 0\r"));
      check();
      Serial.print(F("set d n 192.168.1.64\r"));
      check(); //Insert here your IP
    
      //Configures HTTP connection
      Serial.print(F("set i r 80\r")); 
      check();
    
      Serial.print(F("set o f 1\r")); 
      check();
    
     
      Serial.print(F("set c r GET$/OpenAquarium/stop_feeder.php\r"));
      check();
    
      // Calls open to launch the configured connection.
      Serial.print(F("open\r")); 
      check();
    }			
    		

    Refer to Wifi tutorials for more information.

    8. Visualizing the data

    8.1 From a web browser

    Open Aquarium includes an application to visualize real data of all your sensors in a web browser. If you have followed correctly all the previous section, you will be able to connect to this URL.

    http://your-ip/openaquarium-app

    and see this screen where you can fill user and password credentials to login.

    In user field you should type the user name that you have written in config.php file, and then in password fields, your own password without encryption. Once completed, you should click to connect button at the bottom of the form and you arrive to the main screen when you can see all sensor values.

    Finally, in the menu, you can click in actuators option to see all actuators states.

    8.2 From iPhone / Android devices

    You can access to the web application from iPhone or Android devices, using a mobile web browser and typing the URL of your server in it.

    Device Compatibility

    This shield is tested and fully compatible with the following boards:

    Arduino Boards

    • Arduino Uno

    Forum

    There is a forum available in which you can get support for Open Aquarium.

    Get the shields and kits

    NOTE: Due to the constant evolution of the product pictures shown may vary from actual product. Product specifications subject to change without notice.

    Kits

    Basic Kits

    Aquaponics Kit

    Extra accesories





    If you are interested in Internet of Things (IoT) or M2M projects check our open source sensor platform Waspmote which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.

    Know more at:

    Get the Starter Kits at: