User Tools

Site Tools


projects:hydroponics_sassi_matera_1:start

Hydroponics in the Sassi of Matera with Arduino

Purpose

The purpose of the project is to monitor a hydroponics system to check that:

  • The pump of the water circuit is running
  • The pH of the water is correct
  • The water level is correct

There is a LCD screen to display the pH, water level and if the pump is running. In case something is going wrong an email is sent.

Equipment used

Assembly and wiring

odg source file

  • The water-flow sensor is connected to digital pin 7 of the Arduino board. The sensor is inserted within the tube linking the hydroponics installation and the pump in the tank. So if there is a flow of water the little wheel in the sensor is turning and it gives a signal to the Arduino board.
  • LCD display : it is using the I2C protocol so the SDA and SCL outputs are respectively connected to digital pins 2 and 3 of the Arduino board (The Yùn is similar to the Leonardo so pin 2 and 3 are used for I2C).
  • The ultra-sonic sensor have echo and trig outputs connected to digital pins 8 and 9.
  • The pH sensor is connected to analogical pin A0. For the pH sensor we use an external power so that it receives a tension close to 5v which improves the accuracy. Using the Arduino Yùn Vcc output gives a tension that is too weak (about 4.7v). An important thing is to properly calibrate the sensor : please carefully read the sensor documentation.
    Here are some important indications to calibrate it:
    • After having put the electrode into a standard solution (i.e. distilled water), set up the gain turning the screw nearby the BNC connector so that you get a pH of 7, if the temperature is 25°C. Please note that the temperature plays a significant role on pH measurement. However, the temperature affects not only your sensor but also your sample. All solutions will change their pH value with temperature : the pH of pure water decreases as the temperature increases.
    • To check if the pH is right in an acid solution you can use the “Sprite” beverage which pH is about 4.08.
    • For the tests let the electrode several minutes in the solution to see if the pH is stable.
    • If you want to measure the pH value of other solution, you must wash the pH electrode first.
    • The electrode must be regularly put into a Kcl solution so that it can be able afterwards to evaluate the pH (that is to say it can't be let indefinitely in the water to measure the pH from).

Software

Presentation

We chose the Arduino Yùn because we wanted to be able to send an email if something is going wrong (pump not working, wrong water level or pH value). Of course if you want to use an other board it is possible. In this case you have to adapt the pin numbers : especially the ones used to connect the LCD (look at the pins corresponding to SDA and SCL on your board) and the one used for the water-flow sensor (because it must be a pin that supports software interrupt).

Installation

  • Get the source code.
    • Copy the Arduino sketch to your sketch directory.
    • Copy the send_email.py script to your Lino system using ssh, for example in the /root/scripts/ directory.
    • Connect to your Lino terminal over ssh, go to the directory where you put the script and try to send an email adapting the parameters to your mail settings :
      python send_email.py my_smtp_server mail_username mail_password from_email_address to_email_address "test from yun" "Hello!"
  • Open the Arduino sketch in the Arduino IDE and from there create a new tab (clicking on the arrow on the top-right corner).
  • Name it Params.h.
  • Paste the code below in this new file :
    • #define MAIL_BIN "python /root/scripts/send_email.py"
      #define SMTP_SERVER "my_smtp_server";
      #define SMTP_USERNAME "mail_username";
      #define SMTP_PASSWORD "mail_password";
      #define SMTP_FROM "from_mail_address";
      #define SMTP_TO "to_mail_address";
      
      #define TANK_HEIGHT 35 //50; // in cm
      #define TANK_SURFACE 1320 // in cm2
      #define TANK_MAX_L 45 // in L
      #define TANK_MIN_L 20 // in L
      
      // pH deviation compensate
      #define PH_OFFSET 0.13
      #define PH_MIN 6
      #define PH_MAX 8
      
      #define SEND_MAIL true
      #define DEBUG true
      
      // Read water level every (in ms) ...
      #define WATER_H_FREQ 60000
      // Check if the pump is working every...
      #define PUMP_OK_FREQ 30000
      // Read pH value every...
      #define PH_FREQ 60000
      
      // WATER_FLOW_SENSOR
      #define WATER_FLOW_PIN 7
      #define WATER_FLOW_ITR 4 // Interruption number used
        // Min nb of pulse of the water wheel in one sec
        // to consider it is working
      #define WATER_WHEEL_MIN_PULSE 4
      
      // Ultra sound sensor
      #define USND_ECHO_PIN 8
      #define USND_TRIG_PIN 9
      
      // pH sensor
      #define PH_PIN A0
    • Adapt all parameters to send an email.
    • Adapt all parameters of the tank :
      • TANK_HEIGHT and TANK_SURFACE according to your tank size.
      • TANK_MIN_L and TANK_MAX_L to set the acceptable level of water.
    • Adapt all parameters defining your pH settings :
      • PH_OFFSET (see the sensor documentation to set it).
      • PH_MIN and PH_MAX to set the acceptable values of the pH.

How it is working

  • The Arduino sketch includes the Params.h file defined above.
  • The setup() function initialises the LCD screen and the Bridge library (used to communicate with Linino).
  • The loop() function checks at a given frequency :
    • If the pump is running.
    • The water level.
    • The pH value.
    • If something is wrong then an email is sent by calling the Python script on Linino. We could have used the Temboo platform but according to us it made it unnecessarily complicated (have to create an account, get an API key, have a gmail account…) and it makes the software dependant from an external service.

If you have questions or comments feel free to contact us.

/var/www/tech_mirelsol/data/pages/projects/hydroponics_sassi_matera_1/start.txt · Last modified: 16/06/2014 15:13 by Mirelsol