Monday, September 4, 2017

Well Pump Monitor, Arduino Style

I recently had a failure in my home's well line causing water to appear in places it shouldn't. I can't hear my pump (or any associated plumbing noises) when it runs so I says to myself, "Self, wouldn't it be nice to baseline your pump's activity and issue an alert when something is out of the norm?" The answer was "Yes".

So what do you need? Here are the big chunks:
 All put together it looks like this:
Arduino stack

and
Snap on Current Transformer

to give you this
A/D Debug and Pump Run Time Data
and this.
Splunk Dashboard

I'll elaborate on the above.
  1. The Arduino and the two shields with a temporary USB cable to upload new software and get debug info on the serial port. Next up is the data logger board with a micro-SD card and adapter, and battery for the real-time clock. Then the Proto Shield with some LEDs and buttons, my resistor network, some JST connectors.
  2. The current transformer hooked into my pump's junction box in a most ungraceful manner. I read about 7-8 Amps AC steady state with a clamp-on meter. I didn't see any appreciable in-rush current on startup so I designed for 9 Amps. That CT's turns ratio is 1:2000 so I get 4.5 mA AC on the secondary.
  3. There's the debug info. Every two seconds I take 20 analog samples over approximately one 60 Hz wave, track the max and min values and generate a "delta" value which I use to determine if the pump is on or off.
  4. I pull the SD card periodically, chuck it into the computer and slurp the data into Splunk's free Enterprise version that lets me run queries and generate statistics and visualizations.

The Design

Okay, I've got 4.5 mA AC (RMS) coming through the Current Transformer (CT) through an 11 ohm burden resistor (10 ohms used in the datasheet, 11 as measured). That gives me 4.5 x sqrt(2) x 2 x 11 = 140 mV peak-peak. That's not a lot of voltage compared to my analog reference voltage reference (AREF), but as it turned out, that was plenty for on-off sensing.

I need a DC offset so I can read the negative voltage swings. I went for a 150 mV centerline with +/- 70 mV swings.
LTSpice: Sense Circuit, Primary=8A AC


I tried to tie the 300 mV DC at R2+ to the Arduino's AREF pin to give me more resolution That was an unmitigated disaster. Analog reads were maxed out. Arduino's reference page says 0-5 VDC for AREF. ATMega328 refs says AREF >= 1.0 VDC. I used the Arduino's analogReference(INTERNAL) for a 1.1 VDC reference.That worked.

The V2, AREF, Rint section models the internal Arduino circuit as I understand it. Ignore it.

Here's the simulated waveform with the pump drawing 8A AC.

LTSpice: Similation

 Construction

 I used a JST connector to connect to the burden resistor.

DO NOT use the CT plug as a disconnect point while the CT is in place. Like all good inductors, the coil will generate the voltage needed to move that 4.5 mA current - something will suffer! Let it go through the burden resistor and everyone will be happy.

I also used JST connections for my Digital I/O / PWM connections just in case I wanted to swap anything around later.

The CT cable is terminated in a 1/8" (3.5 mm) stereo phone jack.The ring (center section) is not connected. The tip and shield connect to the CT. I used a mini-phone jack to RCA plug adapter which gave me the CT circuit on the Left stereo channel. I soldered the 11 ohm burden resistor across the RCA jack terminals along with my twisted pair wire that goes back to the two conductor JST plug.

You may want to use Fritzing to layout the construction of your proto board.

Mounting

First off, You could DIE!

Okay, that got your attention I hope. If you're not well versed in household electrical circuits, find someone who is. Your fixture could have exposed conductors that expose you to high voltages and currents - enough to kill you.

Generally speaking, this is a safe project. The transformer circuit is isolated from the high voltage circuit. No component is inserted or spliced into the path of the monitored circuit.

