My Cart

Open Garden - Hydroponics & Garden Plants Monitoring for Arduino

Difficulty Level: Expert -


The Open Garden platform consist of three different kits, each ready for a specific kind of growing plant scenario: indoor (houses and greenhouses), outdoor (gardens and fields) and hydroponics (plants in water installations).

The platform allows to control the state of the plants by sensing several parameters:

  • Soil moisture (Indoor & Outdoor kits)
  • Temperature + Humidity + Light (All kits)
  • Water sensors: pH, Conductivity, Temperature (Hydroponics kit)

Then it uses different types of actuators to modify the state of the plants by irrigating them or activating lights and oxygen pumps:

  • Water pump + Droppers for Drip Irrigation (Indoor kit)
  • Electro valve + Sprinkler for Sprinkling (Outdoor kit)
  • Oxygen Pump + Growing Light (Hydroponics kit)

The nodes send periodically the information to the Gateway that uploads the data to a web server by using any of the available wireless interfaces (WiFi, GPRS, 3G).

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 iPhone / Android device. We have released it as open source code so that you can improve it and make it personal for your own product!!

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

Indoor Kit:
Outdoor Kit:
Hydroponics Kit:

1. Features

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

Electrical Features

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

Open Garden 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 Garden has a wireless network with star topology and ASK modulation (Amplitude-shift keying) at 433MHz in which the gateway receive the data from the nodes placed in the garden or plants.

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

Can I use the 433MHz radios included in Open Garden 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 Garden 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 Garden 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 Garden Shield

2.2 Open Garden Hydroponics

2.3 Open Garden Node

Programming the node

NOTE: The first time that you program an ATtiny you must "Burn Bootloader". You can do it in the Arduino IDE at Tools -> Burn Bootloader. This is needed only once, do it whenever you use a new chip ATtiny before loading the first code, after this, you won't need to do it anymore. You must select the board "ATtiny84@ 8 MHz(internal oscillator; BOD disabled" and the programmer "Arduino as ISP" as we'll explain below. This method is written for Arduino 1.0.5. or 1.0.6. It may not work in other versions.

In order to program ATtiny with Arduino 1.6 please follow the step in this link. You will have to select ATtiny84 (internal 8 MHz clock).

Unlike other shields, the Open Garden node doesn't need an Arduino to work because it has an embedded microcontroller (ATtiny84). Thats why we need a special process to upload a code to the node using an Arduino as a ISP programmer.

