Arduino Uno Orp Sample Code
Arduino Uno Orp Sample Code
GND
9
8
7
6
5
4
3
2
1
0
AREF
13
12
10
11
RESET
RX0
TX0
DIGITAL (PWM= )
ICSP2
L
TX ON
Arduino
TM
RX
1
ICSP
center
sheild
POWER ANALOG IN
RESET
IOREF
GND
GND
3V3
VIN
5V
A0
A1
A2
A3
A4
A5
BNC
#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 rx 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 = false; //have we received all the data from the Atlas Scientific product
float ORP; //used to hold a floating point number that is the ORP.
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(sensorstring); //send that string to the PC's serial monitor
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
}