Turn an old laptop into pH measaurement station by arduino and visual studio code

Nadir ALTINBASBSc.,E&E Engr.-A. Ec., Professional | Freelance  
Turn an old laptop into a pH measure station by Arduino and visual studio code. You may create your own application by using an old laptop. Arduino emulator coding and visual code studio programming required.
Turn an old laptop into pH measuring station by Arduino and Visual Studio Code

Instead of disposing of an old laptop that's not suitable for upgrading to a current operating system, consider modifying it to be reused as a Chemical Ph measurement system with the code blocks we'll discuss here.

Here's a list of hardware that will be needed:

A nutrition pH probe suitable for use with Arduino Sensor board

An Arduino board for the stations such as a Mega 2560 board

Here's how the kit would be assembled:

                                                     Figure 1 shows the component connections

At the first step, we must determine how often you will be reading ph data from the station. If it is rare then you may prefer a visual studio coded user form that can be used to read data from the sensor. (See Figure 2). 

If you expect to get scrolling data output of Arduino serial monitor (Figure 3 from Tools menu of Arduino Emulator), then installing Arduino emulator to the laptop is a better choice The code is available at the following link;

Reference link

The Arduino code is as follows;

//This code was written to be easy to understand.
//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the pH circuit.
//This code was written in the Arduino 1.8.9 IDE
//An Arduino UNO was used to test this code.
//This code was last tested 6/2019

#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 = false;               //have we received all the data from the Atlas Scientific product
float pH;                                             //used to hold a floating point number that is the pH

void setup() {                                        //set up the hardware
  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

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() {                                         //here we go...

  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
    /*                                                //uncomment this section to see how to convert the pH reading from a string to a float
    if (isdigit(sensorstring[0])) {                   //if the first character in the string is a digit
      pH = sensorstring.toFloat();                    //convert the string to a floating point number so it can be evaluated by the Arduino
      if (pH >= 7.0) {                                //if the pH is greater than or equal to 7.0
        Serial.println("high");                       //print "high" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string
      if (pH <= 6.999) {                              //if the pH is less than or equal to 6.999
        Serial.println("low");                        //print "low" this is demonstrating that the Arduino is evaluating the pH 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

Figure2; The VCS User Form for serial data monitor;

(Optional)Visual Studio Code for Arduino serial read: To code of  The VCS User Form for serial data monitor is metioned below as tutorial.Thumb of hand ,User form  should at least  consist of port and baud rate list box,and connection  and close conection button and pH data box, measuring start button,
more than this spec It's up to your imagination to add newer features such as you may use by connecting dc servo motor to hardware list then you shall have a new designed .VCS user form that will contain extra buttons to control servo motor.It depends on your imagination.Only here main specification is explained.Ms Visual Studio code files you'll created and not given here due to this reason.

At the first  stage; Adding Libraries;

Imports System
Imports System.ComponentModel
Imports System.Threading
Imports System.IO.Ports

The object that will connect to serial port introducing;

Dim myPort As Array 
Delegate Sub SetTextCallback(ByVal  As String)

Click on form somewhere empty space then Load part will be open then write below code of piece  ;

myPort = IO.Ports.SerialPort.GetPortNames()
For i = 0 To UBound(myPort)
ComboBox1.Text = ComboBox1.Items.Item(0)
ComboBox2.Text = ComboBox2.Items.Item(0)
Button2.Enabled = False

Click button double and write below code;
 SerialPort1.PortName = ComboBox1.Text
 SerialPort1.BaudRate = ComboBox2.Text
 SerialPort1.Parity = IO.Ports.Parity.None 
SerialPort1.StopBits = IO.Ports.StopBits.One
 SerialPort1.DataBits = 8 SerialPort1.Open()
 Label10.Text = "Connected" Button1.Enabled = False
 Button2.Enabled = True[/c]
Stop connection button double click and then write below code;

  Button1.Enabled = True
  Button2.Enabled = False
  Label10.Text =  "Connection Failed."

Baudrate combobox double click and write below code;

If SerialPort1.IsOpen = False Then
SerialPort1.BaudRate = ComboBox2.Text
MsgBox( "can not change while Port is open" , vbCritical)
End If

Last code is as following;

                                    Figure 3; Arduino Emulator Coding Interface

You may read the pH data from the VCS user form by the connection of a pH probe with a  sensor while connected to an Arduino mega 2560 board. You must define laptop COM ports and baud rate as appropriate.

Note: The Arduino code should be modified as the serial monitor will print serial data on the user form of visual code studio. It is not explained here because every laptop user has different OS's such as Windows XP 32-bit cannot run visual studio code .VCS file can run  when compiled for 64-bit . And you may check these out also from referenced Arduino forum the following lines to improve   ;

So, with the use of three components and a little code, an Arduino board, sensor and pH probe adapted to an old laptop by a USB cable, measuring the data of any chemical compound is made possible.

Reusing your laptop and creating a new test and measure station provides a low budget option in respect to far more costly systems.And also you may have advantage with  respect to test kits if you do not have time to get every time a new test kit or a test bandage, probe system is more accurate and precise than other's.Therefore ; probe using and make of use with an old laptop is more usefull.Fish Tank hobbyist know well that in a definite time interval controlling pH of tank water is needed.Otherwise , water quality damage occurs in an aquarium.

The implementation shows that measuring the pH value of any chemical substances such as honey, aquarium water (fish tank), coke, and liquid from water is possible. Be sure to select an appropriate pH probe suitable for the Arduino sensor. If you find and use Chinese boards in your system, I can help with further info of connection and other features. Contact me on Experts Exchange or by leaving a comment below.

Nadir ALTINBASBSc.,E&E Engr.-A. Ec., Professional | Freelance  

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.

Get access with a 7-day free trial.
You Belong in the World's Smartest IT Community