VernierST / arduino

Project sketches using Vernier Sensors with Arduino. The Vernier Library is used where appropriate. Please see VernierLib for additional sketches.
https://www.vernier.com/arduino
Other
28 stars 21 forks source link

Sketch to display and graph readings to LabVIEW from 2 analog sensors #3

Closed YukiSakuma closed 8 years ago

YukiSakuma commented 8 years ago

Hello, I have 4 analog sensors namely, stainless steel temp, DO probe, pH probe and Ammonium Ion-Selective Electrode. I have two sparkfun arduino board. Now since the vernier interface shield has only two analog inputs I have two of them in order to connect all 4 sensors. So what I need is the sketch and possibly the VI to display each table and graph readings from these sensors. Any help is appreciated thanks.

YukiSakuma commented 8 years ago

I was able to use the thermistor.ino code for stainless steel temp probe and display the readings to LabVIEW using this VI:http://forums.ni.com/ni/attachments/ni/170/741210/2/read_serie_monitor.vi This was then I realized that I need the "actual" code for each probes just like the thermistor.ino for the stainless temp probe. I used the AnalogAutoID to identify the sensors but I need the "actual" code or the one with calculations in it because I will use the readings of each probes to control a solenoid valve for example. I am using the 4 sensors in a giant aquarium with Tilapia fish in it.

Smythics commented 8 years ago

Hi Yuki, Sounds like a great project! I need to warn you about a couple of things. You are likely to run into some interference between pH and the Ammonium ISE when testing the same body of water. You might be able to get away from this by having them at opposite ends of the tank, but more likely you will need to pull a sample to test one or the other. The DO may also experience some interaction with the ISE but it is not as sensitive. Since you are already using two Arduino's that may work to your benefit. Put the ISE and the temperature on one end, pH and DO on the other. No guarantees, but... If you want a custom code for the particular sensors you are using look at the sketch named VernierAnalogSensor.ino and modify it for the pH and DO sensors which have a linear calibration. You will need to look up the slope and intercept values in the sensor booklets for these sensors: http://www.vernier.com/support/manuals/ The ISE is a different animal altogether. The ISE voltage output is not linear with respect to the ion concentration, but rather is modeled by the Nernst Equation. In order to determine the concentration the mV response must be entered into the Nernst equation: E = Eo + m(ln C) The trick with the ISEs and the Nernst equation is that the values Eo and m change as the membrane slowly deteriorates. Every 2 weeks or so the membrane has changed enough to require a new calibration. To determine the values of Eo and m, use 2 known concentration solutions. Record the voltage output of the ISE in each known solution and use then to solve for Eo and m. You can only expect these values to remain valid for a short period of time (a week or two) and then you will need to do this again. Be sure to update these values in your Arduino sketch. I have a sample sketch for the ISE that I will provide outside of this forum.

Smythics commented 8 years ago

VernierBNC (2).zip Here is the code for the ISE. Take a look and let me know if you have questions.

YukiSakuma commented 8 years ago

Thanks for the detailed response but I think I found a way to use the AnalogAutoID to output a specific channel (I want to output the channels without using a for loop), like the statement of the for loop for reading Channels 1 to 2, I removed them and replaced something like in void loop

/*
VernierAnalogAutoID (v 2015.04)
Reads the information to AutoID a Vernier BTA sensor with digital AutoID,
and resistor ID sensors including Vernier Stainless Steel Temperature Probe (TMP-BTA). 
It should read the +/-10 volt Voltage Probe correctly also.
This version does all tests for resistorID sensors first, then
turns on the I2C clock and tests for digital autoID sensors. After that,
it turns off the I2C communications.
Note that this sketch handles multiple pages of sensor calibrations.
When used with the SparkFun Vernier Interface Shield, this program will AutoID
two different sensors on BTA1 and BTA2. With homemade, breadboard
connections, it will work with only one sensor.
After the AutoID:
Assuming Vernier analog (BTA) Sensors are connected to the BTA connectors,
this sketch displays the time and sensor readings on the Serial Monitor.
As written, the readings will be displayed every second. 
Change the variable TimeBetweenReadings to change the rate.
The changes in the 2015.04 version are:
  - fixed bug which lead to incorrect readings of analog sensors in BTA2 
    connector because I2C lines affected the readings
  - minor changes to the voltage thresholds on resistor ID section

 See www.vernier.com/arduino for more information.
*/

int ReadingNumber;
int Channel; //BTA (Channel 1 or 2) 
float VoltageID[5];
int led =13;
int SensorNumber[5]; //integer indicating sensor number'
String Name[5];
String ShortName[5];
String Units[5];
float Intercept[5];
float Slope[5];
int Page[5];
int (CalEquationType[5]);
float VCC= 5.00;// "5 volt" power supply voltage used in resistor ID section

/////////////////////////////////////////
int TimeBetweenReadings = 1000; // in ms
////////////////////////////////////////
#include <Wire.h>
byte sensordata [128];
int device=0x50;
byte floatbyte[5];

