Skip to content

How to use a pH sensor with Arduino?


Measuring the pH value of liquids is important for many applications such as checking water quality, monitoring chemical processes, agriculture, food processing, and more. pH sensors allow you to precisely measure the acidity or alkalinity levels of a solution. These sensors can be easily interfaced with Arduino boards to create DIY pH meters or data loggers. This comprehensive guide will teach you all about pH sensors and how to connect them to Arduino for taking pH measurements.

What is pH and Why Measure it?

pH stands for ‘potential hydrogen’ and is a measure of the hydrogen ion concentration in a solution. It indicates how acidic or basic a liquid is on a scale from 0 to 14. Pure water has a neutral pH of 7. Acidic solutions have a lower pH while bases have a higher pH.

Measuring pH is important for:

  • Checking water quality for drinking, aquariums, swimming pools.
  • Monitoring chemical processes and reactions.
  • Agriculture and gardening applications.
  • Food processing and cooking.
  • Environmental studies.
  • Science experiments.

Accurately monitoring pH allows maintaining safe levels and identifying any hazardous changes.

How pH Sensors Work

pH sensors work by measuring the electron activity in a solution and generating a voltage proportional to the pH. This voltage signal can then be conditioned, amplified, and converted to a digital value for processing by a microcontroller.

The sensing part of a pH probe consists of a glass electrode and a reference electrode. The glass electrode develops an electrical potential proportional to the hydrogen ion activity as given by the Nernst equation. This potential is measured against the stable potential of the reference electrode.

Common types of pH sensors include:

  • Glass electrode sensors
  • ISFET (Ion Selective Field Effect Transistor) based sensors
  • Antimony electrode sensors

Out of these, glass electrode pH sensors are the most popular and commonly used with Arduino.

Parts Required

To interface a pH sensor with Arduino, you will need the following components:

  • Arduino Board (Uno, Nano, Mega etc)
  • pH Sensor (with BNC connector)
  • BNC to Banana plug adapter
  • pH Probe (glass electrode type)
  • Op-amp IC (LM358/LM741)
  • 10kΩ resistor
  • Jumper wires

Optionally, you can also add:

  • LCD/OLED display
  • SD card module for data logging
  • Isolator circuit for safety

Circuit Diagram

The basic circuit diagram for connecting a pH sensor to Arduino is shown below:

The pH probe generates a very small voltage (in mV range) proportional to the hydrogen ion concentration. This needs to be amplified to scale it to the 0-5V range of the Arduino analog inputs.

An op-amp IC like LM358 can provide the necessary amplification or buffering. The 10k resistor helps set the gain to about 200X to amplify the 0-1000mV sensor range to 0-5V DC range for the Arduino.

The Arduino can then read this amplified pH voltage on one of its analog input pins to measure the pH of the solution.

Connecting the Hardware

Follow these steps to connect the pH sensor hardware with Arduino:

  1. Connect the pH probe to the BNC to Banana plug adapter.
  2. Connect the adapter ground (-) jack to the Arduino GND pin.
  3. Connect the adapter signal (+) jack to the non-inverting input of the op-amp IC.
  4. Install a 10kΩ resistor between the op-amp output and inverting input. This sets the gain for amplification.
  5. Wire the op-amp output to an analog input pin on the Arduino such as A0.
  6. Power the op-amp IC if needed by connecting the power and ground pins to 5V and GND respectively.
  7. Optionally, you can add an LCD display, SD module, etc to the available Arduino pins.
  8. Insert the pH probe in the solution to be tested.

This completes the sensor interfacing circuitry. Make sure all connections are secure before powering up the Arduino board.

Calibrating the Sensor

Before taking pH measurements, the sensor needs to be properly calibrated. Calibration eliminates any inherent offsets in the probe and sets the measurement scale accurately.

Calibration involves immersing the sensor in calibration solutions of known pH like 4.0, 7.0 and 10.0 and adjusting the voltages/readings accordingly.

