Temperature and ORP probe Combination

Hello everyone,

I currently have the setup shown below using an Arduino Uno, Atlas Scientific ORP probe, DS18B20 temperature probe, and an Atlas Scientific isolated carrier board. With the current code below, we are able to see readings from both probes in the serial monitor (although for every five temperature readings we receive one ORP reading). However, the ORP readings stop outputting to the monitor after 13 times while the temperature continues to output. Our main objective is to have both probes constantly outputting to the serial monitor without need for two separate codes. Tinkering with the Serial.readstringuntil() command doesn't appear to have an effect. Thanks!

Code:

#include <OneWire.h>
#include <DallasTemperature.h>
 
// Data wire is plugged into pin 4 on the Arduino
#define ONE_WIRE_BUS 4
 
// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire); 

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

SoftwareSerial myserial(rx, tx);                      //define how the soft serial port is going to work

String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false;                //have we received all the data from the PC
boolean sensor_string_complete = true;               //have we received all the data from the Atlas Scientific product
float ORP;         
//used to hold a floating point number that is the ORP

void setup()
{
  // start serial portf
//  Serial.begin(9600);
//  Serial.println("Dallas Temperature IC Control Library Demo");
  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600
  myserial.begin(9600);                               //set baud rate for the software serial port to 9600
  inputstring.reserve(10);                            //set aside some bytes for receiving data from the PC
  sensorstring.reserve(30);                           //set aside some bytes for receiving data from Atlas Scientific product

  // Start up the library
  sensors.begin();
}

void serialEvent() {                                  //if the hardware serial port_0 receives a char
 inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>
 input_string_complete = true;                       //set the flag used to tell if we have received a completed string from the PC
 }

 
void loop()
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  Serial.print("Temperature is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire
        
    if (input_string_complete == true) {                //if a string from the PC has been received in its entirety
    myserial.print(inputstring);                      //send that string to the Atlas Scientific product
    myserial.print('\r');                             //add a <CR> to the end of the string
    inputstring = "";                                 //clear the string
    input_string_complete = false;                    //reset the flag used to tell if we have received a completed string from the PC
  }

  if (myserial.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character
    char inchar = (char)myserial.read();              //get the char we just received
    sensorstring += inchar;                           //add the char to the var called sensorstring
    if (inchar == '\r') {                             //if the incoming character is a <CR>
      sensor_string_complete = true;                  //set the flag
    }
  }


  if (sensor_string_complete == true) {               //if a string from the Atlas Scientific product has been received in its entirety
    Serial.println("      ORP probe " + sensorstring);                      //send that string to the PC's serial monitor
                                                    //uncomment this section to see how to convert the ORP reading from a string to a float 
  if (isdigit(sensorstring[0])) {                   //if the first character in the string is a digit
      ORP = sensorstring.toFloat();                   //convert the string to a floating point number so it can be evaluated by the Arduino
      if (ORP >= 500.0) {                             //if the ORP is greater than or equal to 500
        Serial.println("high");                       //print "high" this is demonstrating that the Arduino is evaluating the ORP as a number and not as a string
      }
      if (ORP <= 499.9) {                             //if the ORP is less than or equal to 499.9
        Serial.println("low");                        //print "low" this is demonstrating that the Arduino is evaluating the ORP as a number and not as a string
      }
    }
   */
    sensorstring = "";                                //clear the string
    sensor_string_complete = false;                   //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
    delay(100);
  }
}

I don't know what an ORP is but, for the DS18B20, your loop timing is totally unreasonable and probably nonsensical too. The DS18B20 requires, in your setup, 750ms to do its job. If you change the delay command to from 100 to 1000, you might get a result.

In the unlikely event that you really need temperature readings at 1/10 sec intervals, you need a different sensor.

Particularly since the thermal time constant of the probe is in the 10s of seconds or even minutes range.

This waits AFAIK for the conversion, up to 750ms.
Leo..

Hi, @mhallums02
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.

The Fritzy image you have posted really doesn't show us much.

Thanks.. Tom... :+1: :coffee: :australia:

The software serial Rx.Tx and one wire connections in your diagram are wrong, probably because you counted 1,2,3, instead of 0,1,2,3... but, other than that, it is fine, and you have obviously gone to some trouble with it.

Further, since you actually receive some results, it is pretty clear that your wiring is kosher anyway, and your errors irrelevant. I guess you would have done the same thing if you did it by hand.

I now understand that the ORP has something to do with water turbidity. Be aware that the DS18B20 isn't as waterproof as it might look.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.