void setup()
 {
    int muxlsb = 10; //low byte of multiplexer
    int muxmsb = 11; //high byte of multiplexer
    Serial.begin(9600);
    pinMode(led, OUTPUT); //LED on SparkFun Vernier Shield
    digitalWrite(led, LOW);   
    pinMode(muxlsb, OUTPUT); 
    pinMode(muxmsb, OUTPUT); 

//    Serial.println(""); 
    //Read BTA1 Sensor
    digitalWrite(muxlsb, LOW); //set multiplexer for BTA1   
    digitalWrite(muxmsb, LOW);    
    Channel=1;
    BTAResistorSensorID(Channel);
    //Read BTA2 Sensor
    digitalWrite(muxlsb, HIGH); //set multiplexer for BTA2   
    digitalWrite(muxmsb, LOW);  
    Channel=2;  
    BTAResistorSensorID(Channel); 
    Wire.begin(); //start I2C communication
    //Read BTA1 Sensor
    digitalWrite(muxlsb, LOW); //set multiplexer for BTA1   
    digitalWrite(muxmsb, LOW);    
    Channel=1;
    if (SensorNumber[Channel]==0) DigitalSensorID( Channel);// if no resistorID, check for digital ID
    PrintSensorInfo();// this line can be commented out if you do not need all this info!!!
    //Read BTA2 Sensor
    digitalWrite(muxlsb, HIGH); //set multiplexer for BTA2   
    digitalWrite(muxmsb, LOW);  
    Channel=2;  
    if (SensorNumber[Channel]==0) DigitalSensorID( Channel);// if no resistorID, check for digital ID
    pinMode(A4, INPUT); //Turn off the I2C communication
    pinMode(A5, INPUT); 
    PrintSensorInfo();// this line can be commented out if you do not need all this info!!!
//    Serial.println(" ");    
//    Serial.println("Vernier Format 2");
//    Serial.println("Readings taken using Ardunio");
//    Serial.println("Data Set");
//    Serial.print("Time");

    for (Channel=1;Channel<3;Channel++) //2 was 3
     { 
//       Serial.print("\t"); //tab character
       //print sensor name:
//       Serial.print (ShortName[Channel]); 
     } 
//    Serial.println("");      
//    Serial.print("seconds");
    for (Channel=1;Channel<2;Channel++) // 2 was 5
     { 
//       Serial.print("\t"); //tab character
       //print sensor name:
//       Serial.print (Units[Channel]);
     } 
//    Serial.println ("");
  }

void loop()
 {
    int Count[3]; //reading from 0 to 5 volt input
    int AltCount[3] ;//reading from -10 to +10V input
    float Voltage[3];
    float SensorReading[3];

    float Time;
    digitalWrite(led, HIGH); //turn on LED
//    Serial.print(ReadingNumber/1000.0*TimeBetweenReadings); 
    int Channel=1;
    int Channel2=2;
    //2 was 3
      {
//        Serial.print("\t"); //tab character
        if (Name[Channel]=="Voltage +/- 10V")
          {
             AltCount[1] = analogRead(A1); //read both +/- 110 volt lines
//             AltCount[2] = analogRead(A3);
              // convert from count to raw voltage if using 10 volt range:
              Voltage[Channel] = AltCount[Channel] / 1024.0 * 5.0 ;          
           }
          else
            {        
              Count[1] = analogRead(A0); //read both analog lines
//              Count[2] = analogRead(A2);
              // convert from count to raw voltage on 0 to 5 range:
              Voltage[Channel] = Count[Channel] / 1024.0 * 5.0; 
            }
           SensorReading[Channel]= Intercept[Channel] + Voltage[Channel] * Slope[Channel];
            if (Name[Channel2]=="Voltage +/- 10V")
          {
//             AltCount[1] = analogRead(A1); //read both +/- 110 volt lines
             AltCount[2] = analogRead(A3);
              // convert from count to raw voltage if using 10 volt range:
              Voltage[Channel2] = AltCount[Channel2] / 1024.0 * 5.0 ;         
           }
          else
            {        
//              Count[1] = analogRead(A0); //read both analog lines
                Count[2] = analogRead(A2);
              // convert from count to raw voltage on 0 to 5 range:
              Voltage[Channel2] = Count[Channel2] / 1024.0 * 5.0; 
            }
            SensorReading[Channel2]= Intercept[Channel2] + Voltage[Channel2] * Slope[Channel2];
     //special calibration for thermistor temperture probe:
     if (SensorNumber[Channel]==10) SensorReading[Channel]=Thermistor(Count[Channel]);
     if (SensorNumber[Channel2]==10) SensorReading[Channel]=Thermistor(Count[Channel2]);
     float avalue=SensorReading[Channel];
     float bvalue=SensorReading[Channel2];
    Serial.print("a");
    Serial.println(avalue);
    delay(50);
    Serial.print("b");
    Serial.println(bvalue);
    delay(50);
//       Serial.print("c");
//    Serial.println(bvalue);
//    delay(50);
//       Serial.print("d");
//    Serial.println(bvalue);
//    delay(50);
//     Serial.print(SensorReading[Channel]);  
//     Serial.print("\t");
//    Serial.print(SensorReading[2]);  

      //if (Channel==1)
      //{Serial.print("hello");}
    //  else 
  //    {Serial.print("mofo");}
    } // end of going through the channels

  Serial.println(" "); 
  delay(TimeBetweenReadings/2);// delay half of period
  digitalWrite(led, LOW);// LED on D13 flashes once per readng
  delay(TimeBetweenReadings/2);// delay the other half
  ReadingNumber++;
  } // end