Here are the steps to calibrate the pH sensor:

  1. Allow the sensor to stabilize in a pH 7.0 solution for 30 minutes.
  2. Take a voltage reading with the sensor immersed in the pH 7.0 buffer and note it down.
  3. Rinse the probe with clean water and place it in the pH 4.0 calibration solution.
  4. Measure and note down the sensor voltage at pH 4 after it stabilizes.
  5. Repeat the same process with the pH 10 calibration solution.
  6. Use these 3 points to create a calibration curve for converting voltage to pH values.
  7. The Arduino sketch can use this function to return accurate pH readings.
  8. Periodically recalibrate the sensor every few weeks for best accuracy.

Arduino Sketch

The Arduino software needs to read the analog voltage, map it to a pH value based on the calibration curve, and display/log the results.

Here is a sample Arduino sketch to do this:

//pH Sensor Arduino Code const int phPin = A0; //pH sensor connected to analog pin A0 float phValue; //to hold pH value void setup() { Serial.begin(9600); //calibrate pH meter function calibrateSensor(); } void loop() { phValue = readpH(); //read pH value Serial.print("pH: "); Serial.println(phValue); delay(1000); } //Function to calibrate sensor void calibrateSensor() { //calibration codes //store calibration points //map voltages to pH values } //Function to read pH float readpH(){ //read analog voltage //map voltage to pH based on calibration return ph; //return pH value }

Modify the calibration logic and reference voltage to pH mapping based on your specific sensor calibration. This will give you accurate real-time pH measurements that can be displayed or datalogged.

Displaying the Output

To display the pH value on an LCD module, simply print the phValue to the LCD in the loop() function:

lcd.setCursor(0,0); lcd.print("pH: "); lcd.print(phValue);

You can also display pH graphically on OLED displays.

Data Logging to SD Card

For datalogging applications, the pH readings can be appended to a CSV file on an SD card module attached to Arduino:

File dataFile ="phdata.csv", FILE_WRITE); if (dataFile) { dataFile.print(phValue); dataFile.println(","); dataFile.close(); }

This will continuously log the pH measurements to the SD card for later analysis.

Applications and Examples

The Arduino based pH sensor setup can be utilized for:

  • Aquarium or swimming pool pH monitoring
  • Checking water quality and alkalinity
  • Hydroponics monitoring
  • Measuring pH of juices, drinks
  • Environmental water analysis
  • Science experiments and projects

By using specialty pH probes, the sensor can also measure pH in non-aqueous solutions like fats, oils, solvents etc.


Measuring pH is important for a wide range of chemical processes and applications. By interfacing a pH electrode probe to an Arduino through a suitable amplification circuit, you can build your own DIY pH meter. With proper calibration, these Arduino pH sensors can provide reasonably accurate pH measurements for your needs. The pH data can also be displayed, charted, or datalogged using Arduino. Overall, Arduino provides a simple yet powerful way to incorporate pH testing ability into your projects.

Frequently Asked Questions

What is the typical output range of a pH sensor?

Most pH sensors have an output voltage range of around -400mV to 400mV or -1500mV to 1500mV corresponding to the 0-14 pH scale. This small mV range voltage needs to be amplified to the 0-5V range for Arduino analog inputs.

Do I need a special pH probe for Arduino?

No, you can use any standard laboratory pH probe with BNC connector. Just get a BNC to banana plug adapter to match its pins to the breadboard. There are also special waterproof Arduino compatible pH probes available.

What solutions are used for calibrating a pH meter?

Calibration is done using standard buffer solutions like ph 4, ph 7 and ph 10. Precision buffer solutions that provide exact ph values for calibration are also available. Choose calibration buffers close to your expected measurement range.

Can I interface other chemical sensors to Arduino?

Yes, Arduino can interface to many types of electrochemical sensors apart from pH, including CO2, dissolved oxygen, nitrogen, and more. Similar circuits with amplifiers and calibration are needed to adapt their signals for Arduino.

