I am currently following a guide to make a self-watering plant arduino:
I am having troubles with understanding how to wire the whole circuit so I decided to draw a circuit diagram. I think in the instructions some of the steps were missing, for example, where am I suppose to connect the analog pin to? Maybe I missed that part but I went over it multiple times...
Here is a picture of the diagram I drew, could someone please point out where my mistakes are:
Also, I have a few more questions. Why is the 5V connected to one of the bolts with the red wire? What is that suppose to accomplish? Also, why do we need a 10k resistor, can't we just sent 5V directly to the coil for the relay to work?
I can't believe that instructable site.
Every now and then these questions pop up here at the Arduino forum, because people don't get what's been instructed there.
Instructions are incomplete, and no explanations about what's going on whatsoever.
So build the evil device you found over there, and have no clue what it will do..
The 10 K resistor connected to one side of the relay is supposed to be connected to the 5 volts.
So the relay and the resistor are always tied to 5 volts.
The other side of that resistor is to be connected to one of the probes.
The other probe is to be connected to A1 of your Arduino.
Note that the relay is switched on by setting its pin to LOW, so the other side is supposed to be HIGH or else that relay can't switch on like this.
Also be sure to use a very low current relay.
And ALWAYS also connect a diode over a relay coil connected to and/or near your Arduino.
Connect it with the anode to the side that is connected to the Arduino, and the cathode (the side that has the line mark) to the coil side that also has the resistor.
If you leave out this diode, be prepared to do serious damage to your Arduino.
This means the resistor is not of any influence to your coil, so your drawing is incorrect.
This is not your fault, it's just a really crappy set of instructions from an author that is proud to also be an author of 2 instruction books and still manages to get stuff wrong and publish it.
Thanks for the great response, you are right the instructables was missing the diode which is one of thee key components for a relay (at least from what my peers have told me). I redrew a new diagram:
Do I need to connect something to the ground? Also, do we put a 10k ohm resistor there to prevent a short? What is wrong with having a short? Will it damage the coil?
Also, what kind of diode should I get? I have never actually purchased one before (I am pretty new to electronics).
The diode across the relay contacts has to momentarily conduct the same current
as operates the relay - any diode that can handle a pulse current rating the same or
larger than the relay will do, 1N4001's are easy to find, will work up to 1A continuous.
Without the diode the inductive kick-back from the relay coil will destroy the rest of
your circuit, it is never optional. It goes across the relay in the direction that does
not normally conduct, its only when the coil is switched off that it springs into action
saving the rest of the circuit from high-voltage.
Many relays require more current than an Arduino pin can supply, in which case a
transistor will be needed to boost the current, this is a common circuit question
search these forums for examples.
Your new drawing isn't correct yet.
You still have the 5 volts connected to the resistor and the resistor connected to the relay coil.
The self made sensor is also directly connected to 5 volts.
That is not what i meant,
You need to connect the 5 volts to the connection of the resistor and the coil, so to the other side of that resistor and create a T-junction.
This way the 5 volts can (and will) go up to the coil and down to the resistor.
After that, the resistor has one unconnected side.
That is where the sensor probe goes.
MAS3:
Your new drawing isn't correct yet.
You still have the 5 volts connected to the resistor and the resistor connected to the relay coil.
The self made sensor is also directly connected to 5 volts.
That is not what i meant,
You need to connect the 5 volts to the connection of the resistor and the coil, so to the other side of that resistor and create a T-junction.
This way the 5 volts can (and will) go up to the coil and down to the resistor.
After that, the resistor has one unconnected side.
That is where the sensor probe goes.
Now, I don't get why we even need the second sensor probe and the 5V from the Arduino connected to the resistor. I was thinking we can just get rid of both the 5V pin and the sensor probe and have pin 12 connected to the coil which is then connected to the resistor which is then connected to the GND of the Arduino. Could you please explain what is wrong with what I just said?
Yes i can.
But first i must point you to my mistake (sorry).
I made you draw the analog input connection to the wrong spot.
The analog input actually goes to the side of the resistor that is connected to that probe.
The other probe goes to GND (and nowhere else).
That way you build a voltage divider.
The current through the coil is not controlled by this setup (if you thought that was what the resistor is for).
So if you use an incorrect relay, that current will do damage to your Arduino.
A resistor in series with a coil would not help a lot because of the nature of that coil.
That's why you would see a transistor popping up if someone over here would have designed this device.
That doesn't really reduce the current through the coil, but it would protect the Arduino from being destroyed by it.
The resistor limits the current, and is part of the sensor.
The other part is the resistance of the soil your plants are in.
This resistance varies by its humidity, and that's exactly what you want to register.
You can't really measure a resistance with an analog input pin.
You need the help of another resistor and build a voltage divider.
That is what a potentiometer is essentially too.
What you are suggesting, would never result in a relay switching, and a sensor that doesn't sense.
If it would sense, that value would depend on coil current.
Also the relay would work in reversed order if at all.
MAS3:
Yes i can.
But first i must point you to my mistake (sorry).
I made you draw the analog input connection to the wrong spot.
The analog input actually goes to the side of the resistor that is connected to that probe.
The other probe goes to GND (and nowhere else).
That way you build a voltage divider.
The current through the coil is not controlled by this setup (if you thought that was what the resistor is for).
So if you use an incorrect relay, that current will do damage to your Arduino.
A resistor in series with a coil would not help a lot because of the nature of that coil.
That's why you would see a transistor popping up if someone over here would have designed this device.
That doesn't really reduce the current through the coil, but it would protect the Arduino from being destroyed by it.
The resistor limits the current, and is part of the sensor.
The other part is the resistance of the soil your plants are in.
This resistance varies by its humidity, and that's exactly what you want to register.
You can't really measure a resistance with an analog input pin.
You need the help of another resistor and build a voltage divider.
That is what a potentiometer is essentially too.
What you are suggesting, would never result in a relay switching, and a sensor that doesn't sense.
If it would sense, that value would depend on coil current.
Also the relay would work in reversed order if at all.
Again, sorry for my mistake.
Thanks! And no problem about the mistake. The circuit makes perfect sense now and for those who are interested this is the circuit:
Now, as for the relay... I decided to use this one:
The max current it can have is 90.9mA. And since the resistance will always be greater than 10kohms, then the current will be less than 0.5mA. Is this how you choose relays? Is my relay choice good?
Oh yeah, I also chose this relay since the coil voltage I will be supplying is 5V from pin 12.
Just don't be surprised when the probes corrode away in a short time. We've been over this in another thread, even stainless steel and gold will corrode with a current flowing through them, when in contact with any dampness.
The 10k resistor is not limiting current to the relay, it has nothing to do with the relay.
90mA is -way- more than any Arduino pin should be sourcing or sinking. 40mA is the maximum allowed, and you should keep it below 30mA.
If you measure it, I doubt the Arduino is even managing to bring it down to 0V. Use an NPN driver transistor. Current limiting resistor, say 470 ohms, to the base of something like a 2N3904. Emitter to ground. Collector to the relay coil. Other end of the relay coil to 5V. Change the program so pin 12 now pulls High to turn on the pump.
That Instructable sucks. Where is the schematic? There isn't even a wiring diagram or clear picture of how it is all wired together.
That circuit isn't going to last long on a 9V battery. Why not just build a small power supply into it? Seems ridiculous to have something that plugs into a wall outlet require a battery to run it. I doubt that you'd get more than a few days from this.
That is not quite "how to choose a relay".
There's a bunch of stuff you need to consider.
You've got the 5 volts coil, that should be OK.
That coil will switch on at 3.5 volts, and off at 0.25 Volts.
The coil current when operated at 5 volts, is 91 mA.
Your Arduino can supply absolutely no more than 40 mA per pin, if you use just a few pins (else less).
This means this relay is not suitable to be directly connected to the Arduino.
The contacts can switch 1 Ampere @ 120 Volts.
Your drawings show a 120 volts pump.
Do you know what current it will take ?
Or does it say what power (Watts) it is ?
The way to reduce probe corrosion (other than using massive thick probes) is to probe
the resistance with low voltage AC signal. Voltages above about a volt or so will lead to water
being electrolysed and strong oxidation of the anode. balanced AC signals help stop build-up of chemical species at one electrode only (at the very least it shares the load between both probes). Balanced AC also stops the polarization of the system (it will start to act like a
feeble battery if you run DC only, adding error voltage to the readings).
Reducing how often you take measurements will also reduce corrosion, if you take 1 second
of readings every hour that's 1/3600 times the charge flow through the electrodes.
I had the corrosion and electrolysis mentioned in my "sorry" reply, but decided to delete that part to prevent too much confusion.
Intermittent probing requires switching the probe and so an extra pin, but in this case that shouldn't be any problem (plenty of pins left).
You could also use yet another pin and create alternating probing, but that would be too much of a hassle i guess.
polymorph:
Just don't be surprised when the probes corrode away in a short time. We've been over this in another thread, even stainless steel and gold will corrode with a current flowing through them, when in contact with any dampness.
The 10k resistor is not limiting current to the relay, it has nothing to do with the relay.
90mA is -way- more than any Arduino pin should be sourcing or sinking. 40mA is the maximum allowed, and you should keep it below 30mA.
If you measure it, I doubt the Arduino is even managing to bring it down to 0V. Use an NPN driver transistor. Current limiting resistor, say 470 ohms, to the base of something like a 2N3904. Emitter to ground. Collector to the relay coil. Other end of the relay coil to 5V. Change the program so pin 12 now pulls High to turn on the pump.
That Instructable sucks. Where is the schematic? There isn't even a wiring diagram or clear picture of how it is all wired together.
Alright, but what is wrong with having more than enough? If this is the case I will head to the store sometime this week to get a 30mA coil relay. Everything else will have the same ratings. Also, quick question, if I did use the 90mA coil would that damage the Arduino? It's funny because the instructable relay used 90mA... Really shows to how cruddy it is :P.
Regarding your transistor comment, I will explore that with greater detail this weekend and possibly re-upload a diagram. Thanks for the tip!
MAS3:
That is not quite "how to choose a relay".
There's a bunch of stuff you need to consider.
You've got the 5 volts coil, that should be OK.
That coil will switch on at 3.5 volts, and off at 0.25 Volts.
The coil current when operated at 5 volts, is 91 mA.
Your Arduino can supply absolutely no more than 40 mA per pin, if you use just a few pins (else less).
This means this relay is not suitable to be directly connected to the Arduino.
The contacts can switch 1 Ampere @ 120 Volts.
Your drawings show a 120 volts pump.
Do you know what current it will take ?
Or does it say what power (Watts) it is ?
The pump says 3W of power on the back. So would that mean the current it will take is 3W/120V = 0.025A? So would 1A relay be overkill?
The relay coil draws 90mA at 5V. But the Arduino pin is rated at a maximum of 40mA source or sink out of a digital pin. This is bad. This is bad for the microcontroller on the Arduino board. You either need to find a relay that only requires 30mA at 5V, or use a buffer transistor like a 2N3904.
As for the relay contacts, one with the contacts rated at 1A @ 120Vac is fine to run a 3W pump like that one. It is NOT overkill, the contacts -must- be rated at a lot more than the pump requires. The pump will draw more current when it starts, and relay contacts wear faster if you run them at or very near their maximum rated current.
I asked that question about the pump's power, because you need to check that.
Polymorph explained perfectly why this is needed and things you might not have considered.