IoT PH Regulator With Arduino and Blynk

34K12730

Intro: IoT PH Regulator With Arduino and Blynk

In this project I will show you how to build a basic pH regulator using cheap electronic components that are readily available online. The regulator can be controlled and monitored online through the Blynk app dashboard and through interaction with the device. The regulator can be used in in soil-free gardening like hydroponics and aquaponics(with other pH regulator than CO2 - don't want to grow algae with your plants), lab experiments, or as I've used it for in this project, an algae bioreactor.

The arduino code is mostly based on a bunch of example codes that I've mashed together. I'm not the most experienced programmer, so if you have some ideas about how to make the code function more optimally, please contribute!

It's a pretty simple type of regulation (no PID), but it will do its job of regulating pH in simple systems like an algae bioreactor. With this particular solution, pH is regulated DOWN with the injection of CO2(from a CO2 tank) into the system through a gas valve. When the pH rises due to the natural growth of the algae, the CO2 counteracts increasing basicity(increasing pH) by increasing the acidity of the water. This ensures that the pH is kept relatively stable at the level that is ideal for the particular organism(algae) that is growing in the system. If the pH gets too acidic (low pH) or too basic (high pH) the organism will die or will be weakened/stressed. Basically, the program will activate the valve(through a relay) when the pH goes above a certain point (the setpoint). As CO2 is injected into the system and the pH goes down, the valve will be shut off to keep the pH at the desired level.

This project is easily modifiable to use other types of components, like peristaltic pumps or liquid valves (feeding acid/base solutions) to regulate pH up or down, depending on what kind of project/system that you are using it with. It can be modified to supply both pH hightening and pH lowering agents, which can be used in gardening systems like hydroponics/aquaponics where pH can both rise and fall depending on the many enviromental factors in the system.

STEP 1: Parts

Now, the components:

You can also buy the pH probe seperately if you need a replacement. I've never needed one myself, having built three of these regulators running actively.

Notes on the arduino board type: I experienced problems with the ethernet shield and rotary encoder if I plugged them directly to the connectors on top of the LCD shield. This is likely because the arduino cannot handle the current drawn through both shields and to the pH module and encoder. Therefore I went with the Arduino mega 2560 which have some extra inputs/outputs when the shields are installed. It is tempting to go with the arduino UNO which has the exact same size as the shields, but then there will only be pins available on the top LCD shield, which will reproduce the problems. It's also more tidy to not have a bunch of wires connected right next to the LCD on the top shield. If you can find alternative ways to wire the encoder and pH modules other than connecting it to the LCD shield, then it might work on an arduino UNO, but for me it was easier to just use the mega 2560 instead. If you choose to go without the LCD shield or ethernet shield(internet through serial instead) then you should be free to use an UNO or even an arduino micro or mini if you wish.

STEP 2: Build!

Follow the wiring in the diagram, but move the 5V to the pH module next to the 5V to the encoder if you're using the LCD shield(which is optional by the way - if you don't need physical interaction with the regulator).

For the rotary encoder:

V+ to 5V on arduino

DT to D42 on arduino

CLK to D40 on arduino

GND to GND on arduino

For the pH module:

V+ to 5V on arduino

Po to A8 on arduino

GND to GND on arduino

For the relay

V+ to D38 on arduino

GND to GND on arduino

-Connect the live wire (12V) to the solenoid valve to the load part of the relay. And the other to ground from the power supply.

-Short the ethernet switch pin (ethpin in arduino code) to ground, since it's not a necessery part in most cases. Be careful to not short any other pins though.

-Stack the shields on top of the arduino so that the PCBs matches the shape of the arduino and the pin spacings on the shields matches the spacings on the arduino input pins. You can't really go wrong with this if you pay attention.

Notes on CO2 supply, couplings and more (from comment below):

The CO2 source that I used was a big CO2-flask that was already set up in the lab where this regulator is installed. I know brewing shops sell these, and it's definitely available from several other retailers.

