Go Down

Topic: pH measurement with pump activation (Read 1 time) previous topic - next topic



I am new to using Arduino (I'll be honest I did not know it existed until a couple weeks ago) and I am a research student looking at using it for measuring and controlling pH in a reactor. When the pH drops below 7.5 I am after a pump to turn on until the value is greater than 7.5 again. I am using:

1) An Arduino Uno board.
2) An Atlas Scientific Arduino Rapid Development Shield (http://www.atlas-scientific.com/product_pages/components/arduino.html)
3) An EZO pH circuit microcomputer (http://www.atlas-scientific.com/product_pages/circuits/ezo_ph.html)
4) A pH probe.

The micro computer comes with sample code which is what I am using as a basis of the code for the probe but it is beyond my understanding of Arduino code. I have watched various tutorial videos so can do the standard 'getting LEDs to flash' etc but this code is too advanced for me. My code is below of which it is basically the same as the sample code (this version is anyway) as I tried various versions and altered it but with no success.

I get a reading from the probe and I calibrated it fine, the issue is it displays OK after every reading which I need to not be present I think? Unless I can still get it to work with a pump to dose when the pH is less than 7.5? So my question is how can I remove the OK check from the serial monitor? Or if i don't need to then how do I go about creating code to have a pump dose if the pH is less than 7.5? I am very inexperienced in coding. I did a search and looked at the two forums below:


Kind Regards,


EDIT: Ok after speaking with my supervisor, as I have managed to get the code to give a reading all that is needed now is to have that 'low' signal turn on a pump to dose for pH correction. But I do not know how to write code to turn on  a pump to dose when the signal displays a pH less than 7.5. Defining what the pump would be in the code would be where I would start from maybe?

Kind Regards,


From a coding perspective there may be little to nothing to do - it depends on the type and power consumption of the pump motor. To run a brushed DC motor for example, all you need do is provide it power and the arduino needs to switch that power on & off via external hardware - perhaps a transistor or relay.

In that scenario, digitalWrite may be all you need in the sketch; wiring up the hardware is another matter - you can find examples in the playground.


Mar 17, 2015, 07:46 pm Last Edit: Mar 17, 2015, 08:57 pm by themeatcleaver3
Ok thank you! I have looked at the digitalWrite command and have managed to get some coding that seems to be able to work. The issue is the hardware now though, as I have the Atlas Rapid Development Board on top of the Arduino Uno it uses all the pins so I will have to wire the pump to one of the rapid development shield's ports but can't find anywhere saying which would be suitable. Any suggestions would be helpful please  :D . I can't just wire it to the 13 pin for example as those are taken up by the Atlas Shield board on top :/

Also if the above is not possible as it seems it would just short the pH measurement of the micro computer and shield, what additional hardware would be required?

EDIT: I now understand relays so I have to use a relay with a 12V power supply and have Arduino turn it on and off depending on the pH?



Ok so I got this code to work and used the LED on pin 13 to test it to see if it would send a signal to an array when connected as I don't have a 12V array yet. The only issue is that the OK check is causing problems with the signal so I need to get rid of it but I do not know how whilst still being able to get a pH reading? Is anyone able to help with this? When the pH is high I want the signal to be low but when an OK is read it activates the signal as I am guessing it just reads the OK as a value of 0 which is less than 7.5?

Basically I am after removing the OK check from the code so the signal that would be sent to the relay would be constant depending on the pH value. I have tried the simple code that was suggested on teh other threads but do not get a value.

Kind Regards,



Code: [Select]
    if (ph < 7.500 && ph > 0.0)



I have altered the code to be able to keep the pH within a desired range for most plants, but both pumps seem to always be running no matter the pH reading. Also the serial monitor does not display anything despite changing the Arduino_only var as stated in the sketch. My PH EZO circuit is set to UART mode because I assume that is what this sketch calls for and change to channel 0, but still have nothing on the serial monitor as well.


The attached code as it should have been posted.

Code: [Select]

//This code has intentionally has been written to be overly lengthy and includes unnecessary steps.
//Many parts of this code can be truncated. This code was written to be easy to understand.
//Code efficiency was not considered. Modify this code as you see fit.   
//This code will output data to the Arduino serial monitor. Type commands into the Arduino serial monitor to control the pH circuit.
//set the var Arduino_only to equal 1 to watch the Arduino take over control of the pH circuit.

//As of 11/6/14 the default baud rate has changed to 9600.
//The old defaul baud rate was 38400

#include <SoftwareSerial.h>      //we have to include the SoftwareSerial library, or else we can't use it. 
#define rxph 2                     //define what pin rx is going to be.
#define txph 3                     //define what pin Tx is going to be.

SoftwareSerial probe(rxph, txph); //define how the soft serial port is going to work.

