Nutrient dosing system (EC/ppm) – Hydroponics (Arduino)
Introduction
This article is specifically on the control of a nutrient dosing pump with the Arduino microcontroller. To work with the Arduino microcontroller is really not difficult and anyone can do it. Learning to work with the Arduino microcontroller opens up a whole range of possibilities. You can, for instance, measure all kinds of parameters with the wide range of affordable sensors that are available for the Arduino. You can control pumps, heaters, fans and other devices. You can also communicate the values to your cell phone to the internet or any other place via Wi-Fi, Bluetooth or cell phone communication modules.
System Block diagram
Let’s have a look at the system block diagram.

In the sketch above you can see the block diagram of the nutrient dosing system. The two sensors that we use is a temperature sensor and then also the DIY EC sensor. In order to do temperature compensation, we need the temperature sensor and of course, the EC sensor is for the electric conductivity measurement.
The Arduino microcontroller that we going to use is the Arduino Uno. We will switch the dosing pump with a relay unit that’s coupled to the Arduino. The pump can be any type of dosing pump that you have available.
What is important to note is that the supply of the dosing pump is totally separate from the supply of the Arduino. Depending on the type of pump that you have it can be a DC supply, a 110 volt AC supply, a 230 volt AC supply or any supply that your dosing pump needs. The relay is only there to do the switching. The switch or output part of the relay is totally isolated from the Arduino supply. Please note that only one of the two relays in the two relay module is used for this project and you can also use a one relay module.
The EC sensor
The EC sensor used in this project is a DIY homemade sensor and the details can be found in the video below.
Circuit on breadboard
In the sketch below you can see the circuit as built on a breadboard. At the top left, you can see the 10K thermistor that’s used as a temperature sensor. Just below that is the constructed EC probe and to the right is the relay module.
As you can derive from the circuit, the relay is coupled to 5 volt and ground, with the control or the signal wire going to digital pin number 7 of the Arduino. The thermostat is coupled with one leg on 5 v And the other leg wired via a 10k resistor to ground. The pin that is connected to the resistor is also connected to the analogue pin A5 of the Arduino. The one side of the EC probe is coupled to pin A0 of the Arduino. The same pin is coupled via a 1k resistor to pin A1 of the Arduino. The second pin of the EC probe is coupled to ground. Please see the circuit below for more detail.