How often should the pH meter be calibrated?

pH sensors need to be recalibrated every 1-2 weeks to maintain accuracy. Frequent calibration compensates for ageing effects of the glass electrode membrane over time. Calibrate more often for very precise measurements.

How to build an Arduino PH sensor

We all know PH is an essential thing for drinking water. If you don’t take care of this crucial ingredient, you might ruin your entire meal in a matter of seconds. This article will teach you how to build an Arduino Ph sensor as a beginner project for someone who doesn’t know what they’re doing.

What is an Arduino?

We can regard an Arduino as a ‘microcontroller.’ This means that it is a tiny computer that you can use for electronic projects (and for much more). It can act as the main component in a huge amount of projects. By combining multiple projects, you can make something even greater.

We do this project using the Arduino Uno and the Arduino 1.0.2 IDE (integrated development environment).

These are the components we will be using:

– Arduino Uno ($30)

– Arduino Starter Kit ($80)

– Ph probe ($50)

Before you get started, make sure you set up the Arduino kit by following the instructions that came with it. This takes approximately 1 hour and 30 minutes to do. However, if you’re in a hurry, it’s possible to do this in 20 minutes by following this tutorial.

What is pH?

pH is a measure of the acidity or alkalinity of an aqueous solution.

The pH scale is logarithmic, and it measures the negative base ten logarithms of the activity of hydrogen ions in a solution.

The pH scale is from 0 to 14, with seven being neutral, less than seven acidic, and greater than seven is alkaline.

Every solution has a pH that a simple electrode can measure. For example, lemon juice has a pH of 2-3, and vinegar has a pH range from 4-6. Clean water may have a pH between 6.5 and 8, depending on the area you live.

A downside to this value is that it’s not used for precise recipes when cooking.

A pH level of 7 is considered neutral, any lower and it becomes increasingly acidic, any higher and it becomes progressively alkaline.

A probe

A probe is an electronic device that allows you to measure the amount of voltage or current flowing through a circuit. For example, we will be using a Ph probe when measuring PH. This sensor lets us know if the water contains acids or bases.

The PH probe has two wires:  one red and one black. The blue wire connects to 5V, and the black wire connects to the Ground(GND). The Red wire is what you use to measure the PH. It’s a very sensitive probe that can measure the pH value. You connect it to the Arduino, and in a concise period, it will tell you if the solution has an acidic or basic value.

pH Sensor for Arduino

There are many different models of Ph Sensor for Arduino. Unfortunately, many of them appear similar. But, if you want to do a good job and make sure your sensor will last for a long time, you should go with one from Rayming PCB & Assembly and get this one.

You can connect the sensor to the Arduino board using two wires. Once the connection is complete, you can start testing the sensor. You should do this by using a small piece of bread. The amount of sugar in bread is close to human skin, so it is easy to see how the sensor will react.

One can adjust the Ph probe to any other values as well. You need to tell it which value you want, and it will give it back to you (the value). You can do this by using a simple piece of bread.

Testing the sensor after connecting it to the Arduino is essential before using other solutions. You should always let the sensor rest for around 24 hours to stabilize and work properly. You will have to do this again when you connect it to a new circuit later.

The Ph probe requires between 3.5V and 5V to read the solution’s pH value properly. Therefore, to monitor the pH level of your Arduino project, you will need to use a voltage regulator or a voltage divider.

This project will use two transistors and two resistors to get the proper readings from different circuits or sensors. For example, if you want to measure the temperature on your Arduino board, you can get that information with a thermistor. However, the readings for both temperatures and pH depend on the circuit’s current level and, therefore, on the value used in your soil ph sensor Arduino.

Components and supplies