void BTAResistorSensorID(int Channel)
 {
  Name[Channel]="";// clear name string
  ShortName[Channel]="";// clear name string
  SensorNumber[Channel] = 0;
  delay (10);
  int CountID = analogRead(A5);
  VoltageID[Channel] = CountID / 1024.0 * VCC;// convert from count to voltage 
  if (VoltageID[Channel]>0.86 & VoltageID[Channel]<0.95) SensorNumber[Channel] = 1; //Thermocouple
  if (VoltageID[Channel]>3.83 & VoltageID[Channel]<3.86) SensorNumber[Channel] = 2; // Voltage +/-10 V
  if (VoltageID[Channel]>1.92 & VoltageID[Channel]<2.13) SensorNumber[Channel] = 3; // TI Current Probe (not used)
  if (VoltageID[Channel]>1.18 & VoltageID[Channel]<1.30) SensorNumber[Channel] = 4; //Reistance 
  if (VoltageID[Channel]>3.27 & VoltageID[Channel]<3.68) SensorNumber[Channel] = 5; //Extra-Long Temperature Probe  
  if (VoltageID[Channel]>4.64 & VoltageID[Channel]<4.73) SensorNumber[Channel] = 8; //Differential Voltage
  if (VoltageID[Channel]>4.73 & VoltageID[Channel]<4.83) SensorNumber[Channel] = 9; //Current
  if (VoltageID[Channel]>2.38 & VoltageID[Channel]<2.63) SensorNumber[Channel] = 10; //Stainless Steel or Surface Temperature Probe
  if (VoltageID[Channel]>2.85 & VoltageID[Channel]<3.15) SensorNumber[Channel] = 11; // Voltage 30 V  
  if (VoltageID[Channel]>1.52 & VoltageID[Channel]<1.68) SensorNumber[Channel] = 12; //TILT, TI Light Sensor
  if (VoltageID[Channel]>0.43 & VoltageID[Channel]<0.48) SensorNumber[Channel] = 13; //Exercise Heart Rate
  if (VoltageID[Channel]>4.08 & VoltageID[Channel]<4.16) SensorNumber[Channel] = 14; //Raw Voltage
  if (VoltageID[Channel]>0.62 & VoltageID[Channel]<0.68) SensorNumber[Channel] = 15; //EKG
  if (VoltageID[Channel]>4.32 & VoltageID[Channel]<4.40) SensorNumber[Channel] = 17; //CO2 
  if (VoltageID[Channel]>4.50 & VoltageID[Channel]<4.59) SensorNumber[Channel] = 18; //Oxygen
  switch (SensorNumber[Channel]) 
   {
      case 1:
            Name[Channel] = "Thermocouple" ;  
            Units[Channel] = "Deg C " ;  
            ShortName[Channel] = "TC";
            Slope[Channel]=-2.45455;
            Intercept[Channel]=6.2115;
            Page[Channel] = 1;; //calibration storage p (1,2, or 3)
            CalEquationType[Channel]=1;
       break;
       case 2:
            Name[Channel] = "Voltage +/- 10V" ;  //!!! do not change this name or you will mess up the code of the loop
            Units[Channel] = "V" ;  
            ShortName[Channel] = "Voltage10";
            Slope[Channel]=4;//note correction for Sparkfun circuit done in calculation of Voltage!!
            Intercept[Channel]=-10;
            Page[Channel] = 1;; //calibration storage page 
            CalEquationType[Channel]=1;
      break;
      case 3:
            Name[Channel] = "Current" ;  
            Units[Channel] = "Amps" ;  
            ShortName[Channel] = "Current";
            Slope[Channel]=-2.665;
            Intercept[Channel]=6.325;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
      break;
      case 4:
            Name[Channel] = "Reistance" ;  
            Units[Channel] = "Ohms" ;  
            ShortName[Channel] = "Diff V";
            Slope[Channel]=-2.5;
            Intercept[Channel]=6.25;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
      break;
      case 8:
            Name[Channel] = "Diff Voltage" ;  
            Units[Channel] = "V" ;  
            ShortName[Channel] = "Diff V";
            Slope[Channel]=-2.5;
            Intercept[Channel]=6.25;
            Page[Channel] = 1;; //calibration storage page 
            CalEquationType[Channel]=1;
      break;
      case 9:
            Name[Channel] = "Current" ;  
            Units[Channel] = "Amp" ;  
            ShortName[Channel] = "I";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
      break;
      case 10:
            Name[Channel] = "Temperature" ;  
            Units[Channel] = "Deg C" ;  
            ShortName[Channel] = "Temp";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
       break;
       case 11:
            Name[Channel] = "Temperature" ;  
            Units[Channel] = "Deg C" ;  
            ShortName[Channel] = "Temp";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
        break;
        case 12:
            Name[Channel] = "TI Light" ;  
            Units[Channel] = "relative" ;  
            ShortName[Channel] = "TI Light";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
         break;
         case 13:
            Name[Channel] = "Exercise Heart Rate" ;  
            Units[Channel] = "V" ;  
            ShortName[Channel] = "Ex HR";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
         break;
         case 14:
            Name[Channel] = "Voltage" ;  
            Units[Channel] = "V" ;  
            ShortName[Channel] = "Volts";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
         break;
         case 15:
            Name[Channel] = "EKG" ;  
            Units[Channel] = "V" ;  
            ShortName[Channel] = "EKG";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
         break;
         case 17:
            Name[Channel] = "Carbon Dioxide" ;  
            Units[Channel] = "ppm" ;  
            ShortName[Channel] = "CO2";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
         break;
         case 18:
            Name[Channel] = "Oxygen" ;  
            Units[Channel] = "%" ;  
            ShortName[Channel] = "O2";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
         break;
       default: 
            Name[Channel] = "nothing on BTA" ;  
            SensorNumber[Channel] = 0; //
            Units[Channel] = "" ;  
            ShortName[Channel] = "";
            Slope[Channel]=1;
            Intercept[Channel]=0;
            Page[Channel] = 1;; //calibration storage page
            CalEquationType[Channel]=1;
         break;
   } // end of switch case
  } //end of BTA resistor check
  void DigitalSensorID(int Channel)
    { 
      int i;
      int x;
        // check for digital ID sensor:
        for (i=0; i<133; i++)  // clear our digital ID sensor data
         { 
           sensordata[i]=0; 
         } 
       //Now check for Digital AutoID sensor:
      Wire.begin(); // join i2c bus (address optional for master) !!!
      //Reading device first time... ;
      Wire.beginTransmission(device); // Now we're going to read it back
      Wire.write(0x0);               // Sending address 0, so it knows where we'll want
      Wire.endTransmission();       // to read from
      x =Wire.requestFrom(device,32);    // Start new transmission and keep reading for 128 bytes
      i=1;
      while(x>1)    
        {  
          x=Wire.available();
           byte a = Wire.read();    // Read a byte and write it out to the Serial port
           sensordata [i]=a;
           i++;  
         } 
      //Reading device second time... ;
      Wire.beginTransmission(device); // Now we're going to read it back
      Wire.write(0x20);               // Sending address 0, so it knows where we'll want
      Wire.endTransmission();       // to read from
      x =Wire.requestFrom(device,32);    // Start new transmission and keep reading for 128 bytes
      i=1;
      while(x>1)    
       {  
         x=Wire.available();
         byte c = Wire.read();    // Read a byte and write it out to the Serial port
         sensordata [i+32]=c;
         i++;  
        }  
       //Reading device third time... ;
       Wire.beginTransmission(device); // Now we're going to read it back
       Wire.write(0x40);               // Sending address 0, so it knows where we'll want
       Wire.endTransmission();       // to read from
       x =Wire.requestFrom(device,32);    // Start new transmission and keep reading for 128 bytes
       i=1;
       while(x>1)    
        {  
          x=Wire.available();
          byte c = Wire.read();    // Read a byte and write it out to the Serial port
          sensordata [i+64]=c;
          i++;  
         }      
       //Reading device a forth time... ;
       Wire.beginTransmission(device); // Now we're going to read it back
       Wire.write(0x60);               // Sending address 0, so it knows where we'll want
       Wire.endTransmission();       // to read from
       x =Wire.requestFrom(device,32);    // Start new transmission and keep reading for 128 bytes
       i=1;
       while(x>1)    
        {  
          x=Wire.available();
          byte c = Wire.read();    // Read a byte and write it out to the Serial port
          sensordata [i+96]=c;
          i++;  
        }      
      /*Print out array:  // remove *'s to get this display for diagnostics
      Serial.print("array: ");  
      for (i = 68; i<121;i++)
       {
         Serial.print (i);
         Serial.print (" ");
         Serial.print(sensordata[i]);  
         Serial.print (" ");
         Serial.println(char(sensordata[i])); 
        }
       */
         //******************************************************************
          //Determine sensor number:  
         //  VoltageID[Channel]=-1;// indicated resistor ID not used
        SensorNumber[Channel] =sensordata[2];  

        //Determine the sensor name:    
        Name[Channel]="";
        for (i = 0; i<20;i++)
         {
           char c =  sensordata[i+9]; 
           Name[Channel] += c;
         }
        Name[Channel] += '\0';    //add terminating character

        //Determine the short name:  
         ShortName[Channel]="";
         for (i = 0; i<12;i++)
         {
           char c =  sensordata[i+28]; 
           ShortName[Channel] += c;
         }
        ShortName[Channel] += '\0';    //add terminating character

        //Determine the calibration equation type:  
        CalEquationType[Channel]=sensordata[57]; 

        //Determines the  calibration page:  
        Page[Channel]= sensordata[70];  

        // the code below uses the calibration page set:
        // Intercept starts at 71 for page 1, 90 for p2, and 109 for p3

        //Determines intercept:   
        for (i = 0; i<4;i++)
          {
            floatbyte[i]=sensordata[i+71+(Page[Channel])*19];
          }
         float j = *(float*) &floatbyte;  
         Intercept[Channel] =j;

         //Determines slope:
         // slope starts at 75 for page 1, 94 for p2, and 113 for p3
         for (i = 0; i<4;i++)
          {
            floatbyte[i]=sensordata[i+75+(Page[Channel])*19];
          }  
         float y = *(float*) &floatbyte;  
         Slope[Channel] =y;

         //Determines the units:  
         // the cryptic code in the next line just uses the
         //correct bytes, depending on the page selected.
         // units start at 83 for page 1, 102 for p2, and 121 for p3
         for (i= 0; i<7;i++)
           {
            char c =  sensordata[83+i+(Page[Channel])*19]; 
             Units[Channel] += c;
           }
         Units[Channel] += '\0';    //add terminating character
     } //end of checking for digital ID sensor

