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:
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:
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?
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.
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 . 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?
Thanks,
meat
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.
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.
alo alo everyone im trying to build this system but im struggling to link up the code that works with my board and lcd keypad shiel, almost all code that ive found has LED code and i have to switch out code i found for my shield from another page and swap out some of the names for values being printed ill post the code ive been working with bellow, ive tried to incorporate it to the code above to no avail. pls will someone with some experience help me get this to work
im using ph sensor controller V2.0
arduino uno
lcd keypad shield D1
with 2 6v dose pumps
/*
This sample code is used to test the pH meter V1.0.
Editor : YouYou
Ver : 1.0
Product: analog pH meter
SKU : SEN0161
*/
#define SensorPin A1 //pH meter Analog output to Arduino Analog Input 1 #define Offset -1.75 //deviation compensate #define LED 13 #define LED 13 #include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); #define samplingInterval 20 #define printInterval 800 #define ArrayLenth 40 //times of collection
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
int pHArrayIndex=0;
void setup(void)
{
pinMode(LED,OUTPUT);
lcd.begin(16, 2);
lcd.println("pH meter");
Serial.begin(9600);
Serial.println("pH meter"); //Test the serial monitor
}
void loop(void)
{
static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
static float pHValue,voltage;
if(millis()-samplingTime > samplingInterval)
{
pHArray[pHArrayIndex++]=analogRead(SensorPin);
if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
voltage = avergearray(pHArray, ArrayLenth)5.0/1024;
pHValue = 3.5voltage+Offset;
samplingTime=millis();
}
if(millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
lcd.print("Voltage:");
lcd.print(voltage,2);
lcd.print(" pH value: ");
lcd.println(pHValue,2);
digitalWrite(LED,digitalRead(LED)^1);
printTime=millis();
}
}
double avergearray(int* arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
lcd.println("Error number for the array to avraging!/n");
return 0;
}
if(number<5){ //less than 5, calculated directly statistics
for(i=0;i<number;i++){
amount+=arr*;*
}*
avg = amount/number;*
return avg;*
}else{*
if(arr[0]<arr[1]){*
min = arr[0];max=arr[1];*
}*
else{*
min=arr[1];max=arr[0];*
}*
for(i=2;i<number;i++){*
_ if(arr*<min){_
_ amount+=min; //arr<min*_ _ min=arr*; }else { if(arr>max){ amount+=max; //arr>max* max=arr*; }else{ amount+=arr; //min<=arr<=max* * } }//if* * }//for* * avg = (double)amount/(number-2); }//if* * return avg; }* this is the closest weve gotten to having a reading on the lcd with a ph and voltage output please help_