To build this little project, you will need to gather a few components and supplies. Here is the list:

  1. Acrylic sheet (plexiglass)
  2. Jumper wires
  3. Resistor 1k ohm
  4. Resistor 220 ohm
  5. Mini breadboard
  6. 158x90x60mm enclosure
  7. 20×4 LCD Module
  8. Atlas Scientific Consumer Grade pH Probe
  9. Atlas Scientific Gravity Analog pH Sensor
  10. Arduino UNO
  11. Arduino IDE


Before you start building your sensor, make sure to read these instructions carefully. Your project will not be waterproof. Ensure that you place the device on a flat, safe surface.

 When moving or storing your Arduino circuit, always unplug the sensor from the Arduino to make sure it doesn’t short-circuit on something.

If you are unsure about this project, don’t hesitate to ask someone about electronics and programming. You will learn more, and your project and knowledge will grow bigger.

Other than that, almost everything is as simple as a ‘Plug and Play’ installation. If anything fails to work correctly, try restarting the Arduino IDE. If it still doesn’t work, check all the connections again to ensure there aren’t any loose wires touching other components or parts of the circuit.

Step 1: Prepare the housing

You can choose to make the Arduino board a stand-alone device so that you don’t need an enclosure. But, we think it’s better to use an enclosure because it gives you a safer way to store your sensor or Arduino board in the future. But, of course, you could also use the box that comes with your Arduino kit.

First, you will have to cut out two holes for the LCD module, the mobile phone camera, and the micro SD card slot.

You should place the LCD on the bottom of the enclosure. Make sure you leave enough room for the mobile phone camera and micro SD card slot.

Supply a hole at the right size for the LCD screen, and make a hole on the back of your enclosure so that you can place a screw to fix it in place.

Place your finished product on top of another piece of acrylic sheet or plexiglass that is slightly larger than your enclosure. Then, cut it to the same size as a saw. Once you finish both pieces, drill two holes for the mobile phone camera and one for the micro SD card slot.

 Don’t worry if you mess up while making these holes. You can always take your enclosure apart and fix all these problems. Do this by using a drill bit that is slightly smaller than your cord and then cut all of these holes with a rotary tool, or you can use a saw if you want to make smoother cuts.

Step 2: Install electronics in the housing

Install three components, two transistors, and one resistor for the Arduino pH sensor. Here is a quick explanation of these components:

1) First, we will install the 220-ohm resistor from the LCD module side so that you can use an external power source. You also want to connect this to your Arduino board’s positive (red) side.

2) Next, connect the LCD module’s ground to the Arduino board’s ground.

3) To install the two transistors, you will use a breadboard. First, make sure that you place the transistor in each circuit correctly.

4) You will also have to add an extra ground wire between the transistors and the breadboard since they don’t share a common ground with the Arduino board. Finally, connect the transistor and resistor to GND on the Arduino board.

5) You can now install the Ph probe by using jumper wires.

The Ph probe should be installed like the picture above to connect the wires to your Arduino board. The GND wire should be connected to one of the Arduino’s pins and should go in between both transistors to be grounded.

You can wire the other wire (from the Ph probe) directly with one of the transistors (the transistor without an extra ground wire).

Finally, you can install the LCD module using two wires. You need to connect one pin to the Arduino board and the other to the transistor that shares a ground with the Arduino. You can use a breadboard for this if you want, but it is much easier just by connecting both circuits directly.

Step 3: Wire the electronics together

You have already installed all the components in your housing, and now you have to connect them. For this step, make sure you follow the circuit diagram I created for this project. This diagram will find details about every component’s location and where you should connect it to.

Just connect the parts that are highlighted in green using jumper wires. You can bend the wires to make them fit in between the housing and your Arduino board without causing any harm to them or their circuit.

Now you should be able to plug and play! Feel free to try out all of your sensors’ different settings and see how it works.

Step 4: Complete the assembly

Industrial pH sensor Arduino

Once you have your Arduino pH circuit assembled, you can now place your sensor in a safe environment to see how well it works. However, you don’t want to put it in the water yet because you haven’t installed the software to let your sensor know its pH level.

