Controller

This is the new version of the controller that was designed during the phase 2 analysis.

Design

The schematic is shown below. 

Changes from phase 1 include support for the moisture sensors, sonar depth sensor and on board relay to switch the valve.  Unfortunately, I lost the use of the I2C bus, pins SCL and SDA, which may come back to bite me later.

As with the transmitter, I was unclear whether the RF Modem interface logic signals were 3v or 5v, so 200Ω resistors were placed inline.  The sleep signal was permanently off, while the reset line was wire to the microcontroller, to allow it to reset it on start up.

The moisture sensor wiring and functionality is described in phase 2.

Construction

The circuit board for the controller is shown below.

The board was designed to fit inside a 125 x 85 x 55mm Sealed IP65 ABS Box, #H0304, from Altronics.  The RF Modem is mounted on the lid.  This box is taller then the transmitter box so there was no issues with the modem hitting the connectors.  The PCB installed in the box is shown below.

Note the cut outs on the side of the box.  I phase 1, I used weatherproof glands to seal around the wiring.  This was awkward when installing and making modifications, so this had to change.  I wanted to use barrier terminals to connect the wires, but the screw pitch was 9.5mm and there wasn't room for 19 connections on this small box, so I created my own terminals using pluggable terminal connectors.

The plan was to use a PCB to mount the terminal blocks and mount these up against the side of the box.  A bit of silicone sealant was used between the PCB and the box.  The pluggable terminals mounted on the PCB are shown below.  The PCB is single sided, with the wires soldered to surface mount pads.

The terminal PCB was held in place with stainless steel screws.  I used a P-Touch to generate the labels.  These are shown below.

The photos below show the PCB and modem mounted and ready to be sealed.

The completed box.  Note that the antenna points down.  This is to help weatherproof it to prevent water from coming in through the antenna hole.

Firmware

The software for the microcontroller was a modified version of phase 1, adding support for moisture, and tank depth.  Additional commands were added, as well as some configuration options, additional status information.  The commands are listed in the table below.

Query This will usually be a polled query from the controlling PC, gathering statistics.  The statistics are a simple ASCII string of the form...

HighWaterMark,ValveOpenStatus,LitresSentDuringWatering,LitresSentDuringOverflow,MoistureReading1,MoistureReading2,TankVolume,Temperature

ValveOpen Manually open the valve.  (the valve has a timeout set, so it will never be open for more than 60 minutes)
ValveClose Manually close the valve.
Water nn Let out nn litres from the tank
AutoVentOn The controller will open the valve when the high water mark is reached.
AutoVentOff Do not automatically open the valve when the high water mark is reached.
Reset Reset the counters (litres sent when watering, and litres sent when overflowing) to zero.
BootLoader The microcontroller contains a bootloader, which allows it to update the firmware over the serial connection. It uses the XMODEM-CRC protocol to download the .hex file, so any serial communications software can be used (I use hyperterminal). At the end of the firmware upload, the watch dog timer is used to force a hardware reset.
TankDepth Sets the depth of the tank in cm.
TankSA Sets the cross-sectional surface area of the tank in cm2.  This is used to calculate the current water volume in the tank.
SensorDistance Sets the distance from sonar sensor to the maximum height of the water.
TempAdjust Calibrates the temperature sensor.  Using this function will calibrate the current temperature reading to be the specified temperature.  Because a LM335 is used as the temperature sensor, only one calibration point is necessary.
AutoDepthOn Automatically adjust the TankDepth and SensorDistance parameters based on measured values.
AutoDepthOff Don't do the above.
Parameters List the current parameter settings.

Source for the controller is here .

Client Software

The client software has been updated.  Firstly it needed to support more than one controller.  Secondly it need to support multiple generations of the controller.  The configuration is still mostly hard coded.

Here's a screen capture.

Watering and valve opening/closing is now done using the right mouse context menu

Source for the client is here .

The data recorded by the client software is shown here.