void PrintSensorInfo()
 {// print out information about sensor:
  //(This code is commented out, but add it for more feedback)
//   Serial.println(" "); 
//   Serial.print("BTA Connector ");
//   Serial.println(Channel);
//   Serial.print("sensor ID number: "); 
//   Serial.println(SensorNumber[Channel]);
//   Serial.print("ID voltage level: "); 
//   Serial.println(VoltageID[Channel]);
//   Serial.print("sensor name: ");  
//   Serial.println (Name[Channel]);
//   Serial.print("sensor short name: ");  
//   Serial.println (ShortName[Channel]); 
//   Serial.print("calibration page: ");  
//   Serial.println(Page[Channel]);
//   Serial.print("calibration equation type: ");  
//   Serial.println(CalEquationType[Channel]);
//   Serial.print("intercept: ");
//   Serial.println (Intercept[Channel]);
//   Serial.print("slope ");
//   Serial. println(Slope[Channel]); 
//   Serial.print("units: ");  
//   Serial.println (Units[Channel]);
   }// end of PrintSensorInfo

   float Thermistor(int Raw) //This function calculates temperature from ADC count
{
 /* Inputs ADC count from Thermistor and outputs Temperature in Celsius
 *  requires: include <math.h>
 * There is a huge amount of information on the web about using thermistors with the Arduino.
 * Here we are concerned about using the Vernier Stainless Steel Temperature Probe TMP-BTA and the 
 * Vernier Surface Temperature Probe STS-BTA, but the general principles are easy to extend to other
 * thermistors.
 * This version utilizes the Steinhart-Hart Thermistor Equation:
 *    Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]3}
 *   for the themistor in the Vernier TMP-BTA probe:
 *    A =0.00102119 , B = 0.000222468 and C = 1.33342E-7
 *    Using these values should get agreement within 1 degree C to the same probe used with one
 *    of the Vernier interfaces
 * 
 * Schematic:
 *   [Ground] -- [thermistor] -------- | -- [15,000 ohm bridge resistor] --[Vcc (5v)]
 *                                     |
 *                                Analog Pin 0
 *
 For the circuit above:
 * Resistance = ( Count*RawADC /(1024-Count))
  */
 long Resistance; 
 float Resistor = 15000; //bridge resistor
// the measured resistance of your particular bridge resistor in
//the Vernier BTA-ELV this is a precision 15K resisitor 
  float Temp;  // Dual-Purpose variable to save space.
  Resistance=( Resistor*Raw /(1024-Raw)); 
  Temp = log(Resistance); // Saving the Log(resistance) so not to calculate  it 4 times later
  Temp = 1 / (0.00102119 + (0.000222468 * Temp) + (0.000000133342 * Temp * Temp * Temp));
  Temp = Temp - 273.15;  // Convert Kelvin to Celsius                      
  return Temp;                                      // Return the Temperature
}