The CT installation picture was taken at the prototyping stage. You should route your CT cable out of your junction box (or whatever) in a professional manner and preserve the safety factor provided by those fixtures. Note that NEC code or local restrictions may influence how you install the CT, or if additional insulation for the cable is required (spec'd Insulation Resistance is 500 VDC, 100 MOhm min).

The CT connection should be fixed and enclosed to prevent the burden resistor from being disconnected from the CT. That's why I have the JST connector on the Proto Shield.

The Arduino stack should be encased and mounted.

Readings

I captured debug info for a while to confirm my A/D readings, delta calculation, and threshold for on/off transitions:
Splunk A/D Metrics
What this gave me over the course of 200,000+ readings was:
  • analog reads while off are 138 & 139 min, and 139 & 140 max. 139 == 149.5 mV.
  • absolute min max reads of 60 and 218 (64.5 and 234 mV, +/-85 mV)
  • delta values of 0-2 when off, and 44-127 when on.
 My on-off threshold of 12 worked well enough.

My choices for the resistor network (4.7k, 150x2 ohm) were based on my practice of designing for 1.0 mA current. That's could be reduced for extended battery use by increasing/changing the resistor values and using the 3.3 VDC supply. Adafruit has a 9v battery cases and clips that terminate with the 5.5 x 2.1mm barrel power plug.

Miscellaneous Parts

Other needed items:
  • burden resistor
    • 10 ohm resistor (1/10 W or more)
  • resistor network
    • 4.7k ohm resistor (1/10 W or more)
    • (2) 150 ohm resistors (1/10 W or more)
  • filter capacitor
    • 0.47 uF or less, tantalum (5V or more)
  • CR1220 battery for the RTClock
  • SD card for data logging. Any minimal size will give you ample storage for months or years
  • components for CT cable termination
    • mini-phone jack to mini-phone|RCA|whatever socket
  • JST or other quick disconnect connectors. 0.1" terminal spacing for the Proto Shield
  • piezo speaker for audible alerts (stake connectors soldered in for PC speaker, not used yet)
  • LCD display shield (optional) with 5 buttons gives you lots of display options.

Other Thoughts

I use the red LED for initialization error blink codes. I flash the green LED to signal a successful startup, and turn it on while the pump is running.

I originally intended to do more statistical analysis on the Arduino, beep the PC piezo speaker, and flash the red LED to alert me to anomalous conditions. For the moment, I'm using Splunk to develop my baseline.

I could add wireless/wired networking to this, or use a Raspberry Pi or any number of other microcontroller boards. But the SD card solution works well enough for now. The Uno is a simple, versatile development platform. I like the single purpose-ness of it.

My new replacement Arduino Uno R3 came from Digi-Key (#1050-1041-ND) and is the SMD version. It comes with a plastic backing plate snapped into the Arduino which protects it from shorting out on the backside. The headers are labeled with the pin designations. I like!

I just stumbled upon what may be a safer, cheaper, and better current transformer. The configuration is very similar but it has a built-in burden resistor so the mini-stereo plug can be disconnected while the CT is installed. It also has better insulation, and spec'ed frequency and mechanical strength. 0-100 Amps AC on the primary yields 0-1.0 Volts AC on the secondary, thus producing almost twice the voltage of the SparkFun 30 Amp CT. The turns ratio and load resistor values are not specified. The resistor network would have to be redesigned for a higher DC offset.

The Code: My Arduino code needs some clean-up. Mostly because my timebase is messed up given the amount of  time needed for the analogRead() calls. This falls under the category of "good enough for now" given my queue of other projects. I can post code snippets, the LTSpice file, Splunk queries if/when needed.

Other Applications

The current transformer can be used to sense AC current in any 120 or 240 VAC household circuit up to 30 Amps. Current values other than my 8-9 Amps may require adjustment of the burden resistor, DC offset, and analog reference voltage. Other possible uses:
  • pumps
  • motors (not recommended for 3-phase)
  • fans
  • resistance heaters
  • hot water heaters
  • HVAC equipment
Enjoy!

No comments:

Post a Comment

Micca OriGen G2 DAC Problems

The Micca OriGen G2 is a premium DAC, preamp, and headphone amp primarily intended to be connected to a PC. The Problem & Troubleshootin...