Code
The code for the project can be found below. the code was written for the Arduino Uno but can be used with any of the Arduino microprocessors.
You can find a more detailed description of the code in the video below this post.
// Software by Pierre Hertzog YouTube channel (AgriTech with Pierre) (2020)
// You are welcome to use my software as long as recognition is given to my YouTube channel
// Connections (Also see Video)
// One pin of EC probe to Arduino Gnd
// One pin of EC probe to 1k resistor and to pin A1 of Arduino
// Other pin of resistor to A0
// One pin of thermistor to A5 and one side of 10k resistor
// Other pin of thermistor to 5V on Arduino
// Other pin of 10k resistor to Gnd
// Relay to gnd and 5V and data line to pin D7 of Arduino
int R1= 1000; // Value of resistor for EC probe
int EC_Read = A0;
int ECPower = A1;
int Temp_pin = A5;
float Temp_C; // Do not change
float Temp_F; // Do not change
float Temp1_Value = 0;
float Temp_Coef = 0.019; // You can leave as it is
int Pump_pin = 7;
/////////////////This part needs your attention during calibration only///////////////
float Calibration_PPM =1080 ; //Change to PPM reading measured with a separate meter
float K=1.89; //You must change this constant once for your probe(see video)
float PPM_Con=0.5; //You must change this only if your meter uses a different factor
/////////////////////////////////////////////////////////////////////////////////////
float CalibrationEC= (Calibration_PPM*2)/1000;
float Temperature;
float EC;
float EC_at_25;
int ppm;
float A_to_D= 0;
float Vin= 5;
float Vdrop= 0;
float R_Water;
float Value=0;
///////////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(9600);
pinMode(EC_Read,INPUT);
pinMode(ECPower,OUTPUT);
pinMode(Pump_pin,OUTPUT);
//////////////////////////////////////////////////////////////////////////////////////////
//Calibrate (); // After calibration put two forward slashes before this line of code
//////////////////////////////////////////////////////////////////////////////////////////
}
void loop()
{
Get_EC(); //Calls GetEC()
Pump_con (); //Switch pump if necessary
delay(5000); //Do not make this less than 6 sec (6000)
}
//////////////////////////Pump//////////////////////////////////
void Pump_con ()
{
int Set_ppm = 1000; // change to your desired ppm
int Change_per_dose = 100; // determine this experimentally (see video for clarity)
int Pump_on_time = 5; // set pump dose time in seconds
int Wait_time = 4; // set time to wait between dosing
if (ppm <=(Set_ppm-Change_per_dose))
{
digitalWrite(Pump_pin,HIGH);
delay(Pump_on_time*1000);
digitalWrite(Pump_pin,LOW);
delay(Wait_time*1000);
}
}
////////////////////////////////////////////////////////////////////////////////////
void Get_EC()
{
int val;
double Temp;
val=analogRead(Temp_pin);
Temp = log(((10240000/val) – 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp);
Temp_C = Temp – 273.15; // Kelvin to Celsius
Temp_F = (Temp_C * 9.0)/ 5.0 + 32.0; // Celsius to Fahrenheit
Temp1_Value = Temp_C;
Temperature = Temp_C;
digitalWrite(ECPower,HIGH);
A_to_D= analogRead(EC_Read);
A_to_D= analogRead(EC_Read);
digitalWrite(ECPower,LOW);
Vdrop= (Vin*A_to_D) / 1024.0;
R_Water = (Vdrop*R1) / (Vin-Vdrop);
EC = 1000/ (R_Water*K);
EC_at_25 = EC / (1+ Temp_Coef*(Temperature-25.0));
ppm=(EC_at_25)*(PPM_Con*1000);
Serial.print(” EC: “);
Serial.print(EC_at_25);
Serial.print(” milliSiemens(mS/cm) “);
Serial.print(ppm);
Serial.print(” ppm “);
Serial.print(Temperature);
Serial.println(” *C “);
}
////////////////////////////////////////////////////////////////////////////////////
void Calibrate ()
{
Serial.println(“Calibration routine started”);
float Temperature_end=0;
float Temperature_begin=0;
int val;
double Temp;
val=analogRead(Temp_pin);
Temp = log(((10240000/val) – 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp);
Temp_C = Temp – 273.15; // Kelvin to Celsius
Temp_F = (Temp_C * 9.0)/ 5.0 + 32.0; // Celsius to Fahrenheit
Temp1_Value = Temp_C;
Temperature_begin=Temp_C;
Value = 0;
int i=1;
while(i<=10){
digitalWrite(ECPower,HIGH);
A_to_D= analogRead(EC_Read);
A_to_D= analogRead(EC_Read);
digitalWrite(ECPower,LOW);
Value=Value+A_to_D;
i++;
delay(6000);
};
A_to_D=(Value/10);
val=analogRead(Temp_pin);
Temp = log(((10240000/val) – 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp);
Temp_C = Temp – 273.15; // Kelvin to Celsius
Temp_F = (Temp_C * 9.0)/ 5.0 + 32.0; // Celsius to Fahrenheit
Temp1_Value = Temp_C;
Temperature_end=Temp_C;
EC =CalibrationEC*(1+(Temp_Coef*(Temperature_end-25.0)));
Vdrop= (((Vin)*(A_to_D))/1024.0);
R_Water=(Vdrop*R1)/(Vin-Vdrop);
float K_cal= 1000/(R_Water*EC);
Serial.print(“Replace K in line 23 of code with K = “);
Serial.println(K_cal);
Serial.print(“Temperature difference start to end were = “);
Temp_C=Temperature_end-Temperature_begin;
Serial.print(Temp_C);
Serial.println(“*C”);
Serial.println(“Temperature difference start to end must be smaller than 0.15*C”);
Serial.println(“”);
Calibrate ();
}
The video below contains full detail regarding the project.
I am an electronic engineer with more than 50 scientific publications. My motto is “if you can not explain it simply, then you do not understand it well enough”.
1 Comment
i want accurate results. and that sensor monitor 24/7 values is it possible please help me