PH sensor question

Trying to make a PH sensor temperature compensated,
Cant be that simple, sketch likes it, but I'm sure its wrong lol

code

#include <NewSoftSerial.h>
NewSoftSerial mySerial =  NewSoftSerial(2, 3);
char stamp_data[15];
byte holding;
byte i;
byte startup=0;
//declare variables
float tempC;
int tempPin = 0;

void setup(){
  mySerial.begin(38400);
  Serial.begin(38400);
          }
void loop() {
tempC = analogRead(tempPin);           //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
Serial.print((byte)tempC);             //send the data to the computer
delay(1000);                           //wait one second before sending new data

if(startup==0){
  for(i=1; i <= 2;i++){
      delay(1000);
      mySerial.print("l0");
      mySerial.print(13,BYTE);
      delay(1000);
      mySerial.print("l1");
      mySerial.print(13,BYTE);
 }
  startup=1;
  delay(1000);
   mySerial.print(tempC);    //I'm not sure this is right I changed it from “c” to tempC
   mySerial.print(13,BYTE);
}
 if(mySerial.available() > 3) {
    holding=mySerial.available();
    for(i=1; i <= holding;i++){
        stamp_data[i]= mySerial.read();
   }
    for(i=1; i <= holding;i++){
        Serial.print(stamp_data[i]);
       }
       Serial.println("");
  }
}

Why are you sure its wrong? Please explain it to us.

  • Is the output as expected?

  • if not what did you expect?

  • What temp sensor is used?

  • what PH sensor is used?

  • Datasheet links?

Ok never mind that,, I just need to try it 1st.
But I'm trying to add a little more code at the end and need help there.

what is the code for PH I know its not tempC

#include <NewSoftSerial.h>
NewSoftSerial mySerial =  NewSoftSerial(2, 3);
char stamp_data[15];
byte holding;
byte i;
byte startup=0;
//declare variables
float tempC;
int tempPin = 0;

void setup(){
  mySerial.begin(38400);
  Serial.begin(38400);
          }
void loop() {
tempC = analogRead(tempPin);           //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
Serial.print((byte)tempC);             //send the data to the computer
delay(1000);                           //wait one second before sending new data

if(startup==0){
  for(i=1; i <= 2;i++){
      delay(1000);
      mySerial.print("l0");
      mySerial.print(13,BYTE);
      delay(1000);
      mySerial.print("l1");
      mySerial.print(13,BYTE);
 }
  startup=1;
  delay(1000);
   mySerial.print(tempC);
   mySerial.print(13,BYTE);
}
 if(mySerial.available() > 3) {
    holding=mySerial.available();
    for(i=1; i <= holding;i++){
        stamp_data[i]= mySerial.read();
   }
    for(i=1; i <= holding;i++){
        Serial.print(stamp_data[i]);
       }
       Serial.println("");

 if (tempC > 7) {                //  I need help, what is the code for PH I know its not tempC
   digitalWrite(9, HIGH);
delay (1000);
   digitalWrite(9, LOW);
delay (2*60UL*60UL*1000UL);
 } 
  else {
 
  }  
  }
}

At least some of the same questions that robtillaart asked still apply. You need to answer them before we can help you.

Ok I can tell you, I'm going to use an LM35 temp sensor and a atlas scientific PH stamp.
I don't have it hooked up yet just writing the code for it, so I cant test it as of yet.
http://atlas-scientific.com/arduino-hydroponics.html?gclid=CM3w6L6Y8KgCFUa8KgodPwduIA
They have a sample wiring diagram and a sample code

/*

This software was made to demonstrate how to quickly get your pH/ORP/DO/ stamp running on the Arduino platform.

An Arduino Duemilanove board was used to test this code.

Modify the code to fit your system. Code efficacy was NOT considered, this is a demo only.

To use this code you must add the "newsoftserial" library to your Arduino library folder.

The soft serial port TX line goes to the stamps RX pin.

The soft serial port RX line goes to the stamps TX pin.

Make sure you also connect to power and GND pins on the stamp to power and a common ground.

Data from the stamp is received and re-sent through the Arduinos hardware UART TX line.

Open TOOLS > serial monitor, set the serial monitor to the correct serial port and set the baud rate to 38400.

The data from the stamp will come out on the serial monitor

*/