The coupling from the CO2-flask is pretty simple. Just make sure to regulate the pressure and flow into the valve. The particular valve I'm using has a max pressure rating at 0.7 Mpa/101.5 PSI. You need an adapter to connect a pnematic/PTFE tubing from the flask to the intake of the valve. In my case I needed a 6mm tube to connect to the 1/4" pnematic coupling that I used with the valve.

Do keep in mind that CO2 is not the ideal pH regulating agent for all systems. I plan to use this same regulator in a hydroponic system with a peristaltic dosing pump that delivers phosphoric acid to the water to lower the pH.

Also, In other cases you would be more dependent on pH elevating agents to regulate the pH. It all depends if the life in the ecosystem generally lower pH or elevates pH.

I could probably make a whole instructable just for the algae bioreactor, but the idea for this instructable was to show how to build a simple and cheap regulator that can be used with any pump or valve with most pH regulating agents, perhaps with a slight modification to the code.

STEP 3: Configure Blynk Dashboard

Download the blynk app from http://www.blynk.cc/ and make yourself an account.

Make a new project in the Blynk app and e-mail the authentication token to yourself.

On the project page, install two gauge widgets:

-pH gauge connected to virtual input V0

-setpoint gauge connected to virtual input V1.

Then:

-slider widget connected to virtual pin V3- set the range from 0 to 140(will be translated to pH 14.0)

-LED widget connected to V7. This indicates if the CO2 valve is activated.

-Set up a history graph and set the first input to V0. This will show the change in pH over time.

STEP 4: Upload Sketch

Take a look at the sketch I've uploaded. I've commented in quite a bit of info about the workings of the code.

Make sure you have the Blynk and SimpleTimer libraries installed. The LiquidCrystal LCD library should come pre-installed in your Arduino IDE, but in case you miss it here's a link for that too.

Upload the sketch using the Arduino IDE. Remember to insert the authentication token from the Blynk app into the char token[] = "" field.

STEP 5: Calibrate the Sensor

Plug the probe cable into the BNC connector on the pH module and put the probe into a solution with a known pH. Adjust the pH reading, by adjusting the pot meter right next to the BNC connector, to match the known value of the solution. I used a buffer solution with a pH of 4, and once i calibrated the probe to that, I verified the calibration by using a pH 7 buffer solution. Just calibrating to any solution with a know pH should work, but it's smart to double check the true value with a lab pH probe that you know is calibrated.

Notes on calibration and measurement instability: always recalibrate the reading together with the specific power supply that you are using. This particular pH module is very sensitive to the voltage going in, and this may vary depending on the load you plug in to the power supply. So please make sure that you are putting the same load on the power supply that the electronics are plugged into throughout the period that you are monitoring the pH. I don't know how other pH modules work with arduino but the great sensitivity to small voltage changes seems to be a drawback with using this cheap chinese pH module. There could be several solutions to this, like putting in some lines of code to correct the pH value based on the voltage drop. But for now, just make sure to keep the voltage to the pH module stable by not wiring a bunch of other components with varying current drawn from the arduino. Just one Solid State Relay(SSR) wired to the relay pin to control the valve is recommended. The relay then controls voltage (12 volts) being applied to the valve outside of the arduino circuit(5 volts). Even with just the SSR drawing power, I've still experienced a very slight deviation on the pH reading by about 0.1-0.2 points. This shouldn't be issue with most applications, but it's still a pretty clear "bug". I'm going to try a fix for this using a dedicated voltage regulator to the pH module, and I will post the solution to this if it turns out to be successful.

19 Comments

Can you email me the detail of this mini project ? I can’t access the coding file
PLEASE EXPLAIN THIS PART : For the relay
V+ to D38 on arduino
GND to GND on arduino
-Connect the live wire (12V) to the solenoid valve to the load part of the relay. And the other to ground from the power supply.

i made this till that part the selonoid valve dont open . good are with skematics used ssr-80 d.thx a lot
Hello, I'm new to arduino and I am looking to assemble something like this for hydroponic systems using 2 peristaltic pumps and ph-up/ph-down solutions. My question is how difficult would it be to to alter the code to utilize 2 peristaltic pumps one adding ph-up and the other ph-down to keep the solution within a set ph range?
I am looking for the same thing

Great article about the PH0-14, which has little documentation if any.

I am attempting to take a much simpler, one that just says "time to chlorinate your spa". I am just attempting to do an analogRead(A0) from the PHO, and in "tap" water, I get ~990, but in my Spa water, it maxes at 1024. (I am using an ESP8266 and I sample the PH0 once a second and average the settings over 2 minutes).

I am trying to figure out if my sensor is defective. What are your "normal / operating" readings?

Hi!
I'm trying to do it with the same board as you (Esp8266 Node MCU). Did you succeed with this project?

I made this and it is working. But i meet one problem:

1. Mega + Ethernet + LCD shields and pin 22 not connected to GND work but did not connect to blynk!

2. Mega + Ethernet + LCD shields and pin 22 connected to GND did not work!

3. Mega + Ethernet shield and pin 22 connected to GND work and connect to blynk!

Can you help me to solve this? How can i put one serial LCD to replace the LCD shield (i did not know how to change the code and how to connect with MEGA). I power up the LCD with aux 5v and nothing change.

Thanks.

Sorry for the late reply. I remember I had similar issues, and I believe I found it was because of limitations to the current draw from the arduino mega board. Bypassing the power supply from the arduino to an external supply might help.
How stable do you find this? I purchased a tentacle shield and a ph circuit from atlas scientific because I thought I had to have isolation - I tried these cheaper ph probe circuit that you’re using and I had horrible results. Do you get the PH part of this working stable?
Please forgive the late reply. The Atlas sensor are more stable in my experience also, albeit more expensive. I've had a sensor setup with these cheap probes running for 3 months with recalibrations bi-weekly, and I would say it was accurate enough for this application. They do have a tendency to break down over time though. Around 2 out of 8 probes have broken down in a matter of weeks.
So yeah, if you want a stable and robust rig, go for atlas probes.
The arduino code where i find?
It can be found in Step 4: Upload Sketch. But be warned that the code I wrote three years ago might not be compatible with the current version of Blynk, and will need to be updated

Two who it may consern ,

Currently i'm student i wanna work on this project but i would like to change the Ethernet Child With ESP 12E wifi module. so if it may be possible please provide code and Circuit to this email itulamyafabrice@gmail.com

Those are the componet which i woul like to use

ESP 12E wifi module

pH senor

Arduino

LCD to display only the Ip Address

Arduino uno

can I connect pH, temperature, voltage, current, free chlorine and conductivity sensors to Arduino. would you help me in this.

Hi.

There arer two potentiometers on the PCB. What's the role of the second?

Great work on the writeup, could you also include step details for the CO2-supply and couplings you are using?

​Thanks for your comment. :)

The CO2 source that I used was a big CO2-flask that was already set up in the lab where this regulator is installed. I know brewing shops sell these, and it's definitely available from several other retailers.

The coupling from the CO2-flask is pretty simple. Just make sure to regulate the pressure and flow into the valve. The particular valve I'm using has a max pressure rating at 0.7 Mpa/101.5 PSI.

You need an adapter to connect a pnematic/PTFE tubing from the flask to the valve.

Do keep in mind that CO2 is not the ideal pH regulating agent for all systems. I plan to use this same regulator in a hydroponic system with a peristaltic dosing pump that delivers phosporic acid to the water to lower the pH.

I could probably make a whole instructable just for the algae bioreactor, but the idea for this instructable was to show how to build a simple and cheap regulator that can be used with any pump or valve with most pH regulating agents, perhaps with a slight modification to the code. ;)

Also, In other cases you would be more dependent on pH elevating agents to regulate the pH. It all depends if the life in the ecosystem generally lower pH or elevates pH.