then I specifically plug my temperature probe to channel 1 and dissolve oxygen in channel 2 then I serial print and I was able to output readings from multiple sensors into LabVIEW and graph its reading versus time. But then I discovered that channel 2 reading is wrong only channel 1 reading is right

Is re-calibration not needed on all of my four sensors when using AnalogAutoID?

I have a follow up question can I use the Digital 1 and 2 of the interface shield as an output to control like opening a solenoid valve without using your DCU product any guide on how to do that?

My plan is let's say

if ( SensorReading[Channel]>threshold) //temp probe, threshold=30

digitalWrite(Digitalpin1, HIGH); // output 5 volts to a relay driver that would activate the solenoid valve

YukiSakuma commented 8 years ago

Ok I think I might have fixed the reading for channel 2 in the void loop this is what I did let me know if this is correct Link: https://github.com/YukiSakuma/arduino/blob/YukiSakuma-patch-1/VernierAnalogAutoID/VernierAnalogAutoID.ino

I referenced this link below in order to view the readings from multiple sensors to LabVIEW from this : http://forum.arduino.cc/index.php?topic=83008.msg624557#msg624557 and this is my very slight modification of the VI that I am using to read measurements from multiple sensors to LabVIEW: http://www.mediafire.com/download/uutvftezcqhkpia/Sensor-Display-with-multiple-sensors-with_while_loop_-modified.zip (I can't attach the file even when using zip format) I tested the VernierBNC custom sketch for the Ammonium probe and it shows an "ovf" or stack overflow value while when using the AnalogAutoID it shows a value average of at least 1.00 mg/L but I have to note that I tested the probe with it's storage bottle still locked to the probe and not actually putting it in the water... Please still answer my questions above this post :)

Smythics commented 8 years ago

Sorry for the delay in response. Was out for a bit and still catching up.

DO, pH and ammonium ion will likely require routine calibration. Please note that these sensors are designed for education purposes and are not intended for prolonged use.

Your project is pretty unique. Can you restate any remaining questions for me.

YukiSakuma commented 8 years ago

Yes the project is all about creating a balanced environment for Tilapia growth (starting from fry or fingerling) by maintaining safe levels of pH, temp, DO and Ammonium (supposedly Ammonia) using solenoid valves that activate where certain measurement of a sensor reaches a threshold and creating an organized data log of each sensors . I do plan to have 3 trials where each trial is approximately 1 month each, every new trial always start from fry or fingerlings. I plan to use these sensors for long term monitoring (i.e. 1 month each) though but as you said I might recalibrate it every week during the experiment/trial month... The tank size is 30x54x40 inches Will try to formulate questions later thanks.

YukiSakuma commented 8 years ago

Hello it's been a while the project got a little delayed but let's not bother with that. I now have the Tilapia fingerlings in the aquarium tank but before I could start the long term experiment I need to fix some concerns and issues.