Download this code

#include <NewSoftSerial.h>               //this will let the software take advantage of the "newsoftserial" library.                    

 

NewSoftSerial mySerial =  NewSoftSerial(2, 3);  //setup and rename soft uart.

    //RX|TX

 

char stamp_data[15];          //this is where the data from the stamp is stored. The array is 15 char long because

                                                //if no pH probe is connected, the message "check probe" is transmitted.

                         //Having an array that is too small will cause data corruption and could cause the Arduino to crash. 

 

byte holding;                       //used to tell us the number of bytes that have been received by the Arduino and are

              //holding in the buffer holding

byte i;                                  //counter

byte startup=0;                //used to control the start-up sequence 

 

void setup(){

  mySerial.begin(38400);                     //set up the soft serial to run at 38400              

  Serial.begin(38400);                          //set up the hardware serial port to run at 38400

          }

           

           

          

void loop() {                                       //main loop

 

if(startup==0){                                  //if the start-up sequence has not been run

  for(i=1; i <= 2;i++){                        //we go through this for-loop twice, turning on/ off the stamp leds 

      delay(1000);                               //wait 1 second

      mySerial.print("l0");                 //turn off the led

      mySerial.print(13,BYTE);         //ALWAYS end a command with <CR> (which is simply the number 13) or

           // (print("/r")

      delay(1000);                              //wait 1 second

      mySerial.print("l1");                //turn on the led

      mySerial.print(13,BYTE);        //ALWAYS end a command with <CR> (which is simply the number 13) or

          //(print("/r")

  }

  startup=1;                                    //stop the star-up loop from happening by setting the start-up var to 1

 

  delay(1000);                                  //after the stamp leds flashed twice, lets wait 1 second before we give the

         // stamp a new command

           

  mySerial.print("c");                   //the command "c" will tell the stamp to take continues readings

  mySerial.print(13,BYTE);          //ALWAYS end a command with <CR> (which is simply the number 13) or

        //(print("/r")

  

   //to take a single reading

   //you would simple send the command

   //mySerial.print("r");    

   //mySerial.print(13,BYTE);

  

   //to take a temperature dependent reading

   //send the temperature in celsius, let's say

   //the temperature in celsius is 18.5

  

   //mySerial.print("18.5");    

   //mySerial.print(13,BYTE);

}

 

 

 

 

 if(mySerial.available() > 3) {                  //if we see the more than three bytes have been received by the Arduino

    holding=mySerial.available();            //lets read how many bytes have been received

   

    for(i=1; i <= holding;i++){                     //we make a loop that will read each byte we received

        stamp_data[i]= mySerial.read();     //and load that byte into the stamp_data array

    }

   

    for(i=1; i <= holding;i++){                      //we now loop through the array        

        Serial.print(stamp_data[i]);             //printing each byte we received  through the hardware UART

       }

       Serial.println("");                               //once we finished, we print a null char with the <CR><LF> command.

      }

}

The sample code used for the LM35 is at My Projects: Arduino LM35 Sensor or here is one more Temperature sensor tutorial - Using the TMP36 / LM35
I'm using 5 volts

//declare variables
float tempC;
int tempPin = 0;

void setup()
{
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}

void loop()
{
tempC = analogRead(tempPin);           //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
Serial.print((byte)tempC);             //send the data to the computer
delay(1000);                           //wait one second before sending new data
}

They have a sample wiring diagram and a sample code

Then, why haven't you hooked it up yet? With sample code provided, why do you need to write more code to test it?

Well here's the thing I don't have all the parts yet, this is just part of a real long and complicated program.
Its an automated hydroponic garden. Fighting with those UPS guys in a big way, never ever ship anything UPS they suck USPS all the way.
Anyway all I want to know is the code for the PH part so I can Finnish.

Anyway all I want to know is the code for the PH part so I can Finnish.

I don't have it hooked up yet just writing the code for it, so I cant test it as of yet...They have a sample wiring diagram and a sample code

So, I'll ask again. What's wrong with the sample code?