You can control the water temperature by sliding the potentiometer while controlling the voltage by holding down the “set” button.

Step 5: Load the code Onto Arduino UNO

You can download the Arduino code for the project from here. It’s a sketch that you can use to control your sensor.

You will have to install and run the Arduino IDE on your computer. You will also have it on your mobile phone for setting up, uploading, and testing sensors in the future.

Once you have finished installing everything, open up your Arduino IDE on your computer, select ‘File/Open and select the code you downloaded from our page.

 The code contains the description of each sensor on the Arduino board, and you can easily change it to suit your needs.

Now connect your Arduino UNO to your computer with a USB cord and then click on ‘File/Upload’ this will send the code to your sensor so that you can start testing it out.

Click ‘Tools/serial monitor’ This will open up a terminal in which you can test your sensor! Type “M50” in the terminal to heat the water at 50 degrees Celsius.

After that, check out the display, and you will notice that the LCD screen is currently on, and it says: “Temp 1.0” on top of it.

If you type “M10” in your terminal, you will notice that the temperature is now 10 degrees Celsius hotter, and the LCD screen will now say “Temp 2.0”.

Then type “M20” to see that the temperature has risen to 20 degrees Celsius.

Finally, we can test our pH sensor and see how well this sensor works! Type “pH” in the terminal, and the LCD screen will say “2.0”.

That’s how you can use this Arduino pH sensor to monitor the levels of your environment.

Step 6: Calibrate the sensor

You can calibrate this sensor so that it will be able to tell the exact pH level that is in your environment. For this part, you will need two common solutions in a range of 1-14 pH. In this case, we used a solution at five and another at 10.

Our solution at five pH was pink, and our solution at ten pH was purple. So we mixed these two solutions, and our sensor read “7”. Which means you calibrated the sensor at 7.

You can do this step multiple times to see how well your sensor calibrates and reads the pH level in your environment.

Step 7: Use your DIY pH sensor With Arduino!

After calibrating the sensor, you can use it with Arduino electronics. Here is a code snippet that you can use to see how well your sensor works:

This code will turn on (red LED on) the LED connected to your LED strip (VCC) and display “Temp” on the LCD screen. You can change these values in the sketch to suit your needs!

Now again, open up your Arduino IDE and upload this sketch onto your Arduino board.

This will allow your pH sensor to bridge your sensors and Arduino board. With this, you can control many different sensors from one device!

Now take this same code, but change the text and change it so that it says “pH” instead of “Temp.”

Then connect your pH source (a five pH) to your Arduino board. Then download a sketch from here. This will let your Arduino board be able to read your pH sensor!

Notice that when you download and upload the program, the LED light will turn blue and red when it recognizes that the sensor and Arduino need a connection.

Now type “pH” into your terminal, and you should see this screen:

That’s how easy it is to use this DIY pH sensor from Arduino electronics. You can now use it as a simple probe for your other sensors in our project.

Testing Arduino pH Tester

It is essential to test the pH sensor in different environments to ensure that it will perform well. In this part, I will show you how we tested out the pH sensor in a few different environments. This would allow you to know that the sensor is doing what it is supposed to do.

Here’s how we tested it out:

Testing pH sensor in the air

We tested the pH sensor in an open environment. First, we used a clear jar and filled it up with distilled water so that there was no conductivity of the water, and we stirred for about 30 seconds. Next, we put a piece of pH paper on top of the solution and connected an Arduino board using a USB cable.

Then, we took the sensor apart and connected it to our lab equipment. We tested the voltage output from the sensor, compared it to a known value, and found that there was about 0.1 volts difference between both of them. We then compared the results to the pH table online and found that the readings were correct!

Testing pH sensor in hard water

We used distilled water again to have no water conductivity in the jar. Next, we used a hard water solution and poured it into the jar. We then put some pH paper on top of the water and connected the other end to our Arduino board. Then we took our pH sensor apart, stripped off its casing, and put it into the hard water solution. From there, we tested both outputs from the Arduino and lab equipment.

