Go easy on me, its my first contribution !
One of my Grand Ideas is to build an automated hydroponics setup. The water to feed my dear veggies needs to be decent quality : temperature, pH and amaount of nutrients need to be within a specific range.
Temperature is easy. pH became easy when Phidgets released their new pH phidget, which converts the minuscule currents from an industry standard pH probe into a 0-5V signal.
But EC has proven to be another level of challenge. I decided early on that I needed the toroidal type of sensor, and these babies cost serious money, even old ones on ebay. Then, a base station that supplies the probes and converts their output into 4-20mA and/or two NO/NC switches. Such stations don't come cheap either.
Another option was to self-build, but a toroidal probe is beyond my abilities, and the circuitry not easy to figure out.
I was lucky to hit upon solumetrix in the UK, who supply an all-in-one probe with a serial output. I connected this to my mega and with some help from them managed to read the values with the arduino. There is an RX option as well to change some settings in the probe, but that is as of yet untouched (default settings work fine for me).
So, below please find my code for reading the Solumetrix BK probe with the arduino mega, should be easy enough to convert the code to an UNO or other single serial model and output via an LCD, it's the reading of the probe values that had me puzzled more.
Good luck.
byte inbyte[9]; // for incoming serial data
byte htrap[2];
int i = 0;
float temp =0;
float uc =0;
float cc =0;
int checksum = 0;
void setup() {
Serial1.begin(9600); // opens serial port, sets data rate to 9600 bps
Serial1.flush();
Serial.begin(9600);
Serial.flush();
}
void loop() {
if( Serial1.available() > 28 ) // command length is 14 bytes,
//so to be sure we have a full transmission in the cache,
//and haven't just captured the end of one message and the start of another
//we await until we are sure to have at least 1 full message
//later on, if there is a tail of a message at the start of the buffer, we fill first drop that
{
findheader(); //drop any tail of a message in the buffer, ensure we start reading from the status byte (4)
checksum = 170+85+1; //AA+55+01=170+85+1
for (int i=0; i <= 8; i++)
{
inbyte = Serial1.read();
- //delay(10);*
_ if (i < 8) checksum+=inbyte*;//the other 8 bytes for the checksum*_
* }*
* checksum = 256 - (checksum%256);*
* if (checksum != inbyte[8])*
* {*
* Serial.println("Failed Checksum");*
* }*
* else*
* {*
_ temp = (inbyte[2]+inbyte[3]256)/10;
uc = float(inbyte[4]+inbyte[5]256)/1000;
cc = float(inbyte[6]+inbyte[7]256)/1000;_
_ Serial.println("I received: ");_
_ Serial.println(inbyte[0], HEX); //status*_
* //Serial.print(inbyte[1], HEX); //version*
* //Serial.print(inbyte[2], HEX); //01 - type*
* //Serial.print(inbyte[3], HEX); //02 - continuous*
* //Serial.println(inbyte[4], HEX); //3F - version 6.3*
* //Serial.print(inbyte[5], HEX); //temp low*
* //Serial.println(inbyte[6], HEX); // temp high*
* Serial.print("temp \t");*
* Serial.println(temp);*
* //Serial.print(inbyte[7], HEX); //uc low*
* //Serial.println(inbyte[8], HEX); //uc high*
* Serial.print("uc \t");*
* Serial.println(uc);*
* //Serial.print(inbyte[9], HEX); //cc low*
* //Serial.println(inbyte[10], HEX); //cc high*
* Serial.print("cc \t");*
* Serial.println(cc);*
* //Serial.print(inbyte[11], DEC); //checksum*
* //Serial.print("\t");*
* //Serial.println(checksum);*
* //Serial.print(inbyte[12], HEX); //55*
* //Serial.println(inbyte[13], HEX); //AA*
* delay(4000);*
* Serial1.flush();*
* //inbyte[0]= 0;*
* //inbyte[1]= 0;*
* }*
* }*
}
void findheader(){ //
* while(1)*
* {*
* htrap[0] = Serial1.read();*
* if (htrap[0] == 170) //header or footer AAh = 170*
* {*
* htrap[1] = Serial1.read();*
* if (htrap[1] == 85) //can only be header 55h = 85*
* {*
* Serial1.read(); // flush the fixed "01" indicating probe type*
* //Serial.println("OK");*
* break;*
* }*
* }*
* else*
* {*
* //Serial1.read();*
* //Serial.print(htrap[0],HEX);*
* }*
* }*
}
To connect the probe, I put 12V on the red and black wires (it handles 10 to 24), connected the black wire to the arduino gnd as well, and then connected the orange wire to the megas pin 19 (serial1 RX).
To test, just put a little wire loop with a 1k ohm resistor through the probes hole and around the outside. The value should be 4.550mS. Mine reads 4.61, I guess that's resistor error...