My concern is about the Ammonium ISE calibration, I am using the Vernier BNC sketch you provided and it's very helpful but my concern is every time I calibrate in either solution 1 mg/L or 100 mg/L the electrode voltage reading increases over time. For example for the first minute the reading is 240mV but then after 5 minutes the reading is 260mV. What I do is I get the highest electrode reading voltage after 5 minutes on both solutions to calibrate. Is this correct? I plan to recalibrate every one week the Ammonium, DO, pH.

Next issues. My first issue is also about the Ammonium ISE probe. I said in my concern about how to calibrate but just this day I am trying to recalibrate it but I am getting a constant electrode voltage reading (i.e. 490mV) in both solutions or in water. Any idea how to diagnose and fix this?

My second issue is about the DO and pH interference. Let's recap I have two Arduinos connected to a one computer; Arduino 1 - Temp and Ammonium Arduino 2 - pH and DO I am getting an interference on pH and DO even when I put the probes on each end of the aquarium tank, the length of the aquarium tank is 54 inches. So I tried putting the DO probe in my Aquarium Tank filter in which water pours down from a PVC pipe, the interference lessened a little but the point is I am still getting an interference. I see in this page also (http://www.vernier.com/til/files/638/sensor_interference_tables.pdf) that DO is bad with ISE in this case the Ammonium ISE. I need the DO constantly monitor the amount of DO without the interference.

dvernier commented 8 years ago

Hello,

I will respond to your email, section by section. First, I want to say, as we say all over our web site and on all of our documentation: Our products are designed for use in education. They are not meant for use in a commercial fish farming situation.

My concern is about the Ammonium ISE calibration, I am using the Vernier BNC sketch you provided and it's very helpful but my concern is every time I calibrate in either solution 1 mg/L or 100 mg/L the electrode voltage reading increases over time. For example for the first minute the reading is 240mV but then after 5 minutes the reading is 260mV. What I do is I get the highest electrode reading voltage after 5 minutes on both solutions to calibrate. Is this correct?

I talked with a chemist who knows this sensor well and she said everything you said makes sense. You have to be patient during the calibration process. She says waiting 5 minutes at each calibration point is probably about right.

My first issue is also about the Ammonium ISE probe. I said in my concern about how to calibrate but just this day I am trying to recalibrate it but I am getting a constant electrode voltage reading (i.e. 490mV) in both solutions or in water. Any idea how to diagnose and fix this?

Obviously something is seriously wrong if the voltage reading is not changing in those very different solutions. If the voltage reading is not changing, I would double check all connections. Also, note that ISE membranes do not last long. I read your email to the chemist and she thought it might be that the membrane needs replacing. See page 6 of:

http://www.vernier.com/files/manuals/nh4-bta.pdf

My second issue is about the DO and pH interference. Let's recap I have two Arduinos connected to a one computer; Arduino 1 - Temp and Ammonium Arduino 2 - pH and DO I am getting an interference on pH and DO even when I put the probes on each end of the aquarium tank, the length of the aquarium tank is 54 inches. So I tried putting the DO probe in my Aquarium Tank filter in which water pours down from a PVC pipe, the interference lessened a little but the point is I am still getting an interference. I see in this page also (http://www.vernier.com/til/fi les/638/sensor_interference_tables.pdf) that DO is bad with ISE in this case the Ammonium ISE.

There will always be interference using these two probes in one tank of water. The issue involves ground loops. The water acts as a conductor.

Dave Vernier

David L. Vernier Founder and Co-President Vernier Software & Technology 13979 SW Millikan Way Beaverton, OR 97005 503-277-2299 1-888-Vernier (1-888-837-6437) dvernier@vernier.com www.vernier.com

On Tue, Sep 6, 2016 at 6:52 AM, YukiSakuma notifications@github.com wrote:

Hello it's been a while the project got a little delayed but let's not bother with that. I now have the Tilapia fingerlings in the aquarium tank but before I could start the long term experiment I need to fix some concerns and issues.

My concern is about the Ammonium ISE calibration, I am using the Vernier BNC sketch you provided and it's very helpful but my concern is every time I calibrate in either solution 1 mg/L or 100 mg/L the electrode voltage reading increases over time. For example for the first minute the reading is 240mV but then after 5 minutes the reading is 260mV. What I do is I get the highest electrode reading voltage after 5 minutes on both solutions to calibrate. Is this correct? I plan to recalibrate every a week instead of the mentioned 2 weeks in the comments

Next issues. My first issue is also about the Ammonium ISE probe. I said in my concern about how to calibrate but just this day I am trying to recalibrate it but I am getting a constant electrode voltage reading (i.e. 490mV) in both solutions or in water. Any idea how to diagnose and fix this?

My second issue is about the DO and pH interference. Let's recap I have two Arduinos connected to a one computer; Arduino 1 - Temp and Ammonium Arduino 2 - pH and DO I am getting an interference on pH and DO even when I put the probes on each end of the aquarium tank, the length of the aquarium tank is 54 inches. So I tried putting the DO probe in my Aquarium Tank filter in which water pours down from a PVC pipe, the interference lessened a little but the point is I am still getting an interference. I see in this page also (http://www.vernier.com/til/ files/638/sensor_interference_tables.pdf) that DO is bad with ISE in this case the Ammonium ISE.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/VernierSoftwareTechnology/arduino/issues/3#issuecomment-244956585, or mute the thread https://github.com/notifications/unsubscribe-auth/AFvaavFBi6YMVP3CxfR6frKK3hYie-9gks5qnXAWgaJpZM4HahYL .

YukiSakuma commented 8 years ago

Wow! It's an honor to have our question answered by you Sir Vernier! Thank you for helping me with my inquiries! I tried working with the information you gave me and I have some more questions.