To our surprise, both of them were about 0.02-volt difference which is acceptable for our sensor since it is an analog voltage output device. Unfortunately, we tested one previous version of the pH sensor in hard water, and it didn’t give us a reliable result, so we needed to replace it with this one since it is more precise.

Testing pH sensor in saltwater

We used the same setup again, but we used a saltwater solution, about 0.4 volts difference from our analog output device. Both outputs were still within an acceptable range, and we tested both of them using a previous version of the pH sensor in saltwater, and it also gave us similar results.

Common errors when building an Arduino PH sensor

There are a few common errors that we can find when building this Arduino pH sensor from scratch. Here are some of them:


This error happens when the code you are trying to upload doesn’t work properly. This might be because you did not implement some of your library’s functions in your sketch. To fix this problem, comment out unnecessary codes and compile and upload again.

Sketch Too Large for FLASH Memory

If your sketch is too large for the flash memory, you might get this error message, which means your sketch is too big to fit in the flash memory. To fix this problem, comment out unnecessary codes and compile and upload again. If it still doesn’t work, you can use another Arduino IDE instead of using the default one that comes with Arduino boards.

When you compile your code and upload it on your Arduino board, you might get the “Unsatisfied Link Error” message box. This means that there is a library that you need to add to the Arduino IDE before trying to compile and upload again. But, of course, you can always go to this page and download this library into your Arduino IDE to use it in your project.

Sketch Uploads Successfully, but Nothing Happens on Board

This error happens when you try to upload a sketch, but nothing happens on your board. This might be because there is something wrong with the code you are trying to upload. First, try removing all the comments from your file and then re-compile it again. If that doesn’t work, you could use this other Arduino board instead.

Serial Port Already in Use

When you upload sketches onto your Arduino board, you might get a message box telling you that “Serial port is already in use.” This might be because your IDE tried to upload on a serial port and failed because it was not connected. To fix this, try to restart your Arduino IDE by closing it and re-open the IDE.

Launch4j Error

Sometimes, when you compile your code, a Java error comes up and tells you that the Launch4j cannot run. This is because your Arduino board is not detected by your computer since there might be a problem with the serial connection between your computer and the Arduino board. Connect your Arduino board with a new USB cable to fix this problem.

Invalid Device Signature Error

This error happens when you try to connect an Arduino board to your computer, but your Arduino board doesn’t appear in the list of recognized devices. To fix this, remove the IDE, and after you reboot your computer and then re-plug it into the USB port, this should help.

The code doesn’t start on Power Reset

Sometimes, the code you put into your Arduino IDE doesn’t work when you compile it. This might be because you need to put in the PIN before starting. To fix this problem, comment out the “Serial. begin()” line by putting a “#” at the beginning of that line and then upload the program onto your board again.

Board not in sync

Your board may be out of sync with the Arduino IDE. If you can’t upload any sketch onto your board, try resetting and restarting it by disconnecting the power and reconnecting it to a new USB cable. This should sync it up to Arduino IDE to upload sketches onto your board.

Arduino Board not Recognized

This might be because your Arduino board is not compatible with this type of hardware. If you have an Arduino Uno that you cannot use, you might consider finding a different one.


Finally, we have finished our first pH sensor Arduino project. We started by looking at the basic parts that we will need for this project: an Arduino Uno and a pH sensor. After reading about how these sensors work, we decided to use the DS18B20, easy to find and cheap. Fortunately, most of the parts we used were available on Amazon, so there was no need to look everywhere to get what we needed.

After building our pH sensor, we tested both possible scenarios using hard and saltwater. We found that both outputs were still within an acceptable range from the common range of pH values. Both values were around seven and below eight, which means our sensor gave us a correct output.

Finally, we learned about some common errors and how to fix them for your Arduino project.




                Get Fast Quote Now