EC and PH sensors for Arduino

Vladimir Akopyan
Quickbird
Published in
6 min readOct 23, 2016

--

We had to test our data platform — the app, the cloud, and all the rest of it — with some real data. To do that we’ve put together a miniature SensorBox for greenhouse. The thing consists of a microcontroller and a lot of sensors: temperature, humidity, EC (electrical conductivity) of the solution used to feed the plants, etc. Ph and EC are the ones that required the most thought, so I decided to write an article about them.

EC and Ph probes (the bits that go in the water) typically can’t be read directly with a microcontroller. They require an analogue circuit to drive them, pick up the signal and boost into range where a microcontroller’s ADC can measure it. We tested several pieces of kit before we settled on our current setup, and decided to share the experience.

DFRobot Sensors

These guys make a huge selection of various Arduino shields, boards and sensors, and their kit is of high quality. We’ve now been using their parts for almost a year in several projects, operating 24/7. We stumbled upon them while looking for EC and Ph sensors.

They sell probe and the circuit together, moderately priced, at~ £45 for PH and ~ £60 for the EC kit. They work well, and most importantly all of their kit is well documented! The Ph sensor outputs voltage linearly proportional to the value it is measuring— so if the voltage registered is 0, Ph is 0, if the voltage is max, Ph is 14, etc. Reading the values is nice and easy.

To get values for EC you have to use a formula but nothing too complicated there. It also compensates for variations in temperature. You can literally copy-paste code from their Wiki and it will work.

Electrical Conductivity meter (left) and Ph meter (right) modules from DFRobot. Pictures stolen from DFRobot website.

There are a couple of downsides to this kit:

  • These are 5 v parts, and all the ‘smarter’ micro-controllers are now 3.3 volts. Even micro-controllers with 5 v tolerant pins can’t be used — they become ‘intolerant’ in ADC mode, so it limits your options. This annoying because we love Mbed and recommend everyone that got comfortable with Arduino to advance to this framework
  • Although the Ph meter comes with an industrial grade electrode, the EC meter does not. It’s a lab-grade probe, a fragile glass piece. We are looking for something robust that can take some rough handling.
    The problem is easily solved by replacing it with E201WM or another conductivity electrode. EBay is full of them.
    We spoke to DFRobot and MOQ on the analogue board alone is something like 60.
  • While measuring conductivity, the EC meter emits electric pulses that travel through the water and cause the Ph electrode in the same tank to produce garbage readings that oscillate wildly. This is a ‘feature’ inherent to measuring conductivity, and is unavoidable. You have to sequence the probes: EC off and Ph on, Ph off and EC on.
    Unfortunately these boards do not have a control pin that would allow you to turn them on or off. We considered powering them directly from a pin on Arduino, and shutting off the power when necessary. We measured their power consumption at roughly 18 mA and 20 mA — this is at the very upper limit for Arduino and way higher than what finer microcontrollers can manage.

Cooking-Hacks Sensors

If you follow IoT space, you probably know Libelium, who offers kits and sensors for everything they can. This is their consumer-ish arm, and they offer kits for Hydroponics. Out of the whole kit, the only thing that interests us is the hydroponics board. There are two reasons why we used this board:

  • It allows use of the Ph sensor and EC probe together, because it has a control signal to turn each on or off without having to shunt the whole power supply.
  • You can buy it separately for about £40 (beware! There be unholy VAT and Shipping charges!). So you can use it with whatever Ph and EC probes you need.
Picture stolen from Libelium website

The downside is that their documentation is rubbish.

The guides for Aquaponics and Hydroponics are big blobs of text and look like they were written by Microsoft: Plug this in here, copy-paste this code, see it works! No real explanation.

The board has an awkward form-factor because it is meant to be installed on their shield. We have no interest in buying that shield and very helpfully the pins are not marked.

The first thing to do was to figure out the pins used by the board. So we read through the code in their library it’s easy to follow.

Despite having 14 pins, only 6 of them are used and they are pretty random. First of all, the EC probe is connected using a screw-terminal. On the other hand the Ph probe is connected using an SMA connector. Yeah, the one usually used for antennas. God knows why.

The board also has no screw-mounts or attachment points except for the pins.

Board from below with all the connections marked.

Other than having to put up with these awkward mounting options, the hardware is good. Code found in Libelium library can do calibration as well as measurement. We found it to have good accuracy, and the range of measurement is very high, although because of this the resolution is a little coarse on Arduino with it’s 10-bit resolution.

If you use this board, we recommend crimping jumper cables to make a reliable connection, and getting an SMA to BNC adapter like this one, or this one if you are putting your project into an enclosure.

Fortunately the cooking-hacks libraries are licensed under GNU, so here is our adaptation of it to read the EC sensor. We’ve placed all the code into a C++ class that you can #Include in your Arduino program, and you can find code at the end of this blog.By the way, GNU also means you have to make your changes public!

Throughts on Atlas Scientific

These guys seem to be making high-end and expensive kit that we never got round to testing.

They have a nice Arduino shield with BNC connectors, that you can use to attach any of their probes. For each probe, there is a slot. Into the slot you insert one of their boards. Each board includes a PIC microcontroller and some electronics for taking a reading.

This is a really nice system, if a little wasteful. Support of 3.3 V makes the shield compatible with pretty much anything, you don’t even need an analogue input. You talk conveniently to them through serial or I2C from Linux on Raspberry Pi or another single-board computer.

This isn’t our cup of tea. When designing our system, we built it so that the microcontroller could operate completely independently. Even if the operating system becomes corrupt, unresponsive or catches fire the MCU will continue operating in accordance with the last settings that were saved to it. It has, so far, been working for months and probably will work further.

Other interesting kit:

Spear PH probe for insertion into solid substances.

We accidentally stumbled into what looks like a high-quality fish-monitoring device. Seems lively, we should try it some time.

Issues we still haven’t figured out:

Other probes we’ve been looking at are dissolved Oxygen and Nitrogen probes. So far all the kit we’ve found is really expensive, and we are not sure if the price is justified.. If anyone has worked with them before, we’d love to get in touch.

Code for Ph sensor:

Code for Ec Sensor

--

--

Making Internets great again. Slicing crystal balls with Occam's razor.