MCP3208‐Based Analog Sensor Interface - Digital-Waters/WaterMonitorDevice GitHub Wiki

Introduction

This page summarizes the basic design and implementation of an analog probe interface through a Microchip MCP3204/08 Analog-to-Digital Converter (ADC) to a Raspberry Pi.

Theory of operation

Analog glass bulb probes for pH and ORP measurement use a reference electrode in a reference solution compared against a test electrode in a permiable glass membrane (glass bulb). The glass bulb is placed in the test solution and the measured ions are able to pass through the permiable glass membrane and interact with the test electrode. This creates a potential (voltage) difference between the test electrode and reference electrode. Since this voltage is directly proportional to the ion concentration in the test solution it can be used to determine that concentration. The resultant output voltage can be both negative and positive for both pH and ORP.

In order to digitize this signal it must first be offset and amplified through a low noise, high-impedance, low drift amplifier. Offset means that the voltage from the probe is added to a stable reference voltage that is half the circuit supply voltage. This means that it can swing as much as possible between 0 V and 5V (the circuit voltage). Amplified means that the signal is intensified so that instead of the lower voltage swing (+-0.8V for pH) it swings as close as possible to 0 and 5 volts so that the digitizer circuit can get as much signal as possible. Low noise, high-impedance, and low drift are characteristics of the amplifier which essentially means that the amplifier will distort the actual signal as little as possible.

After this, the signal is fed into a 12-bit analog-to-digital converter which transforms the analog signal into a digital number between 1 and 4096 (2^12-1). Since the signal has been offset by half the supply voltage (2.5V) the signals that are fed into the CPU from the ADC will be symmetric about the half-voltage equivalent digital number (4096/2 = 2048). That means that positive outputs from the probe will be higher than 2048 and negative outputs will be less than 2048. Each bit of a 12-bit ADC value is the reference voltage divided by the resolution of the converter so in our case LSB = 5V / 4096 = 1.22mV

The full conversion formula also taking into account the offset voltage of +2.5V is:

Vsense = ADC_VAL * 5V / 4096 - 2.5V

Basic Setup

The components used in this design comprise:

  • An MCP3208 ADC converter (Link)
  • An OPA1278 Dual Op-Amp (Link)
  • An INA333 Zero-Drift Monolithic Instrumentation Amplifier (Link)
  • A REF3425 2.5V Low-drift voltage reference (Link)
  • A Raspberry Pi Zero/W (Link)
  • Measurement Probe (pH or ORP glass bulb type. Link). You can also use a 0-5V floating variable voltage supply here instead.
  • Various SMD to DIP carrier boards + header pins if necessary
  • Breadboard + Jumper wires + 5-position Male-Female ribbon cable or M-F jumper wires
  • 1x 47k 1% metal film resistor
  • 4 x 1uF/16V+ electrolytic or ceramic capacitors
  • 1 x 10uF/16V+ electrolytic or ceramic capacitor
  • 2 x 0.1uF/16V+ electrolytic or ceramic capacitors
  • A 5V DC supply (while it is possible to run the circuit directly from the RPi's 5V header pin, this can put stress on the USB power supply used to power the Pi)

For breadboarding, carefully solder each SMD component to an appropriate DIP carrier board. Also solder in the header pins. In order to keep the pins straight, I like to place the headers into a breadboard and then place the carrier board on top before soldering in order to keep everything correctly spaced and square.

IMG_20250426_122221 IMG_20250426_123108 IMG_20250426_123120 IMG_20250426_123319

Schematic / Circuit layout

pH_Analog MCP3208_Base REF_2 5V

For the purposes of prototyping, then GND and Analog_GND are the same signal. Also the +2.5V_REF and Vref_2.5V are the same. The power supply rails are (poorly) decoupled using 1uF and 0.1uF capacitors. The VRef input and output on the REF3425 (incorrectly labeled as 3025 on the schematic above) use a 1uF and 10uF capacitor on the input and output, respectively. For better performance, add additional 1uF and 0.1uF capacitors to the supply rails near each IC. Thee are ommitted for testing and breadboarding purposes because breadboarding...

Because the sampling frequency of this circuit is essentially DC, and to simplify the prototype, there is no anti-aliasing filter at the input to the ADC. For better noise performance and increased sampling throughput, an appropriate passive or active RC filter should be placed directly before the ADC input pins.

BreadBoard_ADC_IFC drawio

RPi_SPI_Pinout

Connect the SPI output from the breadboard to the Raspberry Pi GPIO header as shown in the table below.

SPI to RPi Header

Breadboard RPi Pin Name RPi Header Pin
SPI_GND GND 39,34,30,25,20
SPI_SCLK SPI0_SCLK 23
SPI_MISO SPI0_MISO 21
SPI_MOSI SPI0_MOSI 19
SPI_CS SPI0_CE0 24

For the GND pin you can use any one of the RPi ground pins. Listed above are just the ones I found most convenient.