2
\$\begingroup\$

Project

I'm building a controlled watering system for my plants because I keep killing them by forgetting to water... I'm using an ATMega88PV for the logic and a resistive probe (voltage divider) to get a measurement of the moisture content which is working fine. I'll be using an aquarium pump controlled by a relay from the MCU and a large water reservoir for the watering.

I would now like to implement an emergency overflow protection.

My pot is sitting on a tray that will collect any excess water that drains out of the pot so that it can evaporate. I would like to have an automatic kill switch that kills the pump if any water makes it into the collection tray in order to prevent a mess on my floor.

I'm not very good with analogue electronics and I've never used a relay before so I'm asking for your comments on the design.

Here is the design that I have come up with:

schematic

simulate this circuit – Schematic created using CircuitLab

I couldn't find a symbol for a terminal so I used the normally open push button (labeled OVFD for OVerFlowDetector) symbol for my overflow detection switch.

It will basically be two electrodes at the bottom of the tray which are normally open and will close when water collects in the tray. I have a weak pull-up to 5V when OVFD is opened.

I then AND this with the control signal from the MCU GPIO pins (5V, 50mA max) and use this to drive the relay which is a SPST (I think?) with Ucoil = 5v and Pcoil=200mW (40mA).

The relay is normally open (pump disconnected) and will connect the pump to the 230VAC 50Hz from the wall socket when closed. Is this the proper way to use a relay? Now when I look at it, it seems odd... Do I need a SPDT relay?

I'm also a bit worried about driving the relay. The relay needs 40mA to switch and according to the datasheets on the 74LS07 it can only source 40mA. Do I need some kind of current amplification or will it work anyway?

\$\endgroup\$
5
  • 1
    \$\begingroup\$ You must not ground any part of the AC section of the circuit, or connect it to the Arduino circuit (other than through the relay, which provides galvanic isolation between the control and switched circuits). \$\endgroup\$ May 15, 2017 at 23:47
  • \$\begingroup\$ Of course, I'm just used to putting a ground on every isolated circuit for simulation purposes. The ground wouldn't be shared with the MCU and the HV circuit. \$\endgroup\$
    – Emily L.
    May 16, 2017 at 0:22
  • \$\begingroup\$ also AC capacitance sensor for water with any clock signal is better than DC for water. unless it is well fertilized for ions. Pure water is an insulator \$\endgroup\$ May 16, 2017 at 0:37
  • \$\begingroup\$ @TonyStewart.EEsince'75 I'm not watering my plants with distilled water, nor am I growing them in inert media. There will be plenty of impurities in the water itself initially and plenty more will be imparted to it by the soil it passes through for it to be conductive. \$\endgroup\$
    – Emily L.
    May 16, 2017 at 0:58
  • \$\begingroup\$ I understand and 100K may be ok but electrodes get oxidized (insulated) or dry corroded (conductive) and C method is what pro's use. \$\endgroup\$ May 16, 2017 at 1:21

3 Answers 3

1
\$\begingroup\$

You've made a great attempt, but I'd suggest the following:

  1. You need a diode across the relay to protect from the inductive kickback when turning off the relay damaging any driver.
  2. You get better drive if you connect the relay from +5 to the gate output since it's a saturated transistor.
  3. You just need your water level detector as an input to your MCU, you don't need to gate it with a signal from the MCU through an external gate. You have software to do all the logic.
  4. Driving any relay that has 120-240 V on it is always hazardous, I'd suggest you buy a module rather than build your own circuit.

You can buy very cheap Arduino peripherals such as this relay board from various sources such as Amazon or Ebay. They have reasonable output connections for the AC side and you are likely to find it much easier and safer to hook up. enter image description here

This board already has a transistor driver and protection diode built in so all you need is a port signal, 5 V and Ground from your MCU to turn it on an off.

There are also plenty of water level sensors for Arduino such as this moisture sensor ...they almost universally have an on board transistor and hook directly to an MCU port. enter image description here

I'm assuming you think you need a kill-switch to override the system in case your MCU fails to turn off the relay. However this would only seem to avoid a software crash ....which seems unlikely in such a simple system. If you really are concerned, then you should research ways to implement both brownout and watchdog timer events to ensure your MCU is always running correctly.

