PH Regulater/Meter - Arduino

Introduction: PH Regulater/Meter - Arduino

About: Third year Electrical Engineering student at California Polytechnic State University

***If photos and links are not appearing, refresh the page

This is an instructable for an arduino pH regulator or meter:

--- The regulator is meant for reactions that start at a certain pH and naturally decrease/increase in pH due to the reaction. However, for many reactions, it is desired to stay at the starting pH. So, if the reaction deviates too far from the desired pH, this arduino project will pump in acid or base to bring the pH back to normal.

--- This project can also be used just simply as a pH sensor that reads pH of any solution.

Step 1: Necessary Materials

-Arduino Uno

-Computer and keyboard

-12V Peristaltic Liquid Pump

-Analog pH Sensor / Meter Pro Kit for Arduino

-I2C 20x4 Arduino LCD Display Module

-IN4001 Diode

-PN2222 Transistor

-12V DC Power Adapter

-Male to Female Jumper Wires

-Male to Male Jumper Wires

-Alligator Clips

-Arduino USB Cable


Step 2: Solder Diode Between Prongs of Pump

Solder the diode between the prongs of the peristaltic pump as pictured. Be sure to put the silver band of the diode pointing towards the (+) prong of the pump. This will protect the motor of the pump.

Step 3: Wiring Up the Hardware

A4 -------------------- to the SDA of LCD

A5 -------------------- to the SCL of LCD

GND ----------------- to GND of LCD

5V -------------------- to VCC of LCD

A0 -------------------- to middle prong (base) of transistor

GND ----------------- to **left prong (emitter) of transistor, **referred to flat side of transistor

(-) prong pump ---- to **right prong (collector) of transistor

(+) prong pump ---- to Vin (12V)

A3 -------------------- to signal wire (blue) of pH meter

5V -------------------- to (+) wire (red) of pH meter

GND ----------------- to (-) wire (black) of pH meter


***See photos for more detail

Step 4: The Code

There are 2 versions of the Arduino Code file attached... one is for regulating reactions that are increasing in pH, and the other is for reactions decreasing in pH



Download the needed libraries (zip attached in this instructable)

This code uses an LCD library that is not already included on the Arduino...

To implement this zip file into your project, download to your computer,

In arduino window, go to "Sketch" --> "Include Library" --> "Add .ZIP Library"

Step 5: Important Note -- Serial Monitor

This program uses a Serial input to drive the menu screens. This means that it will need to be connected to a computer or laptop during use. To operate the serial monitor, click the top right button (looks like a magnifying glass) on the arduino window.

***IMPORTANT - use "Autoscroll", "No line ending", and "9600 baud" options on the serial monitor screen... if you do not, the code will not perform as designed

To input values, type a value in using your keyboard and press the enter key, or click "Send"

Step 6: Adjusting the Code to Your Regulator Needs

There are very simple constants that just need to be changed to make sure that this program works for you! Below are the recommended constants to change and their descriptions:

-- fillTime : how long it takes your pump to completely fill with liquid, in seconds

-- delayTime: how long you want the regulator to wait before pumping in more solution

-- smallAdjust: number of seconds you want acid/base to be pumped in when pH deviates by 0.3 - 1 pH

-- largeAdjust: number of seconds you want acid/base to be pumped in when pH deviates by > 1pH


In addition, you will need to figure out what offset and slope your pH meter has...

If my slope and offset does not work well with your pH meter, you will need to take the following steps:

(1)-- set slope = 1 and offset = 0

(2)-- take and record pH readings in solutions of exactly pH 4, pH 7, and pH 10

(3)-- Create a system of equations like so:

(actual pH 4 reading)*slope + offset = 4

(actual pH 7 reading)*slope + offset = 7

(actual pH 10 reading)*slope + offset = 10


Use these three equations to find a best fit line to solve for slope and offset and change these constants to your new slope and offset values

Step 7: Video of the PH Regulator/Meter With Calibration Feature

1 Person Made This Project!


  • Tinkercad to Fusion 360 Challenge

    Tinkercad to Fusion 360 Challenge
  • Colors of the Rainbow Contest

    Colors of the Rainbow Contest
  • Pets Challenge

    Pets Challenge



9 months ago

Hello, how can i tweak the code without passing serial monitor? What i want is that code continue without key 1or 3 in my keyboard....thanks for your help.


2 years ago

Being a busy person and all, I am weighing the options of a manufactured pH controller versus learning Arduino coding and making my own. The manufactured ones seem to follow the same principle as yours, i.e. when the pH reaches a certain limit, the pump kicks on for a pre-determined amount of time. This will not work for my application as I am trying to control the pH of a reservoir that will always have fluctuating levels. At 100%, 10 seconds of pump run time may work, but at 20%, it will be a constant battle of pH up/pH down. pH always drifts up so only one controller should be needed.

For example, I am looking to control pH constantly at 4.3, but a range of 4.2-4.4 should be acceptable. Is it not possible to code in Arduino to say, pump turn on when pH drifts up to 4.4 to add acid, and pump turn off when pH goes down to 4.2? I am sure hoping so, and from what little research I've done on the topic, it appears this should be no problem. But if this seemingly-simple function is unattainable in Arduino, that is definitely a deal breaker.



Reply 2 years ago

This should be attainable. I would store a variable that will be your "pump control", that will equal either a 1 or 0 at any given time. 1 meaning pump should be on and 0 meaning off. When you start the program, initialize this variable as a 0. Then inside the program loop, I would just have one "if elseif" statement like below:
if (ph reading > 4.3)
pumpControl = 1 (turn on pump control)
else if (ph reading <= 4.2)
pumpControl = 0 (turn off pump control)
This will accomplish changing the state of the pump only if it is outside 4.2-4.4... if it falls between those values, nothing will change and the pump will remain in its last state (either on or off depending on what happened in its last loop).

Then, at the end of the loop I would do an "if else" statement to actually use the control signal to turn on or off your pump:
if (pumpControl = 1)... you might need == here but I forget the exact Arduino syntax
turn on pump
turn off pump

Hope this pseudo code helps out your understanding, and I hope I was able to answer your question!


2 years ago

This is great work - I am a chemist and looking forward to trying this. I am newish to arduino and electronics. I am also a lecturer and you have explained this really well. The code used is very useable. I intend to use only the parts that calibrate the pH meter and then take readings.


Reply 2 years ago

Thank you! I appreciate the feedback


Question 2 years ago

How can you give the formulas in the program? Can you give me documents about it? This is my gmail: . Thank you !


2 years ago

It does not work to me!


3 years ago

This is the best instructions that work ever. I made this controller with little t rubble. Thanks


3 years ago

Many interesting applications for this project such as:
Chemistry research
Water treatment

On the chemistry side we can also fine tune the controls using different types of acid and base at different concentrations.

A process that needs two way pH control can use two of these controllers. one running acid and one with base. Remember the code needs a slight tweak depending on if u are trying to increase or decrease pH!

Thanks a lot for the great work DJ!


3 years ago

Interesting project!


3 years ago

Very nice! Thanks for sharing your project!