char ph_data[20];                  //we make a 20 byte character array to hold incoming data from the pH.
char computerdata[20];             //we make a 20 byte character array to hold incoming data from a pc/mac/other.
byte received_from_computer=0;     //we need to know how many characters have been received.                                 
byte received_from_sensor=0;       //we need to know how many characters have been received.
byte arduino_only=0;               //if you would like to operate the pH Circuit with the Arduino only and not use the serial monitor to send it commands set this to 1. The data will still come out on the serial monitor, so you can see it working. 
byte startup=0;                    //used to make sure the Arduino takes over control of the pH Circuit properly.
float ph=0;                        //used to hold a floating point number that is the pH.
byte string_received=0;            //used to identify when we have received a string from the pH circuit.
int outPin13 = 13;                  // Peristaltic Pump UP
int outPin12 = 12;                  // Peristaltic Pump DOWN

void setup(){
     Serial.begin(9600);          //enable the hardware serial port
      pinMode(outPin12, OUTPUT);     //enable the software serial port for Pin 12
      pinMode(outPin13, OUTPUT);     //enable the software serial port for Pin 13
 void serialEvent(){               //this interrupt will trigger when the data coming from the serial monitor(pc/mac/other) is received.   
        if(arduino_only!=1){       //if Arduino_only does not equal 1 this function will be bypassed. 
           received_from_computer=Serial.readBytesUntil(13,computerdata,20); //we read the data sent from the serial monitor(pc/mac/other) until we see a <CR>. We also count how many characters have been received.     
           computerdata[received_from_computer]=0; //we add a 0 to the spot in the array just after the last character we received.. This will stop us from transmitting incorrect data that may have been left in the buffer.
           probe.print(computerdata);           //we transmit the data received from the serial monitor(pc/mac/other) through the soft serial port to the pH Circuit.
           probe.print('\r');                   //all data sent to the pH Circuit must end with a <CR>. 

void loop(){
  if(probe.available() > 0){        //if we see that the pH Circuit has sent a character.
     received_from_sensor=probe.readBytesUntil(13,ph_data,20); //we read the data sent from pH Circuit until we see a <CR>. We also count how many character have been received. 
     ph_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer.
     string_received=1;                //a flag used when the Arduino is controlling the pH Circuit to let us know that a complete string has been received.
     Serial.print(ph_data);          //lets transmit that data received from the pH Circuit to the serial monitor.
  if(arduino_only==1){Arduino_Control();} //If the var arduino_only is set to one we will call this function. Letting the Arduino take over control of the pH Circuit 
void Arduino_Control(){
      if(startup=0){                //if the Arduino just booted up, we need to set some things up first.   
          probe.print("c,0\r");   //take the pH Circuit out of continues mode.
          delay(50);                 //on start up sometimes the first command is missed.
          probe.print("c,0\r");   //so, let’s send it twice.
          delay(50);                 //a short delay after the pH Circuit was taken out of continues mode is used to make sure we don’t over load it with commands.
          startup=1;                 //startup is completed, let's not do this again during normal operation.
  delay(1000);                         //we will take a reading ever 1000ms. You can make this much longer or shorter if you like.
   probe.print("R\r");             //send it the command to take a single reading.
   if(string_received==1){            //did we get data back from the ph Circuit?
     if(ph > 6.200){digitalWrite(outPin12,HIGH);}               // If pH is above 6.2, actuate pH Down Pump
     else if(ph < 5.500){digitalWrite(outPin13,HIGH);}               // If pH is below 5.5, actuate pH Up Pump
     else if(ph < 6.200 && ph > 5.500){digitalWrite(outPin13,LOW);}    // If pH is in optimal range for most plants, do not actuate pH Up
     else if(ph < 6.200 && ph > 5.500){digitalWrite(outPin12,LOW);}    // If pH is in optimal range for most plants, do not actuate pH Up
     string_received=0;}            //reset the string received flag.



//here are some functions you might find useful
//these functions are not enabled

void cal_s(){                        //calibrate to a pH of 7
  probe.print("cal,mid,7\r");}    //send the "cal,mid,7" command to calibrate to a pH of 7.00

void cal_f(){                       //calibrate to a pH of 4
  probe.print("cal,low,4\r");}     //send the "cal,low,4" command to calibrate to a pH of 4.00

void cal_t(){                      //calibrate to a pH of 10.00
  probe.print("cal,high,10\r");}  //send the "cal,high,10" command to calibrate to a pH of 10.00 

void phFactoryDefault(){           //factory defaults the pH circuit
  probe.print("X\r");}          //send the "X" command to factory reset the device

void read_info(){                  //get device info
    probe.print("I\r");}        //send the "I" command to query the information

void phSetLEDs(byte enabled)      //turn the LEDs on or off
  if(enabled)                     //if enabled is > 0
    probe.print("L,1\r");      //the LED's will turn ON
  else                            //if enabled is 0       
    probe.print("L,0\r");      //the LED's will turn OFF

If at first you don't succeed, up - home - sudo - enter.

Go Up