\$\endgroup\$
7
  • \$\begingroup\$ The whole point of the overflow kill is to protect against software errors (bad PID settings causing overshoot or bugs for example). Using software to guard against software issues is a no-go in my book. Yes BOD and WDT can catch some power/sw issues but not all. The hardware AND solution buys me peace of mind. \$\endgroup\$
    – Emily L.
    May 16, 2017 at 0:20
  • \$\begingroup\$ Regarding #4, yes I'm aware of the risks and I am infact using a bought relay module during prototyping. But I want to produce a small, neat PCB with everything integrated for the final thing. And this is also something I want to learn for future projects :) \$\endgroup\$
    – Emily L.
    May 16, 2017 at 1:30
  • \$\begingroup\$ I think your peace of mind should include failure of the relay driving transistor (a short) or failure of the regulator running the MCU. Really this is not even a reasonable attitude, your killswitch gate could fail, or the killswitch sensor fail ....what would you do for that? If you really want peace of mind then double or triple redundancy might help. 3 MCU's running different code in a majority rule for each output should do it. \$\endgroup\$ May 16, 2017 at 2:35
  • \$\begingroup\$ Why is removing more (but not all) sources of failure for a miniscule cost compared to a removing less sources of failure, not a reasonable attitude? \$\endgroup\$
    – Emily L.
    May 16, 2017 at 8:13
  • \$\begingroup\$ Purely my opinion, an MCU running a simple bit test logic (no PID or complex interaction) for the overflow tray compared to a standalone Analog test AND an MCU signal ...it seems the MCU would be more reliable. \$\endgroup\$ May 16, 2017 at 15:47
1
\$\begingroup\$

Your problem is quite simple, and you don't need the AND gate, it's more suitable to use your microcontroller to perform the action to stop the pump.

That would be my circuit to do so, sorry for the mess. The GPIO_1 is responsible for the input from the OVFD, this works exactly as a button, when there's water, the electrodes short and the current flows to the resistor (5V), if there's no water, then, there is no current in the resistor (0V); Concerning the relay, the most usual is a SPDT, and to activate it, I recommend a NPN transistor to protect the microcontroller.

I guess that's it, pretty basic, but you will protect your circuit and avoid using another IC.

schematic

simulate this circuit – Schematic created using CircuitLab

EDIT: Changed R2 value according to @Tony Stewart. EE since '75, but, be advised, that this value depends on your components.

\$\endgroup\$
7
  • \$\begingroup\$ The problem with this design is that any problem with the MCU will prevent the fail safe from triggering. Why the diode? \$\endgroup\$
    – Emily L.
    May 15, 2017 at 23:36
  • \$\begingroup\$ Oh, you need a fail safe proof kill switch, sorry, didn't notice before. As Jack said: You need a diode across the relay to protect from the inductive kickback when turning off the relay damaging any driver. \$\endgroup\$
    – user140439
    May 15, 2017 at 23:43
  • \$\begingroup\$ In this case, only add the transistor after the gate and, concerning the current you won't have any problem, since it will drain from the power source, not the IC itself. \$\endgroup\$
    – user140439
    May 15, 2017 at 23:52
  • \$\begingroup\$ @TBorges R2 must drive 2mA to drive a 125 Ohm 5V relay coil for 40mA with Ic/Ib= 20 . Your 10k only gives 0.43mA base current. pls fix. but I would buy the relay cards with drivers, much easier. \$\endgroup\$ May 16, 2017 at 0:25
  • \$\begingroup\$ Is it beneficial to put a resistor in series with the diode to help dissipate the flyback current? \$\endgroup\$
    – Emily L.
    May 16, 2017 at 0:26
0
\$\begingroup\$

Do you really need a µController for this app?

You should use a 12v pump. Like this one: 12V, 4.2 Watt, 240L/hr Pump There are many of these being sold with similar specs, they are all the same.

All you need is two moisture detectors, one for the soil, and one for the drain tray. When NEITHER detects any moisture, the pump turns on. If and when either detects moisture, the pump cannot be not be on.

You have a comparator for each detector. One turns on a 12v driver to the pump and the other drives a circuit to provide ground to the pump.

You have your fail safe but you have single points of failure, so you may want to use the µController to monitor the moisture as well and add an alarm.

The water supply should be minimal so there is not enough water to go rancid. When the water is gone the µController detects both the soil and tray are dry and activate the alarm.

The alarm is configured so it defaults to on and the µController is required to periodically disable the alarm. If the µController does not disable the alarm the alarm goes off.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for taking the time to write an answer. However you did not answer my question. I need to MCU as it performs PID control of the pump to achieve a specific watering cycle among other things. \$\endgroup\$
    – Emily L.
    May 16, 2017 at 9:18
  • \$\begingroup\$ Still the 12V pump is better than having a 120V relay. The fail safe concept will still work as well. You just work the µController into the above if you think it will cover the things that could go wrong. I believe I did answer your question, the overflow is handled by the tray moisture detector. If there is water in the tray the pump will not operate. You just need to add the µController in with the soil detector to achieve your other objectives. You just want to make sure if anything fails, it fails safely. \$\endgroup\$ May 16, 2017 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.