What kind of relays do we need? It depends on how much current the water valves need. Most garden valves seem to use 300 milliamps. This is a small amount of current, and so a small relay is enough. Relays that can be operated at different voltages are available; we’ll use one that uses 5 V so we don’t need another power source. Figure 8-4 shows a popular small 5 V relay.

4 GSWA3E relay

You can buy it at Digi-Key, as well as from many other vendors.

Almost every electronic device has what’s called a data sheet, where all the detailed technical information on the device is documented. It can be a little overwhelming for the beginner, as there is so much information, and usually you need only a very tiny part of it. As you get more experienced, you’ll learn what’s important and how to find it quickly. If you search for the data sheet for the relay we’ve chosen, you’ll see that it can handle up to 2 amps and 30 volts of direct current (DC), or 1 amp and 125 volts of alternating current (AC), which is more than enough for us. This relay also has the advantage of being compatible with our solderless breadboard as well as the Proto Shield you will use later.

Whenever you want to control something with an Arduino output, you have to remember that an Arduino pin should power only devices that use up to 20 milliamps (see “Driving Bigger Loads (Motors, Lamps, and the Like)”). If you search for the current used by this relay in the data sheet, you won’t find it. However, you will find the resistance. Now you have to do some math, because knowing the resistance of the relay (125 ohms) and voltage that Arduino puts out on the I/O pins (5 V), you can calculate the current by using Ohm’s law, which you learned about near the end of “What Is Electricity?”. Dividing the voltage (5) by the resistance (125), we get the current: 40 milliamps.

Since that’s over our limit, we’ll need MOSFETs. For a change, we’ll use a different MOSFET from the one we used in “Driving Bigger Loads (Motors, Lamps, and the Like)”. We’ll use the 2N7000, and you can find its data sheet posted on the Onsemi Semiconductor website.

Just as in “Driving Bigger Loads (Motors, Lamps, and the Like)”, the gate will be controlled by the Arduino I/O pin, and the drain and source will be the switch that will control the relay. You’ll have to to add three 2N7000 MOSFETs to the shopping list, one for each relay.

To avoid the MOSFET gates from floating, add three 10K ohm resistors to your shopping list, one for each relay.

WARNING

When you turn on or reset an Arduino, all the digital pins start off as inputs, until your program starts running and your pinMode() changes any pins to outputs. This is important because in that brief period of time, before the pinMode() function changes your pin to an output, the gate will be neither HIGH nor LOW: it will be left floating, which means that the MOSFET could easily turn on, causing the water to come on briefly. While this might not be the end of the world in most projects, it’s a good habit to account for this. As hinted at in “Driving Bigger Loads (Motors, Lamps, and the Like)” a 10K ohm between the I/O pin and ground prevents this. 10K ohms is a low enough resistance to make sure the gate doesn’t “float”, but it’s also a large enough resistance that it won’t get in our way when we want to turn on the water.

A resistor used this way is called a pull-down resistor, because it “pulls” the gate down to ground. Sometimes a connection needs to be “pulled” to 5V; in this case, it’s called a pull-up resistor.

Whenever we control a relay or motor, we should add a diode to protect the MOSFETs from the flyback voltage generated by the collapsing magnetic field when the relay is turned off. Although our MOSFET has a built-in diode, it is a relatively small one, so for reliability, it is wise to add an additional, external diode. So, another addition to your shopping list, this time for three 1N4148 (or similar) diodes. While we’re at it, we should add the relay part number, and because we know the type of relay, we can also indicate the correct socket for the relay. Here are the additions that take the shopping list to what we’ll call revision 0.1:

  • Add three MOSFETs to control the relays, 2N7000
  • Add three resistors, 10K ohm
  • Add three diodes, 1N4148 or equivalent
  • Add three relays, DS2E-S-DC5V

Sounds like this circuit is getting complex, doesn’t it? It’s hard to visualise how all the components are supposed to be connected to each other.

Fortunately, a clever system exists for capturing this information. It’s called a schematic diagram.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *