Introduction: IoT PH Regulator With Arduino and Blynk

About: Maker and founder of Apolonia Aquaponics (www.fb.com/ApoloniaAquaponics)

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.