My Dissolved Oxygen Probe (http://www.vernier.com/products/sensors/dissolved-oxygen-probes/do-bta/) interferes with my pH sensor even when trying to place one sensor in the filter. I have found this sensor; DO Optical (http://www.vernier.com/products/sensors/dissolved-oxygen-probes/odo-bta/) does not interfere with pH and ISE (Ammonium) (http://www.vernier.com/til/2952/). How differently does the Optical Probe work?

I tried to fix my Ammonium ISE. I unscrewed the membrane, carefully wiped the electric contacts, put it back in, and soaked the Sensor in High-Standard solution (100 mg/L) for 30 minutes. It functioned again, but reverted to to displaying on 490mV. I haven't had the probe for more than 6 months, but the manual says that it is guarantees to last at least a year. Is it still possible to replace it? I carefully followed the instructions for testing, usage, and storage.

I truly appreciate you help in answering my earlier questions. The information is really helping me since I'm learning in the way.

dvernier commented 8 years ago

Hello,

My Dissolved Oxygen Probe (http://www.vernier.com/ products/sensors/dissolved-oxygen-probes/do-bta/) interferes with my pH sensor even when trying to place one sensor in the filter. I have found this sensor; DO Optical (http://www.vernier.com/products/sensors/dissolved- oxygen-probes/odo-bta/) does not interfere. How differently does the Optical Probe work?

If you look at the two manuals (which you can download from our web site), you will see that they are totally different. The Optical DO sensor is much more expensive, but does not interact electrically with the other water-quality sensors, like the other one does.

I tried to fix my Ammonium ISE. I unscrewed the membrane, carefully wiped the electric contacts, put it back in, and soaked the Sensor in High-Standard solution (100 mg/L) for 30 minutes. It functioned again, but reverted to to displaying on 490mV.

I talked with the chemists about this and they said that the key thing is to look at the voltages out when the probe is in the two standards. They should be 2.1 volts and 1.3 volts. Of course, these tests should be done with no other sensors interfering and following all the procedures in the user manual.

I haven't had the probe for more than 6 months, but the manual says that it is guarantees to last at least a year. Is it still possible to replace it? I carefully followed the instructions for testing, usage, and storage.

First, I have some questions:

Let me know the answers. I will get out a DO probe and an Arduino here and do some tests and compare results.

I do not want to encourage you to spend more money on an ODO probe. I am not sure you really should be using our sensors in this project.

Dave Vernier

David L. Vernier Founder and Co-President Vernier Software & Technology 13979 SW Millikan Way Beaverton, OR 97005 503-277-2299 1-888-Vernier (1-888-837-6437) dvernier@vernier.com www.vernier.com

On Wed, Sep 7, 2016 at 7:02 PM, YukiSakuma notifications@github.com wrote:

Wow! It's an honor to have our question answered by you Sir Vernier! Thank you for helping me with my inquiries! I tried working with the information you gave me and I have some more questions.

My Dissolved Oxygen Probe (http://www.vernier.com/ products/sensors/dissolved-oxygen-probes/do-bta/) interferes with my pH sensor even when trying to place one sensor in the filter. I have found this sensor; DO Optical (http://www.vernier.com/ products/sensors/dissolved-oxygen-probes/odo-bta/) does not interfere. How differently does the Optical Probe work?

I tried to fix my Ammonium ISE. I unscrewed the membrane, carefully wiped the electric contacts, put it back in, and soaked the Sensor in High-Standard solution (100 mg/L) for 30 minutes. It functioned again, but reverted to to displaying on 490mV. I haven't had the probe for more than 6 months, but the manual says that it is guarantees to last at least a year. Is it still possible to replace it? I carefully followed the instructions for testing, usage, and storage.

I truly appreciate you help in answering my earlier questions. The information is really helping me since I'm learning in the way.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/VernierSoftwareTechnology/arduino/issues/3#issuecomment-245473215, or mute the thread https://github.com/notifications/unsubscribe-auth/AFvaalo4H9u60sSu5kUc2WvK3RaNcuisks5qn2y3gaJpZM4HahYL .

YukiSakuma commented 8 years ago

Greetings!

Regarding the Ammonium ISE, I tested them in an isolated environment.

"- Do you have Vernier interface (LabPro, LabQuest, LabQuest 2, Go!Link) to
try this DO probe with?

- Have you done the tests with the two standards? What voltages do you get?
Are you saying that the voltage is 0.490 for each?

- Are you sure you have done all of this calibrating and testing with no
other sensor in water at the same time?

Let me know the answers. I will get out a DO probe and an Arduino here and
do some tests and compare results."

*these all pertain to the Ammonium ISE

The only interface I'm using is a SparkFun Red Arduino Uno Board connected to a Sparkfun Vernier-Arduino Shield since Arduino can comminicate with LabView (my database).

The Raw voltage is 3-4V (regardless of solution) while the converted voltage (ElectrodeReading = 137.55*Raw Voltage -0.1682) sits at 490 mV.

Yes, I calibrated the ISE using only the two standard solutions and no other sensors even connected to the shield.

I also have one more question but for the pH sensor this time. When I measured the pH (already calibrated using the buffer solutions) of my 280-gallon fish tank, the final reading fluctates from 9-10. However, when I immediately move the sensor to a cup/glass of the same aqarium water, the final reading is around 7.2-7.4. This test was done with no other sensors in the water at the time. Does the volume of water have an effect on the output of the pH sensor?

I truly appreciate your feedback you're giving me and I'm doing my best to investigate/test as well. Thank you very much!

dvernier commented 8 years ago

Hello again,

I think I now understand that you are using our sensors with an Arduino, our shield, and LabVIEW on a computer. This is an very unusual, complicated system. I have never done it. There are so many things that could be wrong, it is difficult to even troubleshoot. Why are you using such a complex system? Can you call me and let's discuss your goals here and how you could best get the job done. Call 1-888-837-6437.The only catch is I have to be out of the offfice from 8:30 am Pacific time until about 1 pm Pacific time.

I also have one more question but for the pH sensor this time. When I measured the pH (already calibrated using the buffer solutions) of my 280-gallon fish tank, the final reading fluctates from 9-10. However, when I immediately move the sensor to a cup/glass of the same aqarium water, the final reading is around 7.2-7.4. This test was done with no other sensors in the water at the time. Does the volume of water have an effect on the output of the pH sensor?

This is not reasonable. It implies to me that there is some electrical signal (from a pump or some other sensor) getting into you water. Try the same test with no electrical device of any kind in or touching the water, except our pH probe.

Dave Verniier

David L. Vernier Founder and Co-President Vernier Software & Technology 13979 SW Millikan Way Beaverton, OR 97005 503-277-2299 1-888-Vernier (1-888-837-6437) dvernier@vernier.com www.vernier.com

On Thu, Sep 8, 2016 at 11:20 PM, YukiSakuma notifications@github.com wrote:

Greetings!

Regarding the Ammonium ISE, I tested them in an isolated environment.

"- Do you have Vernier interface (LabPro, LabQuest, LabQuest 2, Go!Link) to try this DO probe with?

  • Have you done the tests with the two standards? What voltages do you get? Are you saying that the voltage is 0.490 for each?
  • Are you sure you have done all of this calibrating and testing with no other sensor in water at the same time?

Let me know the answers. I will get out a DO probe and an Arduino here and do some tests and compare results."

*these all pertain to the Ammonium ISE

The only interface I'm using is a SparkFun Red Arduino Uno Board connected to a Sparkfun Vernier-Arduino Shield since Arduino can comminicate with LabView (my database).

The Raw voltage is 3-4V (regardless of solution) while the converted voltage (ElectrodeReading = 137.55*Raw Voltage -0.1682) sits at 490 mV.

Yes, I calibrated the ISE using only the two standard solutions and no other sensors even connected to the shield.

I also have one more question but for the pH sensor this time. When I measured the pH (already calibrated using the buffer solutions) of my 280-gallon fish tank, the final reading fluctates from 9-10. However, when I immediately move the sensor to a cup/glass of the same aqarium water, the final reading is around 7.2-7.4. This test was done with no other sensors in the water at the time. Does the volume of water have an effect on the output of the pH sensor?

I truly appreciate your feedback you're giving me and I'm doing my best to investigate/test as well. Thank you very much!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/VernierSoftwareTechnology/arduino/issues/3#issuecomment-245829145, or mute the thread https://github.com/notifications/unsubscribe-auth/AFvaahNdFTc-DB9ohvNr7a0myBSQcZwVks5qoPqdgaJpZM4HahYL .

YukiSakuma commented 8 years ago

Greetings Sir Vernier! I apologize for a late reply, thank you so much for your feedback. I was working with the sensors and the information you gave me. These are my findings:

The only interface I'm using is a Sparkfun Vernier Sensor Arduino shield coupled with a Red Sparkfun Arduino Uno board and the official Arduino software. No lab-quest or related Vernier software/hardware. The Arduino is solely powered by the USB connection to my laptop.

This leads me to my next question, what does it mean when both my Ammonium ISE and DO register flat 0V readings in the Arduino COM Monitor? I limited them only to sampling purposes and stowed them when they were not in use.

Thank you again for helping me.

Smythics commented 8 years ago

Hi. Dave's not in the office today so I'll try to help.

I went and talked to one of our biologists and he stressed that these sensors are not intended to be used in situ for long periods of time, but rather calibrated and then used to measure a sample. When you need another reading you need to calibrate again (or take your chances...) and measure. The issue is that the membranes for both of these sensors change over time.

I'll refer you back to Dave's comment that our sensors may not be the best for this application. We've had some inquiries about this for tilapia projects in their classrooms, etc. but I haven't heard of any successful "hands free" monitoring systems.

If I've misinterpreted your set up, please let me know. A photo of the set up may be helpful.

Tom

dvernier commented 8 years ago

Hello,

I am away on vacation until Oct 3rd. There are other people at the office who can help you, but to know who to recommend, I am still trying to figure out what exactly you are doing. We have never used Arduino With LabVIEW. If that is what you are doing, contact Sam Swartley, sswartley@vernier.com.

The fact that you are reading 0 volts, makes me suspicious that you are not reading the voltage properly.

Here is something to try, which could help pin this down: with the program running, swap a working sensor with a non-working sensor. Do you still get a 0 reading? Of course, the reading cannot be right, but it should at least be non-zero.

As I said last time, the fastest way to resolve this would be for you to call our office.

Dave Vernier

Sent from my iPhone

On Sep 16, 2016, at 3:31 PM, YukiSakuma notifications@github.com wrote:

This leads me to my next question, what does it mean when both my Ammonium ISE and DO register flat 0V readings in the Arduino COM Monitor? I limited them only to sampling purposes and stowed them when they were not in use.