# RPi - Automated watering system (Design)

#### Litch

Joined Jan 25, 2013
85
This is all just theory at the moment, thought I'd post it to my peers for review before I actually commence design (and maybe get some pointers).

So the idea:

I've got quite a few chilli plants growing outdoors at the moment and because of work I don't always get to water the bloody things (interstate trips etc..) - and the LOVE water and heat (Chillies are mostly tropical).

So the theory is to throw together a small (cheap-ish) monitoring system that will detect water levels and water (via electronic solenoid) accordingly.

Ultimately, to measure water content in the soil, and water it when required.

[The RPi and it's limiations]
I've got like 4 x RPi's laying around doing nothing (and a few more doing other tasks) so it just makes sense to utilise one of them for this project - but there are some caveats to take note of:

#### tshuck

Joined Oct 18, 2012
3,534
Growing some ghost peppers too?

I did this with a smaller setup with a PIC.

For the sensors, I used wires encased in Plaster of Paris, I did this because soil has a variable number of ion in it, affecting conductivity, making any reading from two electrodes subjective at best. I heard that Gypsum will absorb water and change its conductivity reliably, well, as reliably as any DIY moisture sensor anyway. Plaster of Paris uses Gypsum in it, so there we go, a moisture sensor. They do break down after a while though and need to be replaced every so often.

As far as the control goes, I tend to agree with the others, the RPi is overkill, but, as you said, you'd like to stick with it...

You could employ wireless sensor modules that would take readings and transmit them using your favorite wireless technology to the RPi, which could be in control of the rest of the process, relays, timing, etc. this would, however drive up the cost and time as you would need some sort of controller to figure out when to transmit.

Maybe you could employ some sort of differential signaling(i.e. RS-485) with the RPi, this would allow you to extend your range considerably, but I don't know much about RPis yet, so I don't know if this is possible or not. At the very least, you could use I2C to talk to a transceiver.

On a side note, how big is your setup?

#### nsaspook

Joined Aug 27, 2009
8,513
Maybe you could use SPI instead of I2C because SPI is unidirectional, can be easily buffered with cheap IC chips and used with slow clock rates (down to 3.814 kHz) to extend range. I have some RPi GPIO/ADC SPI interface module code that might be useful for linux hardware interfacing.

#### Litch

Joined Jan 25, 2013
85
On a side note, how big is your setup?
Thanks for that tshuck - that helps!

As for the set up, there are 4 of 650mm x 350mm "tray" pots filled with Thai/Birdseye/Cayenne/Carribbean. Habaneros are still germinating, a couple of large pots with black-Thai chillies and a couple with Jalapenos

I'm yet to get some bloody Ghost (Bhut Jolokia) seeds that germinate!

And thanks to nsaspook as well - I'll check that code out later.

But for now - this is the initial circuit (Image and application file); model numbers are mostly provided (circuit made with ExpressPCB; because then I can just order a couple via that program).

#### Attachments

• 93.1 KB Views: 55
• 25.8 KB Views: 27

#### KnRele

Joined Jan 7, 2013
20
Some time ago, I had a similar idea, to automate watering of my potted plants when away for some time, much along the same lines as discussed here: have humidity sensors and start running water with a pump or a solenoid valve when the soil was dry.

I made a soil humidity sensor from two pieces of stainless-steel threaded stock -- two stainless-steel forks would work just about the same -- where I used this as part of a voltage divider. To avoid problems with corrosion and migrating ions or any such, I would briefly apply a positive voltage, then measure the attenuation of the voltage divider with an A-D converter; then I would apply a similar negative voltage, and measure the attenuation for that polarity as well.

The schematic of this is similar to the one I have attached here. Here, the controller drives the Enable and Select inputs of a 4053 from two of its GPIO lines, configured as outputs, so that it can turn on the positive or negative voltage as desired. The voltage-level conversion from 3.3V to 7.5V is done with NPN transistors (2N3904) -- R2 and R5 will make sure the transistors are off when the GPIOs are configured as inputs.

The two resistors R7 and R8 form a voltage divider, together with the unknown resistance in the soil. If this is dry, its resistance is high and the output voltage should be close to plus or minus 3.5 V.

R9 and R10 scales a +5V to -5V input range to the proper 0 to +5V range that the ADC can handle. R11 and R12 and the two diodes serve to protect the ADC if for some reason the op-amp should be forced into saturation and give voltages outside the range of +5V to -5V. I used a TL082. (the unused half should be configured as a voltage follower, with the output connected to the non-inverting input, and the inverting input connected to 0V)

The controller that I used was a Picotux and the ADC was a PCF8591, which connects via I2C. A Raspberry Pi would work just as well with the PCF8591.

Other alternative devices which already have both the digital outputs and the analog inputs would be any one of the several Arduino variants, or any of a number of the more capable PIC microcontrollers, the PIC16F690 for example.

#### Attachments

• 31.3 KB Views: 69

#### Litch

Joined Jan 25, 2013
85
Brilliant KnRele, I didn't even think of that (momentary measurement, with opposing polarity).

Think I need to go back to the drawing board.

#### MrChips

Joined Oct 2, 2009
23,931
Right idea but way too complicated. Use two I/O pins from your MCU and connect your soil sensor wires there. Connect a capacitor in parallel with the wire and measure the time constant of the combo.

#### Litch

Joined Jan 25, 2013
85
Because the RPi doesn't do timing via "cycles per MHz" very well, and could well be far off depending on process load since it's all scheduled from the Linux Kernel - especially in the vicinity of sub-100ms. As such, I've added an NPN in there to "Turn on" the sensor current. Not ideal, but it should significantly reduce any corrosion, and since any measurement cycle would be in the range of at least 30 minutes, and a duration of 1 second, the impact should be minimal.

Also rearranged some components.

Revision 2 - Changelog:
* ADC moved closer to probe pins
* Darlington moved to where more appropriate
* Power diode added for common ground to prevent back flow
* BC548 NPN added for sensor current on/off
* 330R resistor added in-line to NPN base pin for current limit.
* Swapped out 100uF Tant for Electrolytic (Cheaper, more appropriate)
* Swapped out the ULN2801A with a ULN2803A (Has inbuilt resistors for 5V TTL, which is more suitable for the RPi 3V3 logic; diagram doesn't show new part number).

Component Datasheets:
The rest are pretty well known.

#### Attachments

• 116.9 KB Views: 59

#### Litch

Joined Jan 25, 2013
85
Parts and board are ordered - will let you know how I go.

#### Litch

Joined Jan 25, 2013
85
First proto (Apart from the whole power circuitry being wrong) the LM7805 1.5A VREG gets rather hot, so much so that I've raised it to stand vertical and put a heatsink on it.

Still gets too hot.

That's with a 9V 2A DC SM PSU feeding it, with either the RPI connected (~400mA draw), or every relay engaged (~450mA). Have not been keen to try both.

Is there something I'm doing wrong? Should the LM7805 get that hot at < 1A load?

What is the "Temperature coefficient of output voltage" listed in the LM7805 datasheet?

Should I be looking at voltage "conversion" rather than "regulation" ie. DC to DC power supply rather than a wide range DC input in to a 5V vreg?

Space is minimal, I need somewhere between 1.5 to 3A @ 5V - Ideas?

#### Litch

Joined Jan 25, 2013
85
Revision 3 PCB:
* Removed PIN 10 from ground on the Darlington (Bad connection, grounded all relays and engaged them from power-on)
* Removed horizontal TO-220 LM3805 VREG, redesigned it to be vertical mount with a "FISCHER ELEKTRONIK FK 218 SA-32" heatsink
* Cleaned up what was the mess I made with the power supply, the hell was I thinking.
* Increased trace width for 240v area and ground lines.

Revision 2 Photo:
* Alpha board (First test)
* Relays, DIN, headers installed (now to be removed).
* Power circuitry has bee hacked up underneath to fix the original screw ups
* LM7805 stood up vertical with HS attached

#### Attachments

• 73.6 KB Views: 40
• 278.1 KB Views: 55

#### Litch

Joined Jan 25, 2013
85
Design finished, proto is working 100% (In the context of engaging relays and measuring resistance across the 6 ADC pins)

DC-DC converter is nice and cool powering the RPi and all the relays at once (Thanks to THIS thread)

Thanks for all the input, I'll dump photos, schems and source code in finished projects as soon as I can.

#### Attachments

• 198.3 KB Views: 35
• 212.6 KB Views: 38