We will need:

  • Arduino
  • Breadboard
  • Open Garden node
  • Jumper wires
  • Take out the ATtiny microcontroller from the Open Garden node:

    Connect the Arduino to the ATtiny as you can see in the following pictures:

    Now that you have got all the hardware connected, select in the Arduino IDE the "ArduinoISP" sketch. Upload the sketch to your Arduino.

    Code:
    // ArduinoISP version 04m3
    // Copyright (c) 2008-2011 Randall Bohn
    // If you require a license, see 
    //     http://www.opensource.org/licenses/bsd-license.php
    //
    // This sketch turns the Arduino into a AVRISP
    // using the following arduino pins:
    //
    // pin name:    not-mega:         mega(1280 and 2560)
    // slave reset: 10:               53 
    // MOSI:        11:               51 
    // MISO:        12:               50 
    // SCK:         13:               52 
    //
    // Put an LED (with resistor) on the following pins:
    // 9: Heartbeat   - shows the programmer is running
    // 8: Error       - Lights up if something goes wrong (use red if that makes sense)
    // 7: Programming - In communication with the slave
    //
    // 23 July 2011 Randall Bohn
    // -Address Arduino issue 509 :: Portability of ArduinoISP
    // http://code.google.com/p/arduino/issues/detail?id=509
    //
    // October 2010 by Randall Bohn
    // - Write to EEPROM > 256 bytes
    // - Better use of LEDs:
    // -- Flash LED_PMODE on each flash commit
    // -- Flash LED_PMODE while writing EEPROM (both give visual feedback of writing progress)
    // - Light LED_ERR whenever we hit a STK_NOSYNC. Turn it off when back in sync.
    // - Use pins_arduino.h (should also work on Arduino Mega)
    //
    // October 2009 by David A. Mellis
    // - Added support for the read signature command
    // 
    // February 2009 by Randall Bohn
    // - Added support for writing to EEPROM (what took so long?)
    // Windows users should consider WinAVR's avrdude instead of the
    // avrdude included with Arduino software.
    //
    // January 2008 by Randall Bohn
    // - Thanks to Amplificar for helping me with the STK500 protocol
    // - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader
    // - The SPI functions herein were developed for the AVR910_ARD programmer 
    // - More information at http://code.google.com/p/mega-isp
    
    #include "pins_arduino.h"
    #define RESET     SS
    
    #define LED_HB    9
    #define LED_ERR   8
    #define LED_PMODE 7
    #define PROG_FLICKER true
    
    #define HWVER 2
    #define SWMAJ 1
    #define SWMIN 18
    
    // STK Definitions
    #define STK_OK      0x10
    #define STK_FAILED  0x11
    #define STK_UNKNOWN 0x12
    #define STK_INSYNC  0x14
    #define STK_NOSYNC  0x15
    #define CRC_EOP     0x20 //ok it is a space...
    
    void pulse(int pin, int times);
    
    void setup() {
      Serial.begin(19200);
      pinMode(LED_PMODE, OUTPUT);
      pulse(LED_PMODE, 2);
      pinMode(LED_ERR, OUTPUT);
      pulse(LED_ERR, 2);
      pinMode(LED_HB, OUTPUT);
      pulse(LED_HB, 2);
    }
    
    int error=0;
    int pmode=0;
    // address for reading and writing, set by 'U' command
    int here;
    uint8_t buff[256]; // global block storage
    
    #define beget16(addr) (*addr * 256 + *(addr+1) )
    typedef struct param {
      uint8_t devicecode;
      uint8_t revision;
      uint8_t progtype;
      uint8_t parmode;
      uint8_t polling;
      uint8_t selftimed;
      uint8_t lockbytes;
      uint8_t fusebytes;
      int flashpoll;
      int eeprompoll;
      int pagesize;
      int eepromsize;
      int flashsize;
    } 
    parameter;
    
    parameter param;
    
    // this provides a heartbeat on pin 9, so you can tell the software is running.
    uint8_t hbval=128;
    int8_t hbdelta=8;
    void heartbeat() {
      if (hbval > 192) hbdelta = -hbdelta;
      if (hbval < 32) hbdelta = -hbdelta;
      hbval += hbdelta;
      analogWrite(LED_HB, hbval);
      delay(20);
    }
    
    
    void loop(void) {
      // is pmode active?
      if (pmode) digitalWrite(LED_PMODE, HIGH); 
      else digitalWrite(LED_PMODE, LOW);
      // is there an error?
      if (error) digitalWrite(LED_ERR, HIGH); 
      else digitalWrite(LED_ERR, LOW);
    
      // light the heartbeat LED
      heartbeat();
      if (Serial.available()) {
        avrisp();
      }
    }
    
    uint8_t getch() {
      while(!Serial.available());
      return Serial.read();
    }
    void fill(int n) {
      for (int x = 0; x < n; x++) {
        buff[x] = getch();
      }
    }
    
    #define PTIME 30
    void pulse(int pin, int times) {
      do {
        digitalWrite(pin, HIGH);
        delay(PTIME);
        digitalWrite(pin, LOW);
        delay(PTIME);
      } 
      while (times--);
    }
    
    void prog_lamp(int state) {
      if (PROG_FLICKER)
        digitalWrite(LED_PMODE, state);
    }
    
    void spi_init() {
      uint8_t x;
      SPCR = 0x53;
      x=SPSR;
      x=SPDR;
    }
    
    void spi_wait() {
      do {
      } 
      while (!(SPSR & (1 << SPIF)));
    }
    
    uint8_t spi_send(uint8_t b) {
      uint8_t reply;
      SPDR=b;
      spi_wait();
      reply = SPDR;
      return reply;
    }
    
    uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
      uint8_t n;
      spi_send(a); 
      n=spi_send(b);
      //if (n != a) error = -1;
      n=spi_send(c);
      return spi_send(d);
    }
    
    void empty_reply() {
      if (CRC_EOP == getch()) {
        Serial.print((char)STK_INSYNC);
        Serial.print((char)STK_OK);
      } 
      else {
        error++;
        Serial.print((char)STK_NOSYNC);
      }
    }
    
    void breply(uint8_t b) {
      if (CRC_EOP == getch()) {
        Serial.print((char)STK_INSYNC);
        Serial.print((char)b);
        Serial.print((char)STK_OK);
      } 
      else {
        error++;
        Serial.print((char)STK_NOSYNC);
      }
    }
    
    void get_version(uint8_t c) {
      switch(c) {
      case 0x80:
        breply(HWVER);
        break;
      case 0x81:
        breply(SWMAJ);
        break;
      case 0x82:
        breply(SWMIN);
        break;
      case 0x93:
        breply('S'); // serial programmer
        break;
      default:
        breply(0);
      }
    }
    
    void set_parameters() {
      // call this after reading paramter packet into buff[]
      param.devicecode = buff[0];
      param.revision   = buff[1];
      param.progtype   = buff[2];
      param.parmode    = buff[3];
      param.polling    = buff[4];
      param.selftimed  = buff[5];
      param.lockbytes  = buff[6];
      param.fusebytes  = buff[7];
      param.flashpoll  = buff[8]; 
      // ignore buff[9] (= buff[8])
      // following are 16 bits (big endian)
      param.eeprompoll = beget16(&buff[10]);
      param.pagesize   = beget16(&buff[12]);
      param.eepromsize = beget16(&buff[14]);
    
      // 32 bits flashsize (big endian)
      param.flashsize = buff[16] * 0x01000000
        + buff[17] * 0x00010000
        + buff[18] * 0x00000100
        + buff[19];
    
    }
    
    void start_pmode() {
      spi_init();
      // following delays may not work on all targets...
      pinMode(RESET, OUTPUT);
      digitalWrite(RESET, HIGH);
      pinMode(SCK, OUTPUT);
      digitalWrite(SCK, LOW);
      delay(50);
      digitalWrite(RESET, LOW);
      delay(50);
      pinMode(MISO, INPUT);
      pinMode(MOSI, OUTPUT);
      spi_transaction(0xAC, 0x53, 0x00, 0x00);
      pmode = 1;
    }
    
    void end_pmode() {
      pinMode(MISO, INPUT);
      pinMode(MOSI, INPUT);
      pinMode(SCK, INPUT);
      pinMode(RESET, INPUT);
      pmode = 0;
    }
    
    void universal() {
      int w;
      uint8_t ch;
    
      fill(4);
      ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
      breply(ch);
    }
    
    void flash(uint8_t hilo, int addr, uint8_t data) {
      spi_transaction(0x40+8*hilo, 
      addr>>8 & 0xFF, 
      addr & 0xFF,
      data);
    }
    void commit(int addr) {
      if (PROG_FLICKER) prog_lamp(LOW);
      spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
      if (PROG_FLICKER) {
        delay(PTIME);
        prog_lamp(HIGH);
      }
    }
    
    //#define _current_page(x) (here & 0xFFFFE0)
    int current_page(int addr) {
      if (param.pagesize == 32)  return here & 0xFFFFFFF0;
      if (param.pagesize == 64)  return here & 0xFFFFFFE0;
      if (param.pagesize == 128) return here & 0xFFFFFFC0;
      if (param.pagesize == 256) return here & 0xFFFFFF80;
      return here;
    }
    
    
    void write_flash(int length) {
      fill(length);
      if (CRC_EOP == getch()) {
        Serial.print((char) STK_INSYNC);
        Serial.print((char) write_flash_pages(length));
      } 
      else {
        error++;
        Serial.print((char) STK_NOSYNC);
      }
    }
    
    uint8_t write_flash_pages(int length) {
      int x = 0;
      int page = current_page(here);
      while (x < length) {
        if (page != current_page(here)) {
          commit(page);
          page = current_page(here);
        }
        flash(LOW, here, buff[x++]);
        flash(HIGH, here, buff[x++]);
        here++;
      }
    
      commit(page);
    
      return STK_OK;
    }
    
    #define EECHUNK (32)
    uint8_t write_eeprom(int length) {
      // here is a word address, get the byte address
      int start = here * 2;
      int remaining = length;
      if (length > param.eepromsize) {
        error++;
        return STK_FAILED;
      }
      while (remaining > EECHUNK) {
        write_eeprom_chunk(start, EECHUNK);
        start += EECHUNK;
        remaining -= EECHUNK;
      }
      write_eeprom_chunk(start, remaining);
      return STK_OK;
    }
    // write (length) bytes, (start) is a byte address
    uint8_t write_eeprom_chunk(int start, int length) {
      // this writes byte-by-byte,
      // page writing may be faster (4 bytes at a time)
      fill(length);
      prog_lamp(LOW);
      for (int x = 0; x < length; x++) {
        int addr = start+x;
        spi_transaction(0xC0, (addr>>8) & 0xFF, addr & 0xFF, buff[x]);
        delay(45);
      }
      prog_lamp(HIGH); 
      return STK_OK;
    }
    
    void program_page() {
      char result = (char) STK_FAILED;
      int length = 256 * getch();
      length += getch();
      char memtype = getch();
      // flash memory @here, (length) bytes
      if (memtype == 'F') {
        write_flash(length);
        return;
      }
      if (memtype == 'E') {
        result = (char)write_eeprom(length);
        if (CRC_EOP == getch()) {
          Serial.print((char) STK_INSYNC);
          Serial.print(result);
        } 
        else {
          error++;
          Serial.print((char) STK_NOSYNC);
        }
        return;
      }
      Serial.print((char)STK_FAILED);
      return;
    }
    
    uint8_t flash_read(uint8_t hilo, int addr) {
      return spi_transaction(0x20 + hilo * 8,
      (addr >> 8) & 0xFF,
      addr & 0xFF,
      0);
    }
    
    char flash_read_page(int length) {
      for (int x = 0; x < length; x+=2) {
        uint8_t low = flash_read(LOW, here);
        Serial.print((char) low);
        uint8_t high = flash_read(HIGH, here);
        Serial.print((char) high);
        here++;
      }
      return STK_OK;
    }
    
    char eeprom_read_page(int length) {
      // here again we have a word address
      int start = here * 2;
      for (int x = 0; x < length; x++) {
        int addr = start + x;
        uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF);
        Serial.print((char) ee);
      }
      return STK_OK;
    }
    
    void read_page() {
      char result = (char)STK_FAILED;
      int length = 256 * getch();
      length += getch();
      char memtype = getch();
      if (CRC_EOP != getch()) {
        error++;
        Serial.print((char) STK_NOSYNC);
        return;
      }
      Serial.print((char) STK_INSYNC);
      if (memtype == 'F') result = flash_read_page(length);
      if (memtype == 'E') result = eeprom_read_page(length);
      Serial.print(result);
      return;
    }
    
    void read_signature() {
      if (CRC_EOP != getch()) {
        error++;
        Serial.print((char) STK_NOSYNC);
        return;
      }
      Serial.print((char) STK_INSYNC);
      uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00);
      Serial.print((char) high);
      uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00);
      Serial.print((char) middle);
      uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00);
      Serial.print((char) low);
      Serial.print((char) STK_OK);
    }
    //////////////////////////////////////////
    //////////////////////////////////////////
    
    
    ////////////////////////////////////
    ////////////////////////////////////
    int avrisp() { 
      uint8_t data, low, high;
      uint8_t ch = getch();
      switch (ch) {
      case '0': // signon
        error = 0;
        empty_reply();
        break;
      case '1':
        if (getch() == CRC_EOP) {
          Serial.print((char) STK_INSYNC);
          Serial.print("AVR ISP");
          Serial.print((char) STK_OK);
        }
        break;
      case 'A':
        get_version(getch());
        break;
      case 'B':
        fill(20);
        set_parameters();
        empty_reply();
        break;
      case 'E': // extended parameters - ignore for now
        fill(5);
        empty_reply();
        break;
    
      case 'P':
        start_pmode();
        empty_reply();
        break;
      case 'U': // set address (word)
        here = getch();
        here += 256 * getch();
        empty_reply();
        break;
    
      case 0x60: //STK_PROG_FLASH
        low = getch();
        high = getch();
        empty_reply();
        break;
      case 0x61: //STK_PROG_DATA
        data = getch();
        empty_reply();
        break;
    
      case 0x64: //STK_PROG_PAGE
        program_page();
        break;
    
      case 0x74: //STK_READ_PAGE 't'
        read_page();    
        break;
    
      case 'V': //0x56
        universal();
        break;
      case 'Q': //0x51
        error=0;
        end_pmode();
        empty_reply();
        break;
    
      case 0x75: //STK_READ_SIGN 'u'
        read_signature();
        break;
    
        // expecting a command, not CRC_EOP
        // this is how we can get back in sync
      case CRC_EOP:
        error++;
        Serial.print((char) STK_NOSYNC);
        break;
    
        // anything else we will return STK_UNKNOWN
      default:
        error++;
        if (CRC_EOP == getch()) 
          Serial.print((char)STK_UNKNOWN);
        else
          Serial.print((char)STK_NOSYNC);
      }
    }
            

    Now you can use your Arduino as a serial pogrammer that can program other chips.

    Once you have your Arduino as a serial programmer, you can select your programmer: Arduino as ISP.

    Finally you can select the board ATtiny84 an upload to the node the sketch that you want to run. In order to know how to introduce the board ATtiny84 in the Arduino IDE, please read the section "3.1 Using the library with Arduino"

    NOTE: The method explained above works in Arduino IDE 1.0.5 and 1.0.6 in Linux and Mac OS X. If you are using Windows you have to patch one file due to the use of an old WinAVR toolset in the Windows version of Arduino IDE. Follow these steps:

    1. Close Arduino IDE
    2. Download this zip file with the patch.
    3. Open the folder where Arduino IDE is installed, it will be probably: ÔÇťC:\Program Files\ArduinoÔÇŁ. There you will see a folder called "hardware".
    4. Now copy the "hardware" folder inside the downloaded zip file into the Arduino directory and it will replace only one file (ld.exe). Remember, this file change won't affect the rest of the IDE, It just upload a file to the latest version.
    5. Open Arduino IDE and retry to verify now your code.

    Code for the node

    This is the generic code for the node. This code reads all the node sensors info and sends it to the gateway every minute.

    Code:
    /*  
     *  OpenGarden 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. 
     *  
     *  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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGardenNode.h>
    
    Payload nodePacket;
     
    void setup() {
        //Initialize the transceiver
        OpenGardenNode.initRF(1); //Write here the number for your node ID  (1, 2 or 3)
        OpenGardenNode.initSensors(); //Initialize sensors power  
    }
    
    void loop() {
        OpenGardenNode.sensorPowerON();  //Turns on the sensor power supply
        OpenGardenNode.readSensors();    //Read all node sensors
        OpenGardenNode.sensorPowerOFF(); //Turns off the sensor power supply
        
        OpenGardenNode.sendPackage();  // Send data via RF asking for ACK
        OpenGardenNode.nodeWait(60);   //Enter low power mode for 60 seconds (max: 60 seconds)
    }
            

    Charging the node

    The figure below shows the connector in which the battery must be connected. The position of the battery connector is unique, therefore it will always be connected correctly (unless the connector is forced).

    A red LED indicates that there is a battery connected in the Open Garden node which is being charged, the charging can be done through a mini USB cable or through a solar panel connected to the Open Garden node. Once the battery is completely charged, the LED switches off automatically.

    Solar panel

    For outdoor uses the nodes can be recharged using the solar panel. The Open Garden node has a sonal panel connector named BATT. CHARGE. You have to cut the little connector in the solar panel and you will get two wires (positive and negative). You can stick the solar panel to the transparent cover of the node.

    Connect the red wire with the positive terminal (marked as "IN+" in the board) and the black wire with the negative terminal (marked as "IN-" in the board).

    USB

    For indoor uses the nodes can be recharged using the USB charger.

    You will need:

  • Breakout board for mini USB
  • Mini USB cable
  • Open Garden node
  • Weld two wires (VCC and GND) to the breakout board. Connect the two wires to the USB charging connector in the node in the right position,as you can see in the next photo.

    Finally, connect the breakout board with the mini USB cable to a power supply.

    2.4 Open Garden over Arduino

    3. The Library

    Note: these examples are written for Arduino 1.0.5 and 1.0.6. Certain functions may not work in other versions.

    Open Garden 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 Garden includes two high level libraries for an easy manage of the boards: "OpenGarden" for programming the gateaway and "OpenGardenNode" for programming the node. Before start using the library functions you should download the files from this link. This zip includes all the files needed in two separated folders, "libraries" and "hardware". Copy this folders in the arduino IDE folder "sketchbook". If the folders "libraries" and/or "hardware" already exists in your folder "sketchbook", just add but don't replace the files. Don't forget include these libraries in your codes.

    You must download the library depending on the date of purchase.

    Download the Open Garden Libraries for Arduino. (important: V2.3 after October 2014)

    Download the Open Garden Libraries for Arduino. (important: V1.1 before October 2014)

    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.

    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 Garden functions

    Open Garden Gateway functions

    Sensor initializing functions:

    initSensors()     //Initializing necessary for all the sensors
    sensorPowerON()   //Turns on the sensor power supply
    sensorPowerOFF()  //Turns off the sensor power supply
                

    Transceiver functions:

    initRF()                 //Initializing transceiver
    receiveFromNode()        //Receive data from node and store it in a internal buffer
    getNodeData(node)        //Get a struct with the last data stored in the internal buffer
    printNode (nodePacket)   //Serial print all the node data obtained with getData(node)
    debugRF()                //Serial print node data as it comes to transceiver without buffering it
                

    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

    Irrigation functions:

    initIrrigation(out)//Initializing necessary for irrigation with the number "out"
    irrigationON(out)  //Turns on the irrigation with the number "out"
    irrigationOFF(out) //Turns off the irrigation with the number "out"

    Power strip functions:

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

    Soil moisture function:

    readSoilMoisture() //Returns the value of the soil moisture sensor

    DHT22 functions:

    readAirTemperature() //Returns the temperature value of the DHT22 sensor
    readAirHumidity()    //Returns the humidity value of the DHT22 sensor

    DS18B20 function:

    readSoilTemperature() //Returns the value of the DS18B20  sensor

    LDR function:

    readLuminosity()  //Returns the value of the LDR sensor

    Hydroponics functions:

    calibratepH(calibration_point_4, calibration_point_7, calibration_point_10)//Calibrate the pH sensor
    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)//Calibrate the EC sensor
    readResistanceEC()        //Returns EC Value in resistance
    ECConversion(resistanceEC)//Returns EC Value in µS/cm

    Open Garden Node functions

    Sensor initializing functions:

    initSensors()     //Initializing necessary for all the sensors
    sensorPowerON()   //Turns on the sensor power supply
    sensorPowerOFF()  //Turns off the sensor power supply

    Sensor function:

    readSensors()    //Get data from all the sensors and store it in a internal buffer

    Transceiver functions:

    initRF()         //Initializing transceiver
    sendPackage()    //Send package with the last data from node to gateway

    Node function:

    nodeWait(seconds)  //Enter low power mode some seconds (max: 60 seconds)

    4. Open Garden Indoor

    The complete kit can be found here.

    The parts of this kit are:

    • 1x General kit box
    • 1x Gateway Shield for Arduino
    • 1x Node
    • 1x DHT22 (temperature + humidity)
    • 1x Soil Moisture sensor
    • 2x LDR
    • 1x Water Pump
    • 1x 4mm drip irrigation adapter
    • 1x 12V Power Supply
    • 1x Big 433MHz internal antenna
    • 1x Small 433MHz internal antenna
    • 1x Big Enclosure for gateway
    • 1x Small Enclosure for node
    • 2x 16mm Cable Glands
    • 3x 20mm Cable Gland
    • 1x Vent Plug
    • 6x Flange
    • 7x M3 Metal Nuts
    • 4x M3 x 10mm Metal Screws
    • 3x M3 x 6mm Plastic Screws
    • 3x Metal Spacer M3
    • 1x Battery 3,7V 2300mAh
    • 1x Solar Panel
    • 1x Breadboard
    • 10x Arduino jumper cables
    • 1x Breakout Board for miniUSB
    • 1x miniUSB cable

    4.1 LDR - Light sensor

    Sensor Features

    This is a very small light sensor. A photocell changes (also called a photodetector, CdS or photoconductive cell) resistance depending on the amount of light it is exposed to. These little sensors make great ambient light triggers (when light in the room turns on, do something).

    Features:

    • Light resistance : ~1k Ohm
    • Dark resistance : ~10k Ohm
    • Max voltage : 150V
    • Max power: 100mW

    Connecting the sensor

    The Open Garden gateway and the node have a built in LDR, thats why you don't have to make any connection.

    Gateway connection

    Node connection

    Library Functions

    Getting data:

    The LDR returns an integer value of the percentage of light (0-100%).

    Example:

    {
        int luminosity = OpenGarden.readLuminosity();
    }

    Example

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

    Code:
    /*  
     *  OpenGarden 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. 
     *  
     *  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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h> 
    
    
    void setup() {
        Serial.begin(9600);
        OpenGarden.initSensors();    //Initialize sensors power 
    }
    
    
    void loop() {
        OpenGarden.sensorPowerON();  //Turns on the sensor power supply
        delay(500); // Time for initializing the sensor
        int luminosity = OpenGarden.readLuminosity();  //Read the sensor
        OpenGarden.sensorPowerOFF();  //Turns off the sensor power supply
      
        Serial.print("Luminosity: ");
        Serial.print(luminosity);
        Serial.println("%");
        delay(2000);   //Wait 2 seconds
    }
            		
    		

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

    4.2 DHT22 - Temperature + Humidity sensor

    Sensor Features

    The DHT22 is an humidity and temperature sensor with a single wire digital interface. The sensor is calibrated so you can get right to measuring relative humidity and temperature.

    Features:

    • 3.3-6V Input
    • 1-1.5mA measuring current
    • 40-50 uA standby current
    • Humidity from 0-100% RH
    • -40 - 80 °C temperature range
    • +-2% RH accuracy
    • +-0.5 degrees C

    Connecting the sensor

    The DHT22 sensor have 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.

    Node 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 air termperature and relative humidity of the air can be read by two simple functions. This functions return a float with the value.
    Example:

        float airTemperature = OpenGarden.readAirTemperature();
        float airHumidity = OpenGarden.readAirHumidity();
    

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors(); //Initialize sensors power 
    }
    
    
    void loop() {
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(1000); // Time for initializing the sensor
      float airTemperature = OpenGarden.readAirTemperature();  //Read the sensor
      OpenGarden.sensorPowerOFF(); //Turns off the sensor power supply
    
      Serial.print("Air Temperature: ");
      Serial.print(airTemperature);
      Serial.println("*C");
      delay(2000); //Wait 2 seconds
    }
    
    		

    Watch the Serial monitor. Here is the USB output using the Arduino IDE serial port terminal:

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors(); //Initialize sensors power 
    }
    
    
    void loop() {
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(1000); // Time for initializing the sensor
      float airHumidity = OpenGarden.readAirHumidity();//Sensor takes 2s to read humidity
      OpenGarden.sensorPowerOFF(); //Turns off the sensor power supply
    
      Serial.print("Air Humidity: ");
      Serial.print(airHumidity);
      Serial.println("% RH");
      delay(2000);   //Wait 2 seconds
    }
    
    		

    This is what we see in the Serial monitor using the Arduino IDE serial port terminal:

    4.3 Soil Moisture sensor

    Sensor Features

    This soil moisture sensor can be used to detect the moisture of soil or judge if there is water around the sensor, let the plants in your garden reach out for human help.

    Features:

    • 3.3-5V Input
    • 0-35mA measuring current
    • Analogic output

    Connecting the sensor

    The soil moisture 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 green wire with the Data terminal (marked as "DATA" in the board).

    After connecting the cables, tighten the screws.

    Node 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 green wire with the Data terminal (marked as "DATA" in the board).

    After connecting the cables, tighten the screws.

    Library Functions

    Getting data:

    The soil moisture can be read with a simple function. This function returns an integer with the value.

    {
        int soilMoisture = OpenGarden.readSoilMoisture();
    }

    NOTE: Each soil type has different moisture values, so it's necessary to do a calibration on each sensor. This requires measuring the value of moisture when the soil is completely dry, and then take a second measure after watering the soil. Now you can you choose a middle threshold value from which you consider that the plant should be watered.

    Example

    Upload the next code for seeing soil moisture in the serial monitor:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors(); //Initialize sensors power 
    }
    
    
    void loop() {
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(500); // Time for initializing the sensor
      int soilMoisture = OpenGarden.readSoilMoisture(); //Read the sensor
      OpenGarden.sensorPowerOFF(); //Turns off the sensor power supply
      
      Serial.print("Soil Moisture: ");
      Serial.println(soilMoisture);
      delay(2000);  //Wait 2 seconds
      
    }   		
    		

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

    4.4 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, 2 or 3)

    {
          OpenGarden.irrigationON(1);  //Turn ON the irrigation number 1 
          OpenGarden.irrigationOFF(2); //Turn OFF the irrigation number 2
    }
    			

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    void setup() {
      Serial.begin(9600);
      OpenGarden.initIrrigation(1); //Initialize irrigation number 1 (insert 1,2 or 3)
    }
    
    void loop() {
      OpenGarden.irrigationON(1); //Turn ON the irrigation number 1 (insert 1,2 or 3)
      Serial.println("Irrigation 1: ON");
      delay (5000); //Wait five seconds
      
      OpenGarden.irrigationOFF(1); //Turn OFF the irrigation number 1 (insert 1,2 or 3)
      Serial.println("Irrigation 1: OFF");
      delay (5000); //Wait five seconds
    }		
    	
    		

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

    4.5 RTC - DS1307

    Features

    The Open Garden gateway has a built in Real Time Clock (RTC), which keeps it informed of the time. This allows Open Garden 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()

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

    Getting the time:

    You can read the date and time with this function

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

    Example

    Setting the time:

    Upload the next code to set the time:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime now;
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initRTC(); //Initialize RTC
      OpenGarden.setTime(); //write time to the RTC chip
    }
    
    void loop() {
      delay(1000);
    }		
    		

    Getting the time:

    Upload the next code to get the time:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime now;
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initRTC();  
    }
    
    void loop() {
        now = OpenGarden.getTime(); //Get date and time
        
        //First way: Print date and time at once
        Serial.print("1er way: ");
        OpenGarden.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.6 Accessories for Open Garden Indoor

    4.6.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

    Get the sensor:

    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:

    {
          float soilTemperature = OpenGarden.readSoilTemperature();
    }

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors();   //Initialize sensors power
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(100);
    }
    
    void loop() {
      float soilTemperature = OpenGarden.readSoilTemperature(); //Read the sensor
      
      Serial.print("Soil temperature: ");
      Serial.print(soilTemperature);
      Serial.println("'C");
      delay(2000); //Wait 2 seconds
    }
    		
    		

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

    4.6.2 RF Power Strip & RF link

    Open Garden 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

    Get the modules:

    RF link features

    Features:

    • Frequency: 433Mhz
    • Modulation: ASK

    Get the modules:

    Connecting the actuator

    To use this actuator you will need the following materials:

    • RF Power strip and remote control
    • Arduino
    • Open Garden 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 Garden 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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
     
    #include <OpenGarden.h>
    #include <Wire.h>
    
    void setup() {
      Serial.begin(9600);
      RemoteReceiver::init(1, 3, 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.

    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. In the next example 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 Garden 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 Garden 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.

    {
          OpenGarden.sendPowerStrip(on1);  //Turn ON the plug number 1 
          OpenGarden.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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.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(9600); 
    }
    
    
    void loop() {
       OpenGarden.sendPowerStrip(on1); //Turn ON plug 1
       Serial.println("Plug 1: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off1);//Turn OFF plug 1
       Serial.println("Plug 1: OFF");
       delay(3000); //Wait three seconds
       
       
       OpenGarden.sendPowerStrip(on2); //Turn ON plug 2
       Serial.println("Plug 2: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off2);//Turn OFF plug 2
       Serial.println("Plug 2: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on3); //Turn ON plug 3
       Serial.println("Plug 3: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off3);//Turn OFF plug 3
       Serial.println("Plug 3: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on4); //Turn ON plug 4
       Serial.println("Plug 4: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off4);//Turn OFF plug 4
       Serial.println("Plug 4: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on5); //Turn ON plug 5
       Serial.println("Plug 5: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off5);//Turn OFF plug 5
       Serial.println("Plug 5: OFF");
       delay(3000); //Wait three seconds
    }			
    		

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

    4.6.3 Drip irrigation accesories

    These are the accessories needed to create a drip irrigation in your garden or your group of plants, consisting of a 5mm microtube compatible with the water pump of the Open Garden Indoor kit.

    Get the accesories:

    4.6.4 110-220V Power Converter

    Open Garden 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.

    Get the accesories:

    4.7 Full example

    Upload the next code for a full example of Open Garden Indoor.

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime myTime;
    int flag = 0; // auxiliar variable
    
    //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(9600);
      OpenGarden.initSensors(); //Initialize sensors power    
      OpenGarden.sensorPowerON();//Turn On the sensors
      delay(500);
      OpenGarden.initRF();
      OpenGarden.initRTC();
      OpenGarden.initIrrigation(1); //Initialize irrigation 1
      OpenGarden.initIrrigation(2); //Initialize irrigation 2
      OpenGarden.initIrrigation(3); //Initialize irrigation 3
    }
    
    void loop() {
      myTime = OpenGarden.getTime();
      OpenGarden.receiveFromNode();
    
    
    
      if ( myTime.second() == 0 && flag == 0  ){ //Only enter 1 time each minute
        
      //Get Gateway Sensors
      int soilMoisture0 = OpenGarden.readSoilMoisture();
      float airTemperature0 = OpenGarden.readAirTemperature();
      float airHumidity0 = OpenGarden.readAirHumidity();
      float soilTemperature0 = OpenGarden.readSoilTemperature();
      int luminosity0 = OpenGarden.readLuminosity();
      
      //Get Node Sensors
      Payload node1Packet = OpenGarden.getNodeData(node1); 
      Payload node2Packet = OpenGarden.getNodeData(node2);
      Payload node3Packet = OpenGarden.getNodeData(node3); 
      
      
      int soilMoisture1 = node1Packet.moisture;
      float airTemperature1 = node1Packet.temperature;
      float airHumidity1 = node1Packet.humidity;
      int luminosity1 = node1Packet.light;
      int battery1 = node1Packet.supplyV;
      
      int soilMoisture2 = node2Packet.moisture;
      float airTemperature2 = node2Packet.temperature;
      float airHumidity2 = node2Packet.humidity;
      int luminosity2 = node2Packet.light;
      int battery2 = node2Packet.supplyV;
      
      int soilMoisture3 = node3Packet.moisture;
      float airTemperature3 = node3Packet.temperature;
      float airHumidity3 = node3Packet.humidity;
      int luminosity3 = node3Packet.light;
      int battery3 = node3Packet.supplyV;
      
      //Turn On Irrigation 1 if gateway soil moisture falls under value: 350
      if(soilMoisture0 < 350 ){
          OpenGarden.irrigationON(1); 
      }
      else{
          OpenGarden.irrigationOFF(1);
      }
      
      //Turn On Irrigation 2 if node 1 or node 2 soil moisture falls under value: 300
      if( soilMoisture1<300 || soilMoisture2<300){
        OpenGarden.irrigationON(2);
      }
      else{
        OpenGarden.irrigationOFF(2);
      }
      
       if( soilMoisture3<300 ){
        OpenGarden.irrigationON(3);
      }
      else{
        OpenGarden.irrigationOFF(3);
      }
      
      //Turn On plug 1 where a lamp light is connected, if node 1 or node 2 
      //or node 3 luminosity falls under 30%
      if( luminosity1<30 || luminosity2<30 || luminosity3<30 ){
          OpenGarden.sendPowerStrip(on1); //Turn ON plug 1, 
      }
      else{
           OpenGarden.sendPowerStrip(off1);
      }
        
      
      //Serial Print all values
      Serial.println("***************************"); 
      OpenGarden.printTime(myTime);  
      Serial.println("*********"); 
      Serial.println("Node 1:");
      OpenGarden.printNode(node1Packet);  
      Serial.println("*********"); 
      Serial.println("Node 2:");
      OpenGarden.printNode(node2Packet); 
      Serial.println("*********"); 
      Serial.println("Node 3:");
      OpenGarden.printNode(node3Packet); 
      Serial.println("*********"); 
      
      Serial.println("Gateway:");
      Serial.print("Soil Moisture: ");
      Serial.println(soilMoisture0);
      Serial.print("Air Temperature: ");
      Serial.print(airTemperature0);
      Serial.println("*C");
      Serial.print("Air Humidity: ");
      Serial.print(airHumidity0);
      Serial.println("% RH");
      Serial.print("Soil Temperature: ");
      Serial.print(soilTemperature0);
      Serial.println("*C");
      Serial.print("Luminosity: ");
      Serial.print(luminosity0);
      Serial.println("%");
    
      
      flag = 1;
         }  
       
       else if (myTime.second() == 30 && flag == 1){
           flag = 0;
        }
    }
    		
    		

    Step 1:

    Place the nodes in the plants that we want to measure fixed with flanges, a stick or as you prefer. Insert the moisture sensor in the soil.

    Step 2:

    Insert the pump into a bucket.

    Step 3:

    Insert the 4mm male-male adapter in the microdrip tube

    Step 4:

    Insert the microdrip tube with the adapter into the pump.

    Step 5:

    Fill the bucket with water.

    Step 6:

    Insert a dropper in the plant soil near the node and insert the microtube from the pump.

    Step 7:

    Insert other section of microtube. Repeat the last and this step as many times as plants you want to water.

    Step 8:

    On the last plant we place the final dropper (has a single output).

    Step 9:

    Place the end dropper in the last plant.

    Step 10:

    Now you can power Open Garden. This is an example of final assembly.

    5. Open Garden Outdoor

    The complete kit can be found here.

    The parts of this kit are:

    • 1x General kit box
    • 1x Gateway Shield for Arduino
    • 1x Node
    • 1x DHT22 (temperature + humidity)
    • 1x Soil Moisture sensor
    • 2x LDR
    • 1x Electro-valve
    • 1x 12V Power Supply
    • 1x Big 433MHz internal antenna
    • 1x Small 433MHz internal antenna
    • 1x Big Enclosure for gateway
    • 1x Small Enclosure for node
    • 2x 16mm Cable Glands
    • 3x 20mm Cable Gland
    • 1x Vent Plug
    • 6x Flange
    • 7x M3 Metal Nuts
    • 4x M3 x 10mm Metal Screws
    • 3x M3 x 6mm Plastic Screws
    • 3x Metal Spacer M3
    • 1x Battery 3,7V 2300mAh
    • 1x Solar Panel
    • 1x Breadboard
    • 10x Arduino jumper cables
    • 1x Breakout Board for miniUSB
    • 1x miniUSB cable

    5.1 LDR - Light sensor

    Sensor Features

    This is a very small light sensor. A photocell changes (also called a photodetector, CdS or photoconductive cell) resistance depending on the amount of light it is exposed to. These little sensors make great ambient light triggers (when light in the room turns on, do something).

    Features:

    • Light resistance : ~1k Ohm
    • Dark resistance : ~10k Ohm
    • Max voltage : 150V
    • Max power: 100mW

    Connecting the sensor

    The Open Garden gateway and the node have a built in LDR, thats why you don't have to make any connection.

    Gateway connection

    Node connection

    Library Functions

    Getting data:

    The LDR returns an integer value of the percentage of light (0-100%).

    Example:

    {
        int luminosity = OpenGarden.readLuminosity();
    }

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h> 
    
    
    void setup() {
        Serial.begin(9600);
        OpenGarden.initSensors();    //Initialize sensors power 
    }
    
    
    void loop() {
        OpenGarden.sensorPowerON();  //Turns on the sensor power supply
        delay(500); // Time for initializing the sensor
        int luminosity = OpenGarden.readLuminosity();  //Read the sensor
        OpenGarden.sensorPowerOFF();  //Turns off the sensor power supply
      
        Serial.print("Luminosity: ");
        Serial.print(luminosity);
        Serial.println("%");
        delay(2000);   //Wait 2 seconds
    }
            		
    		

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

    5.2 DHT22 - Temperature + Humidity sensor

    Sensor Features

    The DHT22 is an humidity and temperature sensor with a single wire digital interface. The sensor is calibrated so you can get right to measuring relative humidity and temperature.

    Features:

    • 3.3-6V Input
    • 1-1.5mA measuring current
    • 40-50 uA standby current
    • Humidity from 0-100% RH
    • -40 - 80 °C temperature range
    • +-2% RH accuracy
    • +-0.5 degrees C

    Connecting the sensor

    The DHT22 sensor have 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.

    Node 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 air termperature and relative humidity of the air can be read by two simple functions. This functions return a float with the value.
    Example:

        float airTemperature = OpenGarden.readAirTemperature();
        float airHumidity = OpenGarden.readAirHumidity();
    

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors(); //Initialize sensors power 
    }
    
    
    void loop() {
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(1000); // Time for initializing the sensor
      float airTemperature = OpenGarden.readAirTemperature();  //Read the sensor
      OpenGarden.sensorPowerOFF(); //Turns off the sensor power supply
      
      Serial.print("Air Temperature: ");
      Serial.print(airTemperature);
      Serial.println("*C");
      delay(2000); //Wait 2 seconds
    }
    
            		
    		

    Watch the Serial monitor. Here is the USB output using the Arduino IDE serial port terminal:

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors(); //Initialize sensors power 
    }
    
    
    void loop() {
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(1000); // Time for initializing the sensor
      float airHumidity = OpenGarden.readAirHumidity();//Sensor takes 2s to read humidity
      OpenGarden.sensorPowerOFF(); //Turns off the sensor power supply
      
      Serial.print("Air Humidity: ");
      Serial.print(airHumidity);
      Serial.println("% RH");
      delay(2000);   //Wait 2 seconds
    }
      		
    		

    This is what we see in the Serial monitor using the Arduino IDE serial port terminal:

    5.3 Soil Moisture sensor

    Sensor Features

    This soil moisture sensor can be used to detect the moisture of soil or judge if there is water around the sensor, let the plants in your garden reach out for human help.

    Features:

    • 3.3-5V Input
    • 0-35mA measuring current
    • Analogic output

    Connecting the sensor

    The soil moisture 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 green wire with the Data terminal (marked as "DATA" in the board).

    After connecting the cables, tighten the screws.

    Node 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 green wire with the Data terminal (marked as "DATA" in the board).

    After connecting the cables, tighten the screws.

    Library Functions

    Getting data:

    The soil moisture can be read with a simple function. This function returns an integer with the value.

    {
        int soilMoisture = OpenGarden.readSoilMoisture();
    }

    NOTE: Each soil type has different moisture values, so it's necessary to do a calibration on each sensor. This requires measuring the value of moisture when the soil is completely dry, and then take a second measure after watering the soil. Now you can you choose a middle threshold value from which you consider that the plant should be watered.

    Example

    Upload the next code for seeing soil moisture in the serial monitor:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors(); //Initialize sensors power 
    }
    
    
    void loop() {
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(500); // Time for initializing the sensor
      int soilMoisture = OpenGarden.readSoilMoisture(); //Read the sensor
      OpenGarden.sensorPowerOFF(); //Turns off the sensor power supply
      
      Serial.print("Soil Moisture: ");
      Serial.println(soilMoisture);
      delay(2000);  //Wait 2 seconds
      
    }   		
    		

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

    5.4 Electro-valve

    Actuator features

    Features:

    • 12V DC input voltage
    • Maximum current: 450mA
    • Inlet/Outlet Ports: 1/2"
    • Operating mode: Normally closed
    • Pressure: 0.02~0.8MPa
    • Minimum pressure requirement: 0.02 Mpa
    • Temperature limitations: 120°C

    Connecting the actuator

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

    Gateway connection

    Connect the red wire with the positive terminal (marked with a "+" in the board), the black wire with the negative terminal (marked with a "-" in the board). 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 electro-valve can be activated with a simple function which must include the number of electro-valve (1, 2 or 3)

    {
          OpenGarden.irrigationON(1);  //Turn ON the irrigation number 1 
          OpenGarden.irrigationOFF(2); //Turn OFF the irrigation number 2
    }
    			

    Example

    Upload the next code to activate/deactivate the electro-valve each five seconds:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    void setup() {
      Serial.begin(9600);
      OpenGarden.initIrrigation(1); //Initialize irrigation number 1 (insert 1,2 or 3)
    }
    
    void loop() {
      OpenGarden.irrigationON(1); //Turn ON the irrigation number 1 (insert 1,2 or 3)
      Serial.println("Irrigation 1: ON");
      delay (5000); //Wait five seconds
      
      OpenGarden.irrigationOFF(1); //Turn OFF the irrigation number 1 (insert 1,2 or 3)
      Serial.println("Irrigation 1: OFF");
      delay (5000); //Wait five seconds
    }		
    	
    		

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

    5.5 RTC - DS1307

    Features

    The Open Garden gateway has a built in Real Time Clock (RTC), which keeps it informed of the time. This allows Open Garden 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()

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

    Getting the time:

    You can read the date and time with this function

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

    Example

    Setting the time:

    Upload the next code to set the time:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime now;
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initRTC(); //Initialize RTC
      OpenGarden.setTime(); //write time to the RTC chip
    }
    
    void loop() {
      delay(1000);
    }		
    		

    Getting the time:

    Upload the next code to get the time:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime now;
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initRTC();  
    }
    
    void loop() {
        now = OpenGarden.getTime(); //Get date and time
        
        //First way: Print date and time at once
        Serial.print("1er way: ");
        OpenGarden.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:

    5.6 Accessories for Open Garden Outdoor

    5.6.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

    Get the sensor:

    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:

    {
          float soilTemperature = OpenGarden.readSoilTemperature();
    }

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors();   //Initialize sensors power
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(100);
    }
    
    void loop() {
      float soilTemperature = OpenGarden.readSoilTemperature(); //Read the sensor
      
      Serial.print("Soil temperature: ");
      Serial.print(soilTemperature);
      Serial.println("'C");
      delay(2000); //Wait 2 seconds
    }
    		
    		

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

    5.6.2 RF Power Strip & RF link

    Open Garden 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

    Get the modules:

    RF link features

    Features:

    • Frequency: 433Mhz
    • Modulation: ASK

    Get the modules:

    Connecting the actuator

    To use this actuator you will need the following materials:

    • RF Power strip and remote control
    • Arduino
    • Open Garden 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 Garden 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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
     
    #include <OpenGarden.h>
    #include <Wire.h>
    
    void setup() {
      Serial.begin(9600);
      RemoteReceiver::init(1, 3, 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.

    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. In the next example 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 Garden 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 Garden 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.

    {
          OpenGarden.sendPowerStrip(on1);  //Turn ON the plug number 1 
          OpenGarden.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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.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(9600); 
    }
    
    
    void loop() {
       OpenGarden.sendPowerStrip(on1); //Turn ON plug 1
       Serial.println("Plug 1: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off1);//Turn OFF plug 1
       Serial.println("Plug 1: OFF");
       delay(3000); //Wait three seconds
       
       
       OpenGarden.sendPowerStrip(on2); //Turn ON plug 2
       Serial.println("Plug 2: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off2);//Turn OFF plug 2
       Serial.println("Plug 2: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on3); //Turn ON plug 3
       Serial.println("Plug 3: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off3);//Turn OFF plug 3
       Serial.println("Plug 3: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on4); //Turn ON plug 4
       Serial.println("Plug 4: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off4);//Turn OFF plug 4
       Serial.println("Plug 4: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on5); //Turn ON plug 5
       Serial.println("Plug 5: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off5);//Turn OFF plug 5
       Serial.println("Plug 5: OFF");
       delay(3000); //Wait three seconds
    }			
    		

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

    5.6.3 Sprinkler irrigation accesories

    These are the accessories needed to create a splinker irrigation in your garden, consisting of a sprinkler and 1/2" hose adapters compatible with the electro-valve of the Open Garden Outdoor kit.

    Get the accesories:

    5.6.4 110-220V Power Converter

    Open Garden 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.

    Get the accesories:

    5.7 Full example

    Upload the next code for a full example of Open Garden Outdoor.

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime myTime;
    int flag = 0; // auxiliar variable
    
    //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(9600);
      OpenGarden.initSensors(); //Initialize sensors power    
      OpenGarden.sensorPowerON();//Turn On the sensors
      delay(500);
      OpenGarden.initRF();
      OpenGarden.initRTC();
      OpenGarden.initIrrigation(1); //Initialize irrigation 1
      OpenGarden.initIrrigation(2); //Initialize irrigation 2
      OpenGarden.initIrrigation(3); //Initialize irrigation 3
    }
    
    void loop() {
      myTime = OpenGarden.getTime();
      OpenGarden.receiveFromNode();
    
      
      //Enter one time each 30 seconds and print data in serial monitor  
      if ( myTime.second() == 0 && flag == 0  ){ //Only enter 1 time each minute
        
      //Get Gateway Sensors
      int soilMoisture0 = OpenGarden.readSoilMoisture();
      float airTemperature0 = OpenGarden.readAirTemperature();
      float airHumidity0 = OpenGarden.readAirHumidity();
      float soilTemperature0 = OpenGarden.readSoilTemperature();
      int luminosity0 = OpenGarden.readLuminosity();
      
      //Get Node Sensors
      Payload node1Packet = OpenGarden.getNodeData(node1); 
      Payload node2Packet = OpenGarden.getNodeData(node2);
      Payload node3Packet = OpenGarden.getNodeData(node3); 
      
      
      int soilMoisture1 = node1Packet.moisture;
      float airTemperature1 = node1Packet.temperature;
      float airHumidity1 = node1Packet.humidity;
      int luminosity1 = node1Packet.light;
      int battery1 = node1Packet.supplyV;
      
      int soilMoisture2 = node2Packet.moisture;
      float airTemperature2 = node2Packet.temperature;
      float airHumidity2 = node2Packet.humidity;
      int luminosity2 = node2Packet.light;
      int battery2 = node2Packet.supplyV;
      
      int soilMoisture3 = node3Packet.moisture;
      float airTemperature3 = node3Packet.temperature;
      float airHumidity3 = node3Packet.humidity;
      int luminosity3 = node3Packet.light;
      int battery3 = node3Packet.supplyV;
      
      //Turn On Irrigation 1 if gateway soil moisture falls under value: 350
      if(soilMoisture0 < 350 ){
          OpenGarden.irrigationON(1); 
      }
      else{
          OpenGarden.irrigationOFF(1);
      }
      
      //Turn On Irrigation 2 if node 1 or node 2 soil moisture falls under value: 300
      if( soilMoisture1<300 || soilMoisture2<300){
        OpenGarden.irrigationON(2);
      }
      else{
        OpenGarden.irrigationOFF(2);
      }
      
       if( soilMoisture3<300 ){
        OpenGarden.irrigationON(3);
      }
      else{
        OpenGarden.irrigationOFF(3);
      }
      
      //Turn On plug 1 where a lamp light is connected, if node 1 or node 2 
      //or node 3 luminosity falls under 30%
      if( luminosity1<30 || luminosity2<30 || luminosity3<30 ){
          OpenGarden.sendPowerStrip(on1); //Turn ON plug 1, 
      }
      else{
           OpenGarden.sendPowerStrip(off1);
      }
        
      
      //Serial Print all values
      Serial.println("***************************"); 
      OpenGarden.printTime(myTime);  
      Serial.println("*********"); 
      Serial.println("Node 1:");
      OpenGarden.printNode(node1Packet);  
      Serial.println("*********"); 
      Serial.println("Node 2:");
      OpenGarden.printNode(node2Packet); 
      Serial.println("*********"); 
      Serial.println("Node 3:");
      OpenGarden.printNode(node3Packet); 
      Serial.println("*********"); 
      
      Serial.println("Gateway:");
      Serial.print("Soil Moisture: ");
      Serial.println(soilMoisture0);
      Serial.print("Air Temperature: ");
      Serial.print(airTemperature0);
      Serial.println("*C");
      Serial.print("Air Humidity: ");
      Serial.print(airHumidity0);
      Serial.println("% RH");
      Serial.print("Soil Temperature: ");
      Serial.print(soilTemperature0);
      Serial.println("*C");
      Serial.print("Luminosity: ");
      Serial.print(luminosity0);
      Serial.println("%");
    
      
      flag = 1;
         }  
       
       else if (myTime.second() == 30 && flag == 1){
           flag = 0;
        }
    }
    
    		

    Step 1:

    Place the nodes in the zones of the garden that you want to measure fixed with flanges, a stick or as you prefer. Insert the moisture sensor in the soil.

    Step 2:

    Connect the electrovalve with the little piece of hose to a closed tap.

    Step 3:

    Then connect a longer hose to the other side of the electrovalve.

    Step 4:

    Insert the sprinkler in the soil and connect the other side on the long hose to it.

    Step 5:

    Now you can power Open Garden and open the tap. This is an example of final assembly

    6. Open Garden Hydroponics

    The complete kit can be found here.

    The parts of this kit are:

    • 1x General kit box
    • 1x Gateway Shield for Arduino
    • 1x Hydroponics extension
    • 1x DHT22 (temperature + humidity)
    • 1x DS18B20
    • 1x LDR
    • 1x Electro-conductivity sensor
    • 1x pH sensor
    • 1x Big Enclosure for gateway
    • 1x 12V Power Supply
    • 3x 20mm Cable Gland
    • 1x SMA to BNC pigtail
    • 4x M3 Metal Nuts
    • 4x M3 x 10mm Metal Screws

    6.1 LDR - Light sensor

    Sensor Features

    This is a very small light sensor. A photocell changes (also called a photodetector, CdS or photoconductive cell) resistance depending on the amount of light it is exposed to. These little sensors make great ambient light triggers (when light in the room turns on, do something).

    Features:

    • Light resistance : ~1k Ohm
    • Dark resistance : ~10k Ohm
    • Max voltage : 150V
    • Max power: 100mW

    Connecting the sensor

    The Open Garden gateway and the node have a built in LDR, thats why you don't have to make any connection.

    Gateway connection

    Node connection

    Library Functions

    Getting data:

    The LDR returns an integer value of the percentage of light (0-100%).

    Example:

    {
        int luminosity = OpenGarden.readLuminosity();
    }

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h> 
    
    
    void setup() {
        Serial.begin(9600);
        OpenGarden.initSensors();    //Initialize sensors power 
    }
    
    
    void loop() {
        OpenGarden.sensorPowerON();  //Turns on the sensor power supply
        delay(500); // Time for initializing the sensor
        int luminosity = OpenGarden.readLuminosity();  //Read the sensor
        OpenGarden.sensorPowerOFF();  //Turns off the sensor power supply
      
        Serial.print("Luminosity: ");
        Serial.print(luminosity);
        Serial.println("%");
        delay(2000);   //Wait 2 seconds
    }
            		
    		

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

    6.2 DHT22 - Temperature + Humidity sensor

    Sensor Features

    The DHT22 is an humidity and temperature sensor with a single wire digital interface. The sensor is calibrated so you can get right to measuring relative humidity and temperature.

    Features:

    • 3.3-6V Input
    • 1-1.5mA measuring current
    • 40-50 uA standby current
    • Humidity from 0-100% RH
    • -40 - 80 °C temperature range
    • +-2% RH accuracy
    • +-0.5 degrees C

    Connecting the sensor

    The DHT22 sensor have 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.

    Node 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 air termperature and relative humidity of the air can be read by two simple functions. This functions return a float with the value.
    Example:

        float airTemperature = OpenGarden.readAirTemperature();
        float airHumidity = OpenGarden.readAirHumidity();
    

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors(); //Initialize sensors power 
    }
    
    
    void loop() {
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(1000); // Time for initializing the sensor
      float airTemperature = OpenGarden.readAirTemperature();  //Read the sensor
      OpenGarden.sensorPowerOFF(); //Turns off the sensor power supply
      
      Serial.print("Air Temperature: ");
      Serial.print(airTemperature);
      Serial.println("*C");
      delay(2000); //Wait 2 seconds
    }
    
            		
    		

    Watch the Serial monitor. Here is the USB output using the Arduino IDE serial port terminal:

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors(); //Initialize sensors power 
    }
    
    
    void loop() {
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(1000); // Time for initializing the sensor
      float airHumidity = OpenGarden.readAirHumidity();//Sensor takes 2s to read humidity
      OpenGarden.sensorPowerOFF(); //Turns off the sensor power supply
      
      Serial.print("Air Humidity: ");
      Serial.print(airHumidity);
      Serial.println("% RH");
      delay(2000);   //Wait 2 seconds
    }
      		
    		

    This is what we see in the Serial monitor using the Arduino IDE serial port terminal:

    6.3 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

    Get the sensor:

    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:

    {
          float soilTemperature = OpenGarden.readSoilTemperature();
    }

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors();   //Initialize sensors power
      OpenGarden.sensorPowerON(); //Turns on the sensor power supply
      delay(100);
    }
    
    void loop() {
      float soilTemperature = OpenGarden.readSoilTemperature(); //Read the sensor
      
      Serial.print("Soil temperature: ");
      Serial.print(soilTemperature);
      Serial.println("'C");
      delay(2000); //Wait 2 seconds
    }
    		
    		

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

    6.4 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 with the BNC-SMA pigtail to the Open Garden Hydroponics board.

    After connecting the cable, tighten the connector.

    Library functions

    Getting data

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

    Example:

    {
        OpenGarden.calibratepH(calibration_point_4,calibration_point_7,calibration_point_10);
        int mvpH = OpenGarden.readpH(); //Value in mV of pH
        float pH = OpenGarden.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 OpenGarden.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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    #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
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initSensors();   //Initialize sensors power 
      OpenGarden.sensorPowerON(); //Turn on sensors power supply
      OpenGarden.calibratepH(calibration_point_4,calibration_point_7,calibration_point_10);
      delay(1000);
    }
    
    void loop() {
    
      int mvpH = OpenGarden.readpH(); //Value in mV of pH
      Serial.print(F("pH Value in mV = "));
      Serial.print(mvpH);
    
      Serial.print(F(" // pH = "));
      float pH = OpenGarden.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:

    6.5 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:

    {
        OpenGarden.calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal);
        float resistanceEC = OpenGarden.readResistanceEC(); //EC Value in resistance
        float EC = OpenGarden.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 OpenGarden.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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.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(9600);
      OpenGarden.initSensors();   //Initialize sensors power 
      OpenGarden.sensorPowerON(); //Turn on sensors power supply
      OpenGarden.calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal);
      delay(500);
    }
    
    void loop() {
    
      float resistanceEC = OpenGarden.readResistanceEC(); //EC Value in resistance
      Serial.print(F("EC Value in resistance = "));
      Serial.print(resistanceEC);  
    
      Serial.print(F(" // EC Value = "));
      float EC = OpenGarden.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 electro-valve/pump number 3. However you can still using electro-valves/pumps number 1 and 2.

    6.6 RTC - DS1307

    Features

    The Open Garden gateway has a built in Real Time Clock (RTC), which keeps it informed of the time. This allows Open Garden 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()

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

    Getting the time:

    You can read the date and time with this function

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

    Example

    Setting the time:

    Upload the next code to set the time:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime now;
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initRTC(); //Initialize RTC
      OpenGarden.setTime(); //write time to the RTC chip
    }
    
    void loop() {
      delay(1000);
    }		
    		

    Getting the time:

    Upload the next code to get the time:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime now;
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initRTC();  
    }
    
    void loop() {
        now = OpenGarden.getTime(); //Get date and time
        
        //First way: Print date and time at once
        Serial.print("1er way: ");
        OpenGarden.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:

    6.7 Accessories for Open Garden Hydroponics

    6.7.1 RF Power Strip & RF link

    Open Garden 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

    Get the modules:

    RF link features

    Features:

    • Frequency: 433Mhz
    • Modulation: ASK

    Get the modules:

    Connecting the actuator

    To use this actuator you will need the following materials:

    • RF Power strip and remote control
    • Arduino
    • Open Garden 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 Garden 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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
     
    #include <OpenGarden.h>
    #include <Wire.h>
    
    void setup() {
      Serial.begin(9600);
      RemoteReceiver::init(1, 3, 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.

    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. In the next example 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 Garden 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 Garden 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.

    {
          OpenGarden.sendPowerStrip(on1);  //Turn ON the plug number 1 
          OpenGarden.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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.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(9600); 
    }
    
    
    void loop() {
       OpenGarden.sendPowerStrip(on1); //Turn ON plug 1
       Serial.println("Plug 1: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off1);//Turn OFF plug 1
       Serial.println("Plug 1: OFF");
       delay(3000); //Wait three seconds
       
       
       OpenGarden.sendPowerStrip(on2); //Turn ON plug 2
       Serial.println("Plug 2: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off2);//Turn OFF plug 2
       Serial.println("Plug 2: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on3); //Turn ON plug 3
       Serial.println("Plug 3: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off3);//Turn OFF plug 3
       Serial.println("Plug 3: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on4); //Turn ON plug 4
       Serial.println("Plug 4: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off4);//Turn OFF plug 4
       Serial.println("Plug 4: OFF");
       delay(3000); //Wait three seconds
    
    
       OpenGarden.sendPowerStrip(on5); //Turn ON plug 5
       Serial.println("Plug 5: ON");
       delay(3000); //Wait three seconds
       OpenGarden.sendPowerStrip(off5);//Turn OFF plug 5
       Serial.println("Plug 5: OFF");
       delay(3000); //Wait three seconds
    }			
    		

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

    6.7.2 Oxygen Pump

    Features:

    • Max output: 100 liters/hour
    • 1 air outlet
    • Includes 10 metres of airline & 1 airstone
    • 230 volt / 3 watt

    Get the actuator:

    Connecting the actuator

    You can connect the oxygen pump 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.

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

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    //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(9600); 
    }
    
    void loop() {
       OpenGarden.sendPowerStrip(on2);  //Turn ON the plug 2 (oxygen pump)
       Serial.println("Oxygen pump: ON");
       delay(5000); //Wait five seconds
       
       OpenGarden.sendPowerStrip(off2);  //Turn OFF the plug 2 (oxygen pump)
       Serial.println("Oxygen pump: OFF");
       delay(5000); //Wait five seconds
    }		
    		

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

    6.7.3 Growing Light

    Features:

    • Light Source: LED
    • Input voltage(V): 12
    • Lamp Luminous Efficiency(lm/w): 100
    • Working temperature: -20°C - 60°C
    • IP Rating: IP68
    • Lamp Power(W): 9
    • Lamp Luminous Flux(lm): 900

    Get the actuator:

    Connecting the actuator

    You can connect the growing light 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.

    {
          OpenGarden.sendPowerStrip(on3);  //Turn ON the plug 3 (growing light) 
          OpenGarden.sendPowerStrip(off3); //Turn OFF the plug 3 (growing light)
    }

    Example

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

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    //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(9600); 
    }
    
    void loop() {
       OpenGarden.sendPowerStrip(on3);  //Turn ON the plug 3 (growing light) 
       Serial.println("Growing light: ON");
       delay(5000); //Wait five seconds
       
       OpenGarden.sendPowerStrip(off3);//Turn OFF the plug 3 (growing light)
       Serial.println("Growing light: OFF");
       delay(5000); //Wait five seconds
    }	

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

    6.7.4 110-220V Power Converter

    Open Garden 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.

    Get the accesories:

    6.8 Full example

    Upload the next code for a full example of Open Garden Hydroponics.

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime myTime;
    int flag = 0; // auxiliar variable
    
    #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
    
    #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
    
    //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(9600);
      OpenGarden.initSensors(); //Initialize sensors power    
      OpenGarden.sensorPowerON();//Turn On the sensors
      delay(500);
      OpenGarden.initRTC();
      OpenGarden.initIrrigation(1); //Initialize irrigation 1
      OpenGarden.initIrrigation(2); //Initialize irrigation 2
      OpenGarden.initIrrigation(3); //Initialize irrigation 3
      OpenGarden.calibratepH(calibration_point_4,calibration_point_7,calibration_point_10);
      OpenGarden.calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal);
      delay(500);
    }
    
    void loop() {
      myTime = OpenGarden.getTime();
    
    
      if ( myTime.second() == 0 && flag == 0  ){ //Only enter 1 time each minute
    
        //Read DHT22
        float airTemperature = OpenGarden.readAirTemperature(); 
        float airHumidity = OpenGarden.readAirHumidity(); 
    
        //Read DS18B20
        float waterTemperature = OpenGarden.readSoilTemperature();
    
        //Read LDR
        int luminosity = OpenGarden.readLuminosity(); 
    
        //Read the pH sensor
        int mvpH = OpenGarden.readpH(); //Value in mV of pH
        float pH = OpenGarden.pHConversion(mvpH); //Calculate pH value
    
        //Read the conductivity sensor in µS/cm
        float resistanceEC = OpenGarden.readResistanceEC(); //EC Value in resistance
        float EC = OpenGarden.ECConversion(resistanceEC); //EC Value in µS/cm
    
    
    
        //Turn On plug 1 where a grown light is connected from 10:00 to 20:00 hours
        if ( myTime.hour() == 10 && myTime.minute() == 0){
          OpenGarden.sendPowerStrip(on1); 
        }
    
        if ( myTime.hour() == 20 && myTime.minute() == 0){
          OpenGarden.sendPowerStrip(off1); 
        }
    
    
    
        //Serial Print all values
        Serial.println(F("***************************")); 
        OpenGarden.printTime(myTime);
        Serial.println("");
        Serial.print(F("Air Temperature: "));
        Serial.print(airTemperature);
        Serial.println("*C");
        Serial.print(F("Air Humidity: "));
        Serial.print(airHumidity);
        Serial.println(F("% RH"));
        Serial.print(F("Water Temperature: "));
        Serial.print(waterTemperature);
        Serial.println("*C");
        Serial.print(F("Luminosity: "));
        Serial.print(luminosity);
        Serial.println("%");
        Serial.print(F("pH Level: "));
        Serial.println(pH);
        Serial.print(F("Conductivity: "));
        Serial.print(EC);
        Serial.println(F("uS/cm"));
    
        flag = 1;
      }  
    
      else if (myTime.second() == 30 && flag == 1){
        flag = 0;
      }
    }
    		

    The nice pot we used for testing the Hydroponic Kit is AquaFarm designed by Back To The Roots.

    Step 1:

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

    Step 2:

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

    Step 3:

    Insert the pH sensor in the water. The sensor must be inserted at least 4 cm in water. The assembly should look like the picture.

    Step 4:

    Finally connect the oxygen pump and the growing light to the RF power strip and place them.

    7. Boxes

    To facilitate the installation of Open Garden, the kits include different types of boxes. In this step, we will explain you a way to mount the boxes but it is only an example. You can set the boxes 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 boxes.

    You can differentiate between three types of boxes.

    7.1 Gateway box

    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 that the Arduino is fixed to the box, you have to put the power supply, the sensors and the actuators that your are going to use throw the glands.

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

    After that tighten all the glands, put on the communication module, the antenna (if you are going to use it) and put the Open Garden Gateway over the Arduino.

    Finally, you can close the box, and you have got the gateway box ready to use..

    7.2 Gateway with Hydroponics 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.

    Now that the Arduino is fixed to the box, you have to put the power supply the sensors and the actuators that your are going to use throw the glands.

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

    Now take the hydroponics extension board and put it over Open Garden shield.

    Screw the EC sensor

    Now put the pigtail in the box and connect the pigtail to the hydroponics extension.

    Connect the pH sensor to the external BNC connector.

    Finally you can put the RF link module in case you have this accesory and close the box.

    7.3 Node 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 spacers to the internal plate with M3 nuts.

    After that, you have to put the battery with some flanges to the plate

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

    Now that the plate is fixed to the box, you have to put the the sensors your are going to use throw the glands and tighten them.

    Then, you have to take the Open Garden Node and screw the sensor in the correct position.

    Now you have to cut the little connector in the solar panel and stick it to the transparent cover of the node box. Screw the two wires of the solar panel to the node where you can read BATT. CHARGE (IN-: Black wire, IN+: Red wire) and connect the antenna as you can see in this photo.

    Connect the battery and screw the Open Garden Node over the spacers.

    Close the box and you have the node box ready to use.

    8. Sending the data to a Web Server

    Web Server

    Open Garden nodes communicate with a special node that makes the role of gateway using 433MHz module and then, this gateway send 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 `opengarden`; 
    USE `opengarden`; 
    
    
    -- 
    -- 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, 'irrigation1', 0); 
    INSERT INTO actuators VALUES (2, 'irrigation2', 0); 
    INSERT INTO actuators VALUES (3, 'irrigation3', 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).

    oppengarden-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:
    
    //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 opengarden.

      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 central base or gateway to know how turn on or turn off the different actuators.

    meekrodb.2.2.class.php
    File used to manage the database.

    opengarden.php
    File that centralize all the operations used in web application.

    set_sensors.php
    File used by the central base or gateway to save the values of all sensors in the 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:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    //Enter here your data
    const char server[] = "YOUR_SERVER_IP";
    const char server_port[] = "YOUR_SERVER_PORT";
    const char wifi_ssid[] = "YOUR_WIFI_SSID";
    const char wifi_password[] = "YOUR_WIFI_PASSWORD";
    
    String wifiString;
    char buffer[20];
    int flag = 0; // auxiliar variable
    DateTime myTime;
    
    void setup() {
      Serial.begin(115200);
      OpenGarden.initSensors();    //Initialize sensors power 
      OpenGarden.sensorPowerON();  //Turns on the sensor power supply
      delay(100);
      OpenGarden.initRF();
      OpenGarden.initRTC();
      wificonfig(); 
    }
    
    
    void loop() {
    
      OpenGarden.receiveFromNode(); //Receive data from node
      myTime = OpenGarden.getTime();
      OpenGarden.printTime(myTime); 
    
      if ( myTime.minute() == 0 && flag == 0  ){ //Only enter 1 time each hour 
    
        //Get Gateway Sensors
        int soilMoisture0 = OpenGarden.readSoilMoisture();
        float airTemperature0 = OpenGarden.readAirTemperature();
        float airHumidity0 = OpenGarden.readAirHumidity();
        float soilTemperature0 = OpenGarden.readSoilTemperature();
        int luminosity0 = OpenGarden.readLuminosity();
    
        //Get Node Sensors
        Payload node1Packet = OpenGarden.getNodeData(node1); 
        Payload node2Packet = OpenGarden.getNodeData(node2);
        Payload node3Packet = OpenGarden.getNodeData(node3); 
    
    
        int soilMoisture1 = node1Packet.moisture;
        float airTemperature1 = node1Packet.temperature;
        float airHumidity1 = node1Packet.humidity;
        int luminosity1 = node1Packet.light;
        int battery1 = node1Packet.supplyV;
    
        int soilMoisture2 = node2Packet.moisture;
        float airTemperature2 = node2Packet.temperature;
        float airHumidity2 = node2Packet.humidity;
        int luminosity2 = node2Packet.light;
        int battery2 = node2Packet.supplyV;
    
        int soilMoisture3 = node3Packet.moisture;
        float airTemperature3 = node3Packet.temperature;
        float airHumidity3 = node3Packet.humidity;
        int luminosity3 = node3Packet.light;
        int battery3 = node3Packet.supplyV;
    
    
        //Create string of the floats to send it
        dtostrf(airTemperature0,2,1,buffer);
        String airTemperature0_wf = String (buffer);
        dtostrf(airHumidity0,2,1,buffer);
        String airHumidity0_wf = String (buffer);
        dtostrf(soilTemperature0,2,1,buffer);
        String soilTemperature0_wf = String (buffer);
    
        dtostrf(airTemperature1,2,1,buffer);
        String airTemperature1_wf = String (buffer);
        dtostrf(airHumidity1,2,1,buffer);
        String airHumidity1_wf = String (buffer);
    
        dtostrf(airTemperature2,2,1,buffer);
        String airTemperature2_wf = String (buffer);
        dtostrf(airHumidity2,2,1,buffer);
        String airHumidity2_wf = String (buffer);
    
        dtostrf(airTemperature3,2,1,buffer);
        String airTemperature3_wf = String (buffer);
        dtostrf(airHumidity3,2,1,buffer);
        String airHumidity3_wf = String (buffer);
    
        /*
       You must create strings with this structure: "node_id:sensor_type:value;node_id2:sensor_type2:value2;...." 
         Note the ";" between different structures
         
         Where node_id:
         0 - Gateway
         1 - Node 1
         2 - Node 2
         3 - Node 3
         
         And where sensor_type:
         0 - Soil moisture 
         1 - Soil temperature
         2 - Air Humidity
         3 - Air Temperature
         4 - Light level 
         5 - Battery level 
         6 - pH level 
         7 - Electrical conductivity
         
         For example: "0:0:56;0:1:17.54;0:2:56.45"
         This means that you send data of the gateway: Soil moisture=56, Soil temperature=17.54 and Air humidity=56.45
         
         */
    
        //Cut data in several string because the wifi module have problems with longer strings
        wifiString= "0:0:" + String(soilMoisture0) + ";0:1:"  + soilTemperature0_wf + ";0:2:" + airHumidity0_wf; 
        sendwifi();
        enterCMD();
    
    
        wifiString= "0:3:"   +  airTemperature0_wf + ";0:4:" + String(luminosity0); 
        sendwifi();
        enterCMD();
    
    
        wifiString = "1:0:" + String(soilMoisture1) + ";1:2:" + airHumidity1_wf + ";1:3:"  +  airTemperature1_wf + ";1:4:" + String(luminosity1);
        sendwifi();
        enterCMD();
    
        
        wifiString = "2:0:" + String(soilMoisture2) + ";2:2:" + airHumidity2_wf + ";2:3:"  +  airTemperature2_wf + ";2:4:" + String(luminosity2);
        sendwifi();
        enterCMD();
    
    
        wifiString = "3:0:" + String(soilMoisture3) + ";3:2:" + airHumidity3_wf + ";3:3:"  +  airTemperature3_wf + ";3:4:" + String(luminosity3);
        sendwifi();
        enterCMD();
        
        
        wifiString = "1:5:" +  String(battery1) + ";2:5:" +  String(battery2) + ";3:5:" +  String(battery3); 
        sendwifi();
        enterCMD();
    
    
        flag = 1;  
    
      }
    
      else if (myTime.minute() == 30 && flag == 1){
        flag = 0;
      } 
    
    }
    
    
    //*********************************************************************
    //*********************************************************************
    
    
    void check() {
      delay(1500);
      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 "));
      Serial.print(wifi_password);
      Serial.print(F("\r"));
      check();
      Serial.print(F("join "));
      Serial.print(wifi_ssid);
      Serial.print(F("\r"));
      check();
    }
    
    
    void enterCMD() {
      Serial.println("");
      // 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 "));
      Serial.print(server);
      Serial.print(F("\r"));
    
      check(); //Insert here your IP
    
      //Configures HTTP connection
      Serial.print(F("set i r "));
      Serial.print(server_port);
      Serial.print(F("\r"));
      check();
    
      Serial.print(F("set o f 1\r"));
      check();
    
      Serial.print(F("set c r GET$/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();
      Serial.print(F("open\r"));
    }
    
    
    void autoflush()
    {
      while (Serial.available() > 0)
      {
        Serial.read();
      }
    }
    
    		
    		

    This example gets the irrigation actuators state from a web server

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    //Enter here your data
    const char server[] = "YOUR_SERVER_IP";
    const char server_port[] = "YOUR_SERVER_PORT";
    const char wifi_ssid[] = "YOUR_WIFI_SSID";
    const char wifi_password[] = "YOUR_WIFI_PASSWORD";
    
    char recv[512];
    int cont;
    
    char irrigation1_wf;
    char irrigation2_wf;
    char irrigation3_wf;
    
    void setup() {
      Serial.begin(115200);
      OpenGarden.initIrrigation(1); //Initialize irrigation number 1 
      OpenGarden.initIrrigation(2); //Initialize irrigation number 2
      OpenGarden.initIrrigation(3); //Initialize irrigation number 3
      OpenGarden.irrigationOFF(1);
      OpenGarden.irrigationOFF(2);
      OpenGarden.irrigationOFF(3);
      cleanVector();
      wificonfig(); 
    }
    
    
    void loop() {
      getActuators();
    
      Serial.println();
      if (irrigation1_wf == '0'){
        OpenGarden.irrigationOFF(1); //Turn OFF the irrigation number 1 
        Serial.println("Irrigation 1 OFF");
      }
      else if (irrigation1_wf == '1'){
        OpenGarden.irrigationON(1); //Turn ON the irrigation number 1 
        Serial.println("Irrigation 1 ON");
      }
      else{
        Serial.println("Irrigation 1 BAD DATA");
      }
    
    
      if (irrigation2_wf == '0'){
        OpenGarden.irrigationOFF(2); //Turn OFF the irrigation number 2 
        Serial.println("Irrigation 2 OFF");
      }
      else if (irrigation2_wf == '1'){
        OpenGarden.irrigationON(2); //Turn ON the irrigation number 2
        Serial.println("Irrigation 2 ON");  
      }
      else{
        Serial.println("Irrigation 2 BAD DATA");
      }
    
    
      if (irrigation3_wf == '0'){
        OpenGarden.irrigationOFF(3); //Turn OFF the irrigation number 3
        Serial.println("Irrigation 3 OFF");
      }
      else if (irrigation3_wf == '1'){
        OpenGarden.irrigationON(3); //Turn ON the irrigation number 3
        Serial.println("Irrigation 3 ON");
      }
      else{
        Serial.println("Irrigation 3 BAD DATA");
      }
    
      cleanVector();
      enterCMD();
    
      delay(5000);
    }
    
    
    //*********************************************************************
    //*********************************************************************
    
    
    void cleanVector(){
      recv[0] = 0; 
      recv[1] = 0;
      recv[2] = 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 "));
      Serial.print(wifi_password);
      Serial.print(F("\r"));
      check();
      Serial.print(F("join "));
      Serial.print(wifi_ssid);
      Serial.print(F("\r"));
      check();
    }
    
    void getActuators(){
      
      //Configures HTTP connection
      Serial.print(F("set dns name "));
      Serial.print(server);
      Serial.print(F("\r"));
      check();
       
      Serial.print("set ip adress 0\r"); 
      check();
    
      Serial.print(F("set i r "));
      Serial.print(server_port);
      Serial.print(F("\r"));
      
      check();
      Serial.print("set com remote 0\r"); 
      check();
      Serial.print("open\r"); 
      check();
      Serial.flush(); 
      Serial.print("GET /get_actuators.php?actuators\r"); 
      checkData();
    
    
    }
    
    void enterCMD() {
      Serial.println("");
      // Enters in command mode
      Serial.print(F("$$$"));
      delay(100);
      check();
      Serial.flush();
    }
    
    
    void check(){
      delay(1500);
      autoflush(); 
    }
    
    
    void checkData(){
      cont=0;   
      delay(3000);
      while (Serial.available()>0)
      {
        recv[cont]=Serial.read(); 
        delay(10);
        cont++;
      }
      recv[cont]='\0';
    
      irrigation1_wf= recv[0]; 
      irrigation2_wf= recv[1];
      irrigation3_wf= recv[2];
    
      //Serial.print("Received:");
      //Serial.print(recv);
    
      autoflush(); 
      delay(100);
    }
    
    
    void autoflush()
    {
      while (Serial.available()>0)
      {
        Serial.read(); 
      }
    }
    
    		

    Refer to Wifi tutorials for more information.

    9. Visualizing the data

    9.1 From a web browser

    Open Garden 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/opengarden-app

    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 the list of all configured sensors and gateways.

    Each node/gateway element has at left its status (online/offline), followed the name of the sensor. Finally, nodes and gateways have an icon at the right that if you click it, you will obtain all the sensor measures. The gateway have an icon near the previous, that clicking it you will get the 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.

    10. Complementary Apps for Open Garden

    In order to enhance the experience with Open Garden we recommend viewing additional information about plants in MyGarden.org. It's is a platform that originated in the minds of enthusiastic Internet users with a passion for gardening. The purpose is to share our garden virtually with people around us in a social network.

    Besides this, they have designed a friendly app for iPhone and Android. It allows you to manage your own garden, add messages, find gardeners and plants, lookup info on plants, trees, perennials etc ...

    Practical example of use

    We have a garden with a drip irrigation of lettuces and a hydroponic culture with tomatoes. To check the corresponding parameters that they need to have a good growth I can check the info in MyGarden app.

    When you open the app you have five actions to choose: Plant overview, Add a message, Message, Gardeners, Garden Todo's. Let's log in and enter in the option "Plant overview". Now we can search the plant and read the paragraph in order to see the differents features of this plants. Let's search the lettuce!

    Here we can see that the lettuce needs to be moist but well-drained. To get this we are going to make a program to check the moisture, and water twice a week only if the moisture falls under a value of 500:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    Payload node1Packet;
    DateTime now;
    
    
    void setup () {
        Serial.begin(9600);
        OpenGarden.initRF();
        OpenGarden.initRTC();
        OpenGarden.initIrrigation(1); //Initialize irrigation number 1 
        OpenGarden.irrigationOFF(1); //Turn OFF the irrigation number 1
    }
    
    void loop() {
        //Get date and time
        now = OpenGarden.getTime();
        
        //Receive data from node
        OpenGarden.receiveFromNode();
        
        //Get the last data received from nodes
        node1Packet = OpenGarden.getNodeData(node1); 
        
        int soilMoisture1 = node1Packet.moisture;
        
        
        if ( now.dayOfWeek()==1 && soilMoisture1<500 ||  now.dayOfWeek()==4 && soilMoisture1<500){   
            OpenGarden.irrigationON(1); //Turn ON the irrigation number 1 
        }
        
        else{
            OpenGarden.irrigationOFF(1); //Turn OFF the irrigation number 1
        }
            
    }
            

    Now we will check the information about our hydroponic tomatoes culture.

    In the tomatoes file we can see that it needs a neutral pH and partial shade or full sun. In order to get this we need to measure with Open Garden Hydroponics to keep our culture with a pH around 6 and turn on a growing light twelve hours per day. We can get this with this easy program:

    Code:
    /*  
     *  OpenGarden 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:           2.2
     *  Design:            David Gasc├│n 
     *  Implementation:    Victor Boria, Luis Martin & Jorge Casanova
     */
    
    #include <OpenGarden.h>
    #include <Wire.h>
    
    DateTime myTime;
    
    //Power strip codes
    unsigned long on1 = 1597145202;
    unsigned long off1 = 1597145204;
    
    
    
    void setup() {
      Serial.begin(9600);
      OpenGarden.initRTC();
      OpenGarden.initSensors();  //Initialize sensors power 
      OpenGarden.sensorPowerON();//Turn on sensors power supply
      OpenGarden.sendPowerStrip(off1);
      delay(1000);
    }
    
    void loop() {
      int mvpH = (OpenGarden.readpHLevel()*5000.0)/1024.0; //Read the sensor and convert it to milivolts
      
      //This equation comes from our calibration
      //It converts milliVolts in pH grades
      float valuepH=(-mvpH*6.0/323.0)+(14885.0/323.0);
      
      Serial.print("pH Level: ");
      Serial.print(valuepH);
      
      myTime = OpenGarden.getTime();
      
      //Turn On plug 1 where a grown light is connected from 10:00 to 22:00 hours
      if ( myTime.hour() == 10 && myTime.minute() == 0){
        OpenGarden.sendPowerStrip(on1); 
      }
      
      if ( myTime.hour() == 22 && myTime.minute() == 0){
        OpenGarden.sendPowerStrip(off1); 
      }
      
      delay(1000);  //Wait a second
    }
    
            

    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 Garden.

    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

    Accesories

    Accesories for Open Garden Indoor

    Accesories for Open Garden Outdoor

    Accesories for Open Garden Hydroponics

    Other





    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: