Tags

, , ,

Chris noted at the beginning of week 3 of Contextual Electronics the value of knowing the design behind a circuit versus settling for a complete solution from a 3rd party.  In my case, I constantly wonder – how the heck does the pH sensor figure out the pH?  And the complimentary question – same for conductivity!  My highest priority in my DIY hydroponics station is “support free.”  After shipping software for over 20 years, I realize this is impossible. However, it is an important principle.  It is always better to have intimate knowledge of what I am building.  Besides – it brings me a YIPPEE! MOMENT – so much to learn.

The Goal

The goals of this post include getting:

  • an intuitive feel for what measuring pH is all about.
  • a strong grasp of the parts that go into a pH measuring circuil.
  • Get you engaged so that together we can build and learn together.

Non Goals

  • discussing what pH values mean to a plant’s health.  This is covered in other posts.
  • a working prototype.  This post focuses on getting to know the pH circuit.
  • choice of probe.

Thanks to Those that Go Before

 Learning is amazing.  How extraordinary to be able to learn from others who willingly share their knowledge.  THANK YOU!  For knowledge is indeed more powerful than currency.  And community learning is indeed more powerful than a textbook.

  • EME Systems for a great article on the hows and whys of a pH circuit.
  • @SparkysWidgets –  I bought a pH circuit.  His phSensor schematic and blog post is all you need to get started.  Because I lack the background in electronics, I didn’t understand much of the post at first.  This got me writing out what I learned here.
  • The pH Pages – useful info on how to build a pH sensor.  
  • Chris Gammell – our very knowledgable and gifted instructor of Contextual Electronics.  A course I would highly recommend if you are interested in turning your prototypes into PCBs and learning tons about electronics along the way.  The more time I spend with Chris, the more I realize what an exceptional person – both in knowledge and in ethics – he is.  Chris is amazing at clarifying circuit concepts!
  • Dave Jones for his excellent videos on different aspects of stuff we need to know about electronics.  The recent one on Op Amps is terrific.
  • The Hydro subreddit.  Thank you to all the knowledgable folks who kindly share their experience and what they have learned.
  • The AskElectronics subreddit.  Thank you for answering questions that might seem obvious to you.  
Again – thank you.  It is a much better learning environment than what I remember 20 or so years ago.  At that time, it seemed we took “knowledge is power” to be ME motivated and not understand shared knowledge is far more powerful than ME knowledge.

The Parts of a pH Measuring Device

Not knowing much about the innards of a pH measuring device, I spent a bit of time reading up on what the heck makes these things work.  It turns out a pH measuring device consists of a probe and a voltmeter.  My apologies if you are rolling your eyes at this obvious conclusion.  Up until now, the pH was just a number on a spreadsheet.  Now I am constantly wondering why?  I’m loving the mix of life, chemistry, electronics, math and programming.  But there is a good chance you have already enjoyed learning all this – probably in 5th grade science… For others who didn’t learn this stuff but are now interested, I’ll summarize what I learned.

The probe  is a glass electrode.  It measure the hydrogen ion (H+ ion) concentration in a liquid.  The image and a better explanation can be found on this post.

glassElectrode

pH Probe (glass electrode)

When the probe is put into the liquid, the H+ ions move toward the glass electrode.  This creates a tiny current which is what a pH sensor measures.  More H+ ions scurrying about means a higher voltage, which means the liquid is more acidic.  Lower – more basic.  When I look at it that way, I can see the comparison between a pH probe and a battery.  Like a battery, a pH probe generates current.  A pH probe does this by getting the  H+ ions to scurry about.  

Like a battery, the voltage can be measured.  Voltage of electrodes is measured using the Nernst equation.  This equation is used to validate that a change in 1 pH unit occurs when  the voltage changes by -59.16mV.  pH values can range from 0 (high acidity) to 14 (strong base).  Given the pH range and the voltage change (59mV) per pH unit, the range of voltages the pH probe will read is: +/-7*59mV or +/-413mv.  At  pH 7 (neutral pH) the probe produces 0 volts.

When the voltage change is not -59.16 mV

There are two adjustments that must be made to get accurate readings:

  • temperature
  • probe degradation

The charts on SparkysWidgets post gives a nice visualization of the relationship between the pH values and temperature:


Temperature
The amount of volts between pH units  depends on the temperature of the solution.  -59.16 mV assumes the solution is at a temperature of 25°C/77°F.  Googling for the temperature coefficient returned  -0.1984 mV per °C. That makes the slope -54.2 millivolts per pH unit at 0°C, and -74.04 millivolts per pH unit at 100°C. 
Degradation
Like a battery, the voltage potential for the gas probe weakens over time.  An accurate reading should calibrate the pH readings to accommodate the degradation of the signal.  To calibrate, I need a solution known to be at pH 7 and one known to be at pH 4.  Every once and awhile – say every two weeks, – I must take a reading for these know solutions and adjust for temperature.  If the voltage of the known solutions is not 0 V for pH 7 and (59.16*4) .237V for pH 4, the readings need to be adjusted to these variances.

The Circuit

Requirements

Time to design the pH sensor.  The requirements include:

  • the voltage produced by the pH probe can be read from an Arduino Uno’s digital i/o pin.
  • “fairly accurate” readings.  A pH of 5 is only 59mV from a pH of 6.  That is a very small amount of differential voltage to measure accurately.  This is because the pH probe is made of glass which creates a very small electrical current.  This means it has a very high output impedance, typically around or more than 100MΩ. SpakysWidgets notes: “A typical probe has an impedance of anywhere between 50MΩ and 500MΩ, and since 100MΩ*1nA=.1v even having a single stray nano amp can throw our measurement off by almost 2 entire ph units.” In order to get a meaningful reading, the design must eliminate most noise and outside disturbances.
  • voltage measurements must be able to interpret both negative and positive voltages since the voltage difference is +/- .414V
  • low BoM.

The Design

Components

The requirements lead to the protagonists of the pH sensor being op amps.  I’ll use two:

  • one op amp will isolate the circuit that will be measured from the circuit that is providing the reading.  This will go a long way in preventing disturbances from being introduced by the pH sensor.
  • one op amp will amplify the signal so that it can be read by the Arduino’s digital i/o pin.
the most important characteristics of the op amp are in its abilities to be as “ideal” as possible when considering attributes that would introduce changes to the pH measurement:
  • low input bias – in the picoAmps
  • high input impedance – meaning the op amp will draw as little current as possible.  This will also help minimize changes to measurements because of the parts used.
I’ll also need:
  • an ADC to convert the incoming analog signal into a digital signal that can be read by the Arduino Uno. 
  • charge pump to handle the -5V readings when using Arduino’s 5V as the power supply.
  • some capacitors to filter out noise.

Design

Why reinvent the wheel?  Besides, at this point in my learning I am still being introduced to components and what they do.  I decided to learn the design of the circuit by walking through SparkysWidget’s schematic on GitHub.  In this section I will walk through the components I mentioned before.

Op Amps

 Op Amps are the central component of a pH circuit.  Their job is to:

  • adjust the pH signal so that it can be read by an Arduino (through an ADC).
  • filter out noise in the pH signal.

Adjust the Signal

The diagram I came up with helped me to understand what is going on.  Even though SparkysWidgets said these things, I didn’t grasp what was really going on until I broke the steps down.  The process helped me better understand the fundamentals of an Op Amp.  I’ll explain what is going on in each step in case it helps you.

ChangesToPHSignal

Before the voltage signal generated by those active Hydrogen ions can be read by the Arduino (and converted to digital from analog by an ADC), the tiny signal coming from the pH probe must be transformed into a value between 0 and 5V – the voltage range the Arduino will read.  The diagram shows this in three forms:

  • block – if the step was a black box, this is what it is doing
  • 101 – simplified “behind the curtain” drawing using standard drawing of a non-inverted op amp.
  • behind the curtain – pieces of the schematic come from SparkysWidgets schematic in GitHub.

1. Signal comes in from pH probe

I noted above that the signal created by the pH probe ranges from:

  • pH 0 = .414 volts
  • pH 7 = 0 volts
  • pH 14 -.414 volts

2. Amplify Signal

Googling for “gain op amp” gave me the formula for the gain:

Using the resistors in SparkysWidgets schematic, Gain = V(out)/V(in) = 1+R8/R7 = 1+4.7 = 5.7

Gain = V(out)/V(in) = 5.7.  Or V(out) = 5.7*V(in).  When the pH of the solution is 0 (strong acid), V(in) is .414.  When the pH is 14, V(in) is -.414.

So the V(out) based on V(in) and the Gain is:

V(out acidic pHs) = 5.7*.414V = 2.36V

V(out base pHs) = 5.7*-.414V = -2.36V 

3. Shift Signal

To read the voltage value from the Arduino, the range of readings must be between 0V and 5V.  One way to do this is to add 2.5V to the reading.  The V(out) values of the Gain op amp become the V(in) values for the offset op amp.  Mapping this to 5V and 0V:

V(high) = 5V = V(in acidic pHs) + V(offset) = 2.36V + 2.5V =  4.86V

V(low) = 0V = V(in base pHs) + V(offset) = -2.36V + 2.5V = .14V

The Arduino sketch will receive readings between .14V and 4.86V

Get Rid of Noise

Given the pH probe uses glass, it’s pretty hard to get a great signal.  On top of that, there is inevitably going to be some noise.  The standard way this gets handled is to put a low pass filter in the circuit at the spot it works best to pluck out the noise.  This is why SparkysWidgets schematic includes the 1uF capacitor on the gain op amp.

LowPassFilter

 

 

 I thought this explanation summarized how the capacitor is used to throw out high frequency noise:

lowPassFilterExplanation

The capacitor’s impedance decreases with increasing frequency.

ChrisDrawingOfImpedenceFrequency.png

Chris’s Drawing Helps See How a Capacitor Works In High and Low Frequency Signals

This low impedance in parallel with the load resistance tends to short out high-frequency signals, dropping most of the voltage across series resistor R1.

The spikes (noise) gets swallowed up by the capacitor since as the spike is winging through the circuit it wants to travel the path of least resistance.  When it has a choice between The path with the resistor and the capacitor with a low impedance, its going to choose the capacitor path.  

ADC

As obvious from its acronym, the ADC takes in the shifted analog signal coming from the shift op amp and digitizes so the Arduino can interpret a value.

Resolution

Most pH charts like this one need one decimal point resolution.  I want to be able to read a pH of 7 and a pH of 7.1 accurately.  I don’t need to distinguish between 7.12 and 7.13.

I noted earlier there is -59.16mV per pH unit when the temperature is 25°C.  The signal was then amplified by 5.7.  This changes the amount of voltage between pH units to -59.16*5.7= -337.212mV.  A pH value of 7.1 occurs at 33.721mV per .1 unit of pH.  Given that, an ADC with 8-bit resolution should be good enough.

Because I was following SparkysWidgets recommendation of using the MCP3221, I didn’t think to consider the Arduino”s ADC.  Luckily folks on the AskElectronics subreddit did:

[–]deadycool 3 points 19 hours ago

Why won’t You use Arduino’s analog inputs?

I’ll start with using the Arduino’s ADC and see if it is “good enough.”  For now I think it is.  Using the Arduino’s ADC will save a level of complexity since I don’t have to think about I2C or SPI to communicate with the ADC as well as lowers the BoM.

Which Communications Interface

If I were to use a separate ADC, I could use Serial, I2C, or SPI to communicate with it.  I’ve used Serial communications on an Arduino enough to feel I can get better accuracy over I2C or SPI.  I chose I2C because of this digikey search.  ADCs with the SPI interface were $1 or more than ADCs with the I2C interface.  It looks like the difference is a higher sampling rate for the SPI bus.  This makes sense because the SPI is a faster bus than I2C.  However, the sampling rate offered by ADCs using the I2C bus to communicate with an Arduino are fine for my needs.  A goal is to save on the BoM where it makes sense to do so.  In this case, using the I2C bus makes sense.

I’ll compare results using the Arduino’s analog input with the same part SparkysWidgets uses – the MCP3221.  The cost is $1.73 for a quantity of 1 on digikey.com.  The default clock speed for the I2C bus on an Arduino is 100KHz, which is plenty fast enough.  Figure 6.2 of the data sheet recommends 10K pull-up resistors for the SDA and SCL lines.

Get Rid of Noise

mash_taiters noted out a good “rule of thumb” : you should always include decoupling capacitors to the supply pins of ICs (usually 0.1uF). They are cheap, small, and will save you headaches.

These words of advice are retold in6.4.2 of the data sheet:  A bypass capacitor from VDD to ground should always be used with this device and should be placed as close as possible to the device pin.  A bypass capacitor value of 0.1 µF is recommended.  Adding this capacitor should handle any noisy spikes.  

VREF

The reasons I might wish to use a voltage reference IC include:

  • a stable reference voltage to measure the input/output voltage.
mash_taiters pointed out to me: “…Vcc [VDD] powers the ADC circuitry, whereas Vref is used as a comparison or reference for the input you’re measuring. For this reason you need to give it a very stable and accurate voltage…”
  • a simpler/more exact mapping from analog to digital.

kizzap noted: “As for Vref, the voltage you pick here can be very critical in determining the range of the signal the ADC can read. It can also dictate how difficult the maths will be in your code:
Say you have a 12-bit ADC. that means you have 4096 steps between 0Volts and Vref. if you have Vref as 5 Volts, you will get 1.2207…mV per step (ignoring INL and DNL here btw). if instead you use say a 4.096V reference, aside from it generally being more stable then a tap off your logic supply, it makes the maths much easier, as you will get a clean 1mV per division.”

I am assuming – I may be wrong – that using  VDD instead of including a voltage reference IC like the MCP1541  ok for this application. 

Charge Pump

SparkysWidgets uses the TPS60400.  The data sheet has a nice drawing of how to easily set up this chip within the circuit:

TPS60400ChargePump

 

The Schematic

I’ve concluded the schematic SparkysWidgets has provided to us is very close to what I would create given my new found knowledge.  So I’m just going to reference this one.  THANK YOU SPARKYSWIDGETS! 

Reflection

Thanks to those that have gone before, I found it wasn’t that overwhelming to build a pH sensor circuit.  The firmware still needs to be written.  This won’t be too difficult given the large amount of information folks have shared.  Amazing.

I thought I knew more about Op Amps than I did.  It took me a surprisingly long time to figure out what the op amps were doing and how they were doing it.  Even with the information SparkysWidgets provided.  My challenge is interpreting what is being said in the context of my new to circuits context.  I post this in case others might be in the same learning boat and could benefit from my interpretation.  Also, I am hoping folks will correct errors I have made or suggest improvements to be made.  That would be spectacular!

 

What’s Next

I need to prototype this circuit so I’ll be ordering parts and laying them out on a breadboard.

While I am waiting on parts, I will be delving into building an EC (conductivity) circuit.  I am assuming the two circuits will be similar and am excited to find out.

 

 

Thank you for reading this far.

 

Please find many things to smile about.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

V(acidic pH mapping to 5V) = 

0V = V(in base pHs) + V(offset base pHs) , V(offset base pHs) = 0V – (-2.36) = 2.36

 

Breaking down what is going on, an analog measurement is made then amplified.  This must mean an OpAmp is going to play an important role in the circuit.    The analog signal is converted to digital.  Seems like I’ll need an ADC.  Finally, a conversion function is needed.  Here is where the math comes in.  I am not strong at math so I thank Sparky for coming to the rescue.

By the way – if you are like me and new to using OpAmps, I highly recommend Dave Vewers’s Youtube video (TBD: link and name of video)  .  By watching this video you get the added bonus of learning what a “dill” is.

Sparky points out the pH is logarithmically proportional to the acidity – which is the activity of a hydrogen ion concentration.  A logarithmic relationship between a pH value and the activity of the hydrogen ions means:

For each pH step we see a ten fold concentration change, for example a pH of 8 has 1/10th the ion activity as a pH of 7.

No wonder my cucumber plant’s leaves turned yellow when it’s pH was off by over 1 step.  The poor plant was not able to take in the proper amount of nutrients.  I can see why maintaining the correct pH level is so important to the health of a plant.

To keep me from guessing, Sparky points out the logarithmic relationship is:

 pH = -log10(activity of the hydrogen ion concentration)

All this really means is when the concentration is greater on either side of the probe, the ion flow will induce a slight voltage between the probes electrodes, this voltage can swing both +/- which will indicate either an acid or base.


pH values can range from 0 (high acidity) to 14 (strong base).  pH 7 is in the middle.  Any pH reading < 7 is said to be acidic.  A reading > 7 is basic.  Sparky assures us a probe 

generates -59mV/pH.  Given that, the effective range is +/- .059*7  volts or +/- .413 volts.

 

But wait – temperature and using a worn down probe need to be taken account when making a reading.  I don’t know how yet.  Sparky is building up the suspense!

Build the Circuit

The OpAmp

OpAmpNonInverted

wikipedia article on op amp:

wikiOpAmp

While we were designing the thermocouple in Contextual Electronics, Chris walked us through the data sheet for an LM324 OpAmp.

  • Supply voltage: The range of voltage that can be measured.  The data sheet for the LM324 states a comfortable range of TBD – data sheet

In order to build an adequate amplifier there are a few consideration

s other then those pointed out by the ideal probe section. One consideration is the very high impedance that a pH probe has. Not only are the probes very high impedance they also are susceptible to noise, and the input stage is very vulnerable to drift/offset characteristics of the amplifiers used to interface the probe. There are a lot of Op-amps that can be chosen for the job, dont just look at the Input Impedance of the Op-Amp 🙂

 

A typical probe has an impedance of anywhere between 50MΩ and 500MΩ, and since 100MΩ*1nA=.1v even having a single stray nano amp can throw our measurement off by almost 2 entire ph units. The goal then is to choose an op amp that is adequate enough that will not load down the probe but that also has characteristics which will keep both the cost down and the accuracy up. When combined with the previous considerations about probe age and drift, a basic roadmap is made on how we can simply and effectively amplify and interface a pH probe signal.

 

A very basic design we can utilize is a simple unity gain amp, a buffer circuit to separate the high impedance probe from our “low” impedance multimeter. We will build this design first for a couple reasons, the first being it is an effective way to compare our probes to the ideal probe model. the second reason being its really easy to build and can take only a few seconds, and demonstrates a base for how the offset(in an inverting config) will alter the signal. While I suppose you could use an LM358 for this I would recommend at very least the ST TL072 or a CA3140 this is to be sure not to load down the probe and get false readings.


http://www.instructables.com/id/How-to-create-voltage-using-one-power-supply/

In analog synthesis, to generate almost any signal with op amps, it is necessary to have positive and negative voltages. This allows the op amp to generate a signal that spans positive and negative voltage values.



 And there it is – a YIPPEE MOMENT!

  • take an analog measurement of the voltage change two things.  Here the voltage change is between….. TBD
  • since the voltage change can be very small, magnify the change so that it can easily be read by the other chips participating in the circuit
  • convert the analog measurement to a digital measurement.
  • Apply an algorithm that takes the digital measurement and interprets it into what I am monitoring – in this case the pH value.

This is the lens through which I need to understand from a vegetable growing perspective.  The other viewpoint is the design of a pH sensor’s circuit.  As with other domains, electronic circuits has patterns.  Once I learn the pattern, I can apply this pattern to multiple scenarios.  The pattern of the pH sensor is:

  • take an analog measurement of the voltage change two things.  Here the voltage change is between….. TBD
  • since the voltage change can be very small, magnify the change so that it can easily be read by the other chips participating in the circuit
  • convert the analog measurement to a digital measurement.
  • Apply an algorithm that takes the digital measurement and interprets it into what I am monitoring – in this case the pH value.
The pattern is the one I learned in the Contextual Electronics when we designed a circuit for a thermocouple.  
 
For the pH sensor, I want to take an analog measurement of a voltage change that has units between 0 and 14.  This is not the same as what I can measure with my Arduino circuit, which is 0 to 5V.
 
 
As the SparkysWidgets post points out (and the logarithm entry in Wikipedia notes), the pH is logarithmically proportional to the acidity (activity of a hydrogen ion concentration).  SparkysWidgets tells me the relationship is:

 pH = -log10(ah)

I’ll trust this person to be right.  Sparky then goes on to say:

All this really means is when the concentration is greater on either side of the probe, the ion flow will induce a slight voltage between the probes electrodes, this voltage can swing both +/- which will indicate either an acid or base.

 

 

Speaking electronics, the pH on the left side is the voltage.

 
 

I like to divide discussion of design and functionality into:

  • The job being done.  If I don’t do this circuit, what additional work would I be doing?  The more I think of this in terms of energy I would have to spend, the more I am able to focus on the most time consuming and least desirable tasks.  I guess being lazy has its advantage when it comes to design!
  • A block diagram.  The block diagram gives me a very high level map of the modules that are needed to complete the job.   I’ll keep taking it down a level until I’m at the wire-connecting-to-chip level.
  • A Fritzing diagram.  The prototype uses a breadboard and jumper wires.  Fritzing provides a better visual and has more components for breadboard drawing than does the ECAD (?) tool I use – Kicad.  (TBD: LINK TO KICAD).

The Job

The water node reports readings and adjust the contents of three different chemistries (pH UP, pH DOWN, nutrients) in the nutrient reservoir.

The job of the water node is to :

  • report the readings of the water temperature, pH, and conductivity when it is requested.
  • Adjust the pH UP or DOWN when given a command to adjust to a pH level.
  • Adjust the nutrients when given a command to adjust to a range of PPM.

The Block Diagram

 TBD: UPDATE BEFORE POSTING

The BoM

 The price for prototype parts includes:

TBD: UPDATE FROM GOOGLE DOCS BEFORE POSTING

Part

Cost

Info

ph Kit

$105.95

See this post

EC Kit

$108.87

AtlasScientific Web Page

Water Temp sensor

$6.40

Previous post

Arduino

—-

spare parts

3 Peristaltic Pumps

$85 (3 + a little over $10 shipping)

Adafruit

3 N-channel power MOSFETs

$3.75

Adafruit

3 1N4001 Diodes

$1.50

Adafruit

1 Button

—–

spare parts

1 LED

—–

spare parts

1 1KΩ Resistor

—–

spare parts

1 4.7KΩ Resistor

—-

spare parts

Total

$307.72

 

The Fritzing Diagram

TBD: UPDATE BEFORE POSTING 

 

LED

The green LED is on when the prototype is first plugged in.  I then will use PWM to set the LED to 1/4 the full strength.  The LED will go to full strength when data is being taken or sent and then return to 1/4 full strength.

Testing the Circuit

I broke the prototype into chunks.  Testing first then adding on another chunk.

LED

 I started with the LED because this is Arduino 101 stuff.  I used the Fade sketch that comes with the Arduino IDE.

pH

I then wired up the pH sensor.  I detailed how I did this in an earlier post.  The pH circuit uses a serial interface.  This requires a TX and RX pin on the Arduino for sending and receiving data.  As shown in the Fritzing diagram, I put a yellow jumper wire between pin 13 on the Arduino and the breadboard hole. This serves as the TX line from the Arduino (RX line from the pH circuit).  A green jumper goes from pin 12 of the Arduino to the TX pin of the pH circuit.  So pin 12 is the RX pin from the Arduino. I used Atlas-Scientific’s sketch to test the circuit.  I am not testing the probe at this time – only the circuit.  I sent several of the commands listed in the Atlas-Scentific data sheet for the pH circuit.

i command (version) returns 

V4.0,8/12

EC

Next I wired up the EC sensor.  As with the pH sensor, I covered how I did this in an earlier post.  A pro of using both circuits from Atlas-Scientific is they are identical in pin outs, use a serial interface, and use the same commands.  Once I figured out how to work with the pH circuit, I already knew how to work with the EC circuit.  This allowed me to use the same sketch I used to test out the pH circuit.  The only change was setting pin 10 as the TX pin on the Arduino and pin 9 as the RX pin.

 

Now I have two chips that use the serial line to communicate.  As I pointed out in the earlier post, the serial library does not multiplex.  I’ll use a similar solution to what I did earlier.

 

Water Temperature

I wired up the water temperature sensor just as it is shown in the Fritzing diagram.  I then wrote and ran an extremely simple test sketch that just reads the temperature 5 times.  The WaterNodeTest.ino sketch can be found in the bitknitting gitHub  TBD

Pump

I have one pump set up. I’m waiting for two more from Adafruit.  All three circuits are identical.  I’ll test the other two when the parts arrive this week.  For the test of the one pump I have, I ran a very simple sketch 

How much pH Up/Down is needed per gallon?  http://generalhydroponics.com/site/index.php/resources/faqs/ph_dynamics_and_adjustment/

Answer: Start out with one milliliter per gallon. Wait 15 To 30 minutes, and test your water again. Frequently you will only need 1 to 2 ml of pH Up/Down per gallon of water. You may need additional pH Up/Down if you have hard water. The General Hydroponics Flora Series is pH buffered to facilitate keeping the pH in a favorable range.

 

 

You might consider just reading SparkysWidgets post (I’ll refer to this post as Sparky in the rest of this post.  Awkward, but I do not know the person’s name behind the post.)and ignoring the rest of this post.  It does a great job covering what a pH sensor is.  Sparky’sWidg. However, my interpretation might help others that learn through a similar lens that I use and documenting my interpretation has the added advantage of jogging my memory when I need to do so in the future.

The SparkysWidgets post (I’ll refer to this post as Sparky in the rest of this post.  Awkward, but I do not know the person’s name behind the post.) is a great source for getting the context of how a pH value is measured from the scientific and math viewpoint.

It turns out how a pH sensor gets its job done is straightforward.   A pH sensor:

  • takes an analog measurement of the voltage change between two electrodes.  This is a small value, so..
  • the measurement is amplified to be measurable within the range of +/-5V.
  • the amplified value is converted from analog to digital so that the Arduino can read the value.
  • the Arduino through an Arduino sketch reads in the +/-5V value.  
  • Calculates the pH (which includes adjustment for temperature).  As noted in this post: “The pH of any solution is a function of its temperature. Voltage output from the electrode changes linearly in relationship to changes in pH, and the temperature of the solution determines the slope of the graph.”
  • Adjust the pH based on the 
The “secret sauce” is the conversion function.

Sparky points out the pH is logarithmically proportional to the acidity – which is the activity of a hydrogen ion concentration.  A logarithmic relationship between a pH value and the activity of the hydrogen ions means:

For each pH step we see a ten fold concentration change, for example a pH of 8 has 1/10th the ion activity as a pH of 7.

No wonder my cucumber plant’s leaves turned yellow when it’s pH was off by over 1 step.  The poor plant was not able to take in the proper amount of nutrients.  I can see why maintaining the correct pH level is so important to the health of a plant.

To keep me from guessing, Sparky points out the logarithmic relationship is:

 pH = -log10(activity of the hydrogen ion concentration)

Info I got from the pH pages noted:

In theory, a pH probe produces about 59 millivolts (mV) per pH unit, and at pH 7 (neutral pH) the probe produces 0 volts. Acid pHs produce negative voltages. Basic pHs produce positive pHs.

 

pH values can range from 0 (high acidity) to 14 (strong base).  Given the pH range and the voltage change (59mV) per pH unit, I can now calcite the range of voltages the pH probe will read: +/-7*59mV or +/-413mv (.413 volts).

 

My pH sensing circuit needs to read the value the pH probe receives, magnify the reading to be within the +/-5V range, convert it to a digital signal and then then apply the conversion function.  And then – a YIPPEE MOMENT!  I can read the pH value of the nutrient bath that is feeding my vegetables.

 

 

 

 

The Circuit

I find building circuits more fun and approachable if I think of the parts as workers in a workshop.  I’m tempted to give them names like “Harry” and “Fred” but the last time I did this I got an F on a test because the teacher insisted on the Latin names for the trilobites he wanted us to identify.  So I won’t be adding this familiarity.  The workers that I need to hire to make pH sensors include:

  • Two Op Amps:
    • One Op Amp will isolate reading from measuring the voltage. Sparky notes: A typical probe has an impedance of anywhere between 50MΩ and 500MΩ, and since 100MΩ*1nA=.1v even having a single stray nano amp can throw our measurement off by almost 2 entire ph units). Because a copy of the part of the circuit that gets the reading from the pH probe is used (a unity gain buffer),   measuring the pH does not affect the reading of ion activity by the pH probe.  
    • The other Op Amp will amplify the tiny voltage change read in from the pH probe to a +/-5 v range.
  • charge pump to handle the -5V readings when using Arduino’s 5V as the power supply.
  • An ADC to convert the analog reading into a digital value that can be interpreted by the Arduino sketch.
  • Some capacitors to filter out noise.

 

 

 

Zero volts output at neutral pH (=7.0) 

Positive voltage in acids, pH<7 

Negative voltages in bases, pH>7 

Total realistic pH range is 0 to 14. 

Generates -59.16 millivolts per pH unit at room temperature (=”Nernst potential”). Note that this is a negative slope–higher pH, lower voltage. 

the full scale range is +/-0.414 volts. (+/-0.05916*7), at 25 degC. 

Temperature coefficient of the Nerst potential is -0.001984 mV per °C. That makes the slope -54.2 millivolts per pH unit at 0 degrees Celsius, and -74.04 millivolts per pH unit at 100 degrees Celsius. 

Googling for “gain op amp” gave me the formula for the gain:

Advertisements