Op Amp for your garden (newer, better)

opamp2

Note 2022: although still very useable, nowadays ofcourse it is very simple to make this with just a moisture sensor baord and a relay board from say Aliexpress or banggood (don’t use the standard moisture sensor itself that comes with the module, as that is crap)

A short while ago I published an automatic irrigator for garden soil based around an op amp and like usual, when pondering about it, one comes up with improvements.

One of the biggest issues with the previous design was that it does not have a sensor for a low water level, with the risk of your pump running dry if the reservoir is empty. Submersible pumps generally do not like that at all. But there is a simple solution.

S1 is a level switch that is controlled by a magnet or a floater and that closes when the water level is getting dangerously low. Connect the switch with a series resistor, parallel to the to the moisture probe, or, in layman’s terms: to the wires of the moisture sensor.

If the soil is dry and the pump starts pumping, as soon as the level will get too low, the switch will close and the mositure sensor will suddenly be ‘seen’ by the op-amp as having a very low resistance. The Op amp will therefore ‘think’ that the soil is wet enough and stop the pump.

The Nozzle on the veggie bed

7 Segment display on Arduino with 595

7_segment_display7 Segment displays are easy to attach to an arduino (or other microprocessor). Just connect the digital Outputs of the Arduino with a segment of the display (via a current limiting 470-560 ohm resistor: the IC can in total only deliver 70mA) and fire away.

Nothing wrong with that except for normally needing 8 digital pins for that (if you are using the point as well), and in some cases that might just be too much.

It is possible to use only 3 output pins if you are using a serial shift register like the 74HC595.
This chip will take a base-10 number and translate that into a binary number on its 8 output pins. So if I send  ‘0’ the output will be ‘00000000’ and if I send ‘255’ the output will be ‘11111111’ so with the proper connections to the pins of the display, the correct segments can be made to lit up.

When you get a 7 segment display it is not always clear what the pin configuration of that chip is. Sometimes it is not even clear if it is a common anode or a common cathode display, so that is what we need to figure out first. Ofcourse if you have a datasheet, that helps, but it can’t hurt to check, just to make sure. If you look at the picture below, it is already clear what the common pins are. Use a simple multimeter, keep  one probe on the common pin and see what segments light up  when you touch a pin with the other probe

7seg_dispA simple way  to set up the proper connections is to follow the more or less standardized connections below:
Q0 ->A  (or, to be more precise, the pin that lights up segment ‘A’)
Q1->B
Q2->C
Q3->D
Q4->E
Q5->F
Q6->G
Q7->DP
It is obvious that  sending ‘0’  to the display will not light up any segments while sending ‘255’ to the display will light up all the segments, including the DP.
As the DP is connected to Q7 it is clear that sending 127 will light up all the segments except DP, which means it will form an ‘8’.

For the ‘0’ you need all the elements to light except G. As G is connected to  Q6, you will need ‘11111100’ on the 595, which is ’63’
With the chosen connections, the following numbers will make the ‘0’ til ‘9’:

63, 6, 91,79, 102, 109, 125,7, 127,111.

(192,249,164,176,153,146,130,248,128,144  for common anode)
If for whatever reason (easier in yr print design perhaps), just set up a truth table and determine the base numbers you need to send

After you have those base-numbers that represent a specific number, store those in an array, from where you can send them to the HCT595.

Your connections between Arduino, 74HC595 and 7 segment will look like this:

Arduino pin 5 => 74HC595 pin 12 (latch)
Arduino pin 6 => 74HC595 pin 14 (data)
Arduino pin 7 => 74HC595 pin 11 (clock)

74HC595 pin 1  (Q1)   => LED Pin 5  (B)
74HC595 pin 2  (Q2)   => LED Pin 9  (C)
74HC595 pin 3  (Q3)   => LED Pin 7  (D)
74HC595 pin 4  (Q4)   => LED Pin 6  (E)
74HC595 pin 5  (Q5)   => LED Pin 2  (F)
74HC595 pin 6  (Q6)   => LED Pin 1 (G)
74HC595 pin 7  (Q7)   => LED Pin 10  (DP)
74HC595 pin 8  (GND)  => Ground
74HC595 pin 9  (Q7S)  => Not connected
74HC595 pin 10 (MR)   => Vcc (High)
74HC595 pin 11 (SHCP) => Arduino pin 7
74HC595 pin 12 (STCP) => Arduino pin 5
74HC595 pin 13 (OE)   => Ground (Low)
74HC595 pin 14 (DS)   => Arduino pin 6
74HC595 pin 15 (Q0)   => LED Pin 4  (A)
74HC595 pin 16 (Vcc)  => Vcc

the choice for the arduino pins connecting to the 595 lines… that is  randomly chosen. they could have been other pins

LED pin 3 or 8 => 470 Ohm resistor => Vcc  (for a common anode display)  or  => Ground (for a common cathode display)
With regard to the last line there is some debate whether with a 7 segment display it would be enough to use only one resistor in the common anode or cathode or that they each should have their own resistor. Obviously, displaying a ‘1’ involves only 2 segments to light up, whereas a ‘0’ requires 6 segments to light up and therefore would be less bright. For testing purposes you could use 1 resistor of say 330 ohm in the common lead. For final circuit I would advise separate resistors.

7segment

7_segmentPrint

7segm_action

Program:

/*
Using a 7-segment display with the 74HC595 shift register
*/

int latchpin = 5;// connect to pin 12 on the '595
int clockpin = 7; // connect to pin 11 on the '595
int datapin = 6; // connect to pin 14 on the '595
// the array contains the binary value to make digits 0-9
// for the number '11'  use code '31' for CC and '224' for CA
int segment[10] = {63,6,91,79,102,109,125,7,127,111 }; // for common cathode
//int segment[10] = {192,249,164,176,153,146,130,248,128,144 }; // for common anode

void setup()
{
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
}
void loop()
{

digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0); // clears the display
digitalWrite(latchpin, HIGH);
delay(1000);

for (int lus=0; lus<10; lus++)
// counts from 0 to 9, using the values in the array
// whose values correspond to the binary outputs 0~9
// add 128 for digital point
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, segment[lus]+128);
digitalWrite(latchpin, HIGH);
delay(500);
}

digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0); // clear the display
digitalWrite(latchpin, HIGH);
delay(1000);

digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 128); // light the decimal point
digitalWrite(latchpin, HIGH);
delay(1000);

}

mind you that it is possible to count to ’11’ on the display. just write ’31’ (‘00011111’) to the 595

VQB 27 E
VQB 27 E

A popular 7 segment matrix is the VQB 27 E Y3. The pin out is a bit different. You will find it in the image

Opamp for your garden

opamp-probe

(You may want to have look at the improved version right away)

I admit that this has little to do with Arduino’s, but when working on my previous articles on moisture probes and garden irrigation with an Attiny, I mentioned using op-amp comparators instead of microcontrollers, so I thought I’d publish one like that as well.
The concept of an op-amp comparator is simple, if the ‘+’ gate is higher than the ‘-‘ gate, the output goes high, otherwise it goes low.
So with a humidity sensor attached in dry soil, the resistance of that sensor is high and therefore the voltage on the ‘-‘ gate is low and presumably lower than the voltage on the ‘+’ pin and therefore thge output of the opamp will go high.

This will switch on the Solidstate relay and the pump will start pumping. The water that flows into the plantbed will decrease the resistance between the humidity spikes, th evoltage on the ‘-‘ pin wil rise until it is above the level set with P1, the output will go low and the pump will be switched off.

Instead of a Solidstate relay you can also choose for a regular relay, hence the circuit around T1.

Capacitor C2 is in fact a bit optional. after the output of the op-amp goes low, C2 will still have a bit of charge that will keep the pump turn a little bit longer after the humidity is ‘enough’. It also gives a bit of delay in switching the pump on. This avoids jittering of the pump.

The value of R1 largely depends on the type of soil probe you decide to make. Some people have two spikes close together and that would call for a lower value of R1, some people choose to have the spikes at opposite sides of a plantbed, obviously that calls for a higher value of R1.

It is not really necessary to adapt R1, but if R1 and the resistance of the probe in ‘almost to dry’ condition are far off, the gain of P1 will be limited.

As this is an Arduino dedicated site, I will pull the arduino in here as well. You could choose not to let the Arduino do the measuring of the soil through its analog gates, but you could hook up th eoutput of the above opamp to a digital port of the Arduino and only let it check high or low.
You could build, say 4 of these circuits, each (use a quad opamp then) and have your arduino just do the measuring of the outputs and take appropriate action.741pcb

this is a design that is for toner transfer. So you are looking at it from the pertinax side. PDF design here. (NOTE There is new design in which a flaw was eliminated)
Below the component placing on the PCB. Unfortunately (I use a different program for the circuit and the PCB as I dislike Fritzing’s circuit design), the numbering of the components is different, but it does not take a rocket scientist to figure it out.741-opbouw

U3 is the connector for the power. J1 is the connector for the probesu6 is there for a different spacing of the capacitor. U2, U4 and U5 are for a relay. U5 and U2 should be drilled according to the size of the relay you happen to use.
J2 is the switching output of the SSR. The entire PCB is about 4×5 cm.

Mounting components on the PCB

Power supply is 5-10 Volt. Depending on what type 741 you are using it could be up to 18 or 22 volts. If you feed with more than 10 Volts you need to recalculate and adapt the value of R2 in the circuit (unfortunately this has come out as R4 on the PCB design) . The forward voltage on the 39MF22 is 1.2 Volts, for a regular LED that is nominal 2 Volts. So if you would feed with say 15V and say 10 mA, you would need a resistor of 12.8/10=1.28k (say 1.4 k). With the current resistor you would have a current of12.8/0.330=39mA. That is too much for the 39MF22 (max 20 mA). The max supply voltage with the current 330 ohm resistor is in fact 10 Volts (and that is alreday pushing it with 20.6mA).

The current 330 Ohm resistor gives a value of 5.5 mA, which is just above the trigger current of the 39MF22.
Because of variations in resistor values and forward voltages of the LED, 330 might in some instances be just a bit too much if you are feeding the circuit with just 5 volts. Try 220 or a 180 Ohm resistor then.

You should stick to the following minimal and maximal values of your resistor (in Ohm)

Voltage Min value Max value
5 90 360
6 140 560
7 190 760
8 240 960
9 290 1160
10 340 1360
11 390 1560
12 440 1760
13 490 1960
14 540 2160
15 590 2360
16 640 2560
17 690 2760
18 740 2960

As you may have noticed, there is a small mistake in the PCB design as that the LED and the resistor to the 39MF22 have been switched. This should not make any difference for the SSR version, but it may cause the Relay not to shut off. So if you are making the relay version, just switch the LED and the 330 Ohm (or adapted value) in position: The circuit is right, the PCB is wrong

Using MOSFETS with TTL levels (5 Volt and 3.3 Volt)

If you are looking for 3V3 compatible FETs: scroll towards the end (last update november 2021)

FET

Various Arduino projects that need to switch a high DC load are using MOSFET’s to do this, according to the circuit at the right (R1 is optional and may be necessary to switch off the FET if the pin goes low.

Popular MOSFET’s that are used are the IRF510 and IRF 520

irf510 irf520
IRF510 IRF520

Looking at those graphs one can see that at a gate to source level of 5V (Arduino levels) the IRF510 is only capable of delivering 1 Amp, whereas it is specified for 5,6 Amps continuous current. The 520 is somewhat better: at 5 V it delivers 3 Amps from its max of 9.2. This is because these FET’s are designed to pass the max current at gate voltages of around 10 Volts and that is beyond what most microcontrollers can deliver.

For the IRF522 it is even worse.

irf522

Looking at the curve, at a gate to source voltage of 5V the IRF522 is hardly turned on. You are limited to a current of about 200mA. Much better to use a cheap Darlington transistor then.

The IRF530 is a better choice:irf530

At 5V volt on the gate, the IRF530 will pass something around 4.5Amps.

If you are shopping for a MOSFET for the Arduino consider the IRL540 The L shows that is a logic level mosfet. A logic level mosfet means that it is designed to turn on fully from the logic level of a microprocessor. The standard mosfet (IRF series etc) is designed to run from 10V.

Here is the curve for the IRL540:

irl540

Now at 5V you are out of the linear region and the MOSFET can already deliver its specified 28 Amps continuous current.

You may also consider the IRLZ44.

The IRLZ44 data-sheet shows the Vgs(th) to be 1-2V. With a 3V drive the FET drops less than 0.15V at 4A (at 25C, Rds(on) is about 0.04 ohms), and under 0.25V at 175C (Rds(on) < 0.063 ohms).
So we know the FET’s I^2-R ohmic dissipation will be under 1 watt, and that’s good. If we use Vgs = 4V, specified for AVR chip outputs, the dissipation should be about 0.4W at 25C (0.8W for Tj = 175C). The  Transfer characteristics graph (figure 3 in the data sheet) shows it can handle 30 Amps  with a gate voltage of 3V3.

irlz44

Wether a MOSFET is a standard MOSFET or a ‘logic’FET becomes clear from the Datasheet. If for instance you look at the Datasheet of the IRFZ44N at the Rds(on), This lists the ‘on-resistance’ under the condition that Vgs=10V (and Id=25A). If there is no rating for Rds(on) when Vgs=5V (or 4.5V), then it is not a logic-level MOSFET. A logic level MOSFET will have Rds(on) specified for Vgs=5V or 4.5V. If its only specified for Vgs=10V, its not logic-level.

Another thing to beware of in datasheets is Vthresh (threshhold voltage). This is not the gate voltage to turn the device on, its the gate voltage at which it switches fully off (less than a few uA of current, typically). If Vthresh is given as 2..4V range, it cannot be a logic level MOSFET (Vthresh is usually 0.5 to 1V for logic-level MOSFETs).

When designing with MOSFETs be aware that instead of having a Vsat like a bipolar transistor, a fully-saturated MOSFET acts as a low-value linear resistor. If for instance you want to switch 5A in a 12V circuit and you only want to waste 0.5V across the MOSFET, then its on-resistance (Vds(on)) should be <= 0.1 ohms (0.5V / 5A)

The dissipation then is 5x5x0.1=2.5 Watt. But suppose the FET you choose has 0.05ohm Vds(on) and carries 10A then it will dissipate I^2R watts, ie 10x10x0.05 = 5W. This will need a good heatsink if the load is on for more than a second or two, but it is no issue if it gets millisecond pulses every few seconds. ‘ON-resistance’ of 0.2 to 0.001 ohms are available (though less than 0.005ohms gets expensive).

The relatively cheap BUZ11 is also an option. Although it is no Logic level MOSFET, it will go into saturation with a 5 Volt gate voltage at around 7 amps and a VDS of about 0.5 to 1 Volt. But it’s RDS(on) will be far from ideal and you will lose 3.5-7 Watts in the FET:BUZ11

Should you however be stuck with a FET like the IRF522 that really needs a high voltage to switch efficiently then use the following circuit:MOSFET

Realise though that it is an inverting circuit. A HIGH on the Output of the Arduino will switch the Load Off. Also the 520 and 510 will be more efficient with this circuit.

MOSFETwith low voltage input

Remember to use a heatsink for the MOSFET if you are using any serious loadsMOSFET Print

If you are using this circuit to switch any serious loads, then it is wise to solder some thick wire over the tracks coming from the MOSFET. You will find the print design here. This is for direct transfer so it is already mirrorred the right way.

If you have a non logic FET (like the IRF series and need some galvanic separation from your microcontroller circuit, the following circuit comes in handy:fet520

3.3 Volt levels

For a long time ‘TTL” meant 5 volt. Nowadays more and more 3.3 Volt boards are available as well in the Arduino series as in the popular ESP8266 and the raspberry Pi. On these boards the STN4NF03L (Vgs(th) 1Volt), can be a good choice. Not an ideal choice, but a good one. Check section 2.1 figure 4 in the datasheet. (Mind you the Vgs(th) -threshold gate source voltage- is not the Voltage at which to use the FET, see  warning at end of this paragraph)
Other good choices are the FQP30N60L (Vgs(th) 1-2.5 Volt), or the IRLZ44 (Vgs(th) 1-2V)(discussed above and practical results of the latter found in Jeroen’ s comment below)
Other FETs that can be used with 3V3 are for instance (By no means complete):
IRLB8721PbF Vgs(th)  1.35-2.35 Volt
PJC7400_R1_00001  Vgs(th) 1.7Volt
IRLMS2002TRPBF Vgs(th) 1.2 V
AON2408 Vgs(th) 1.2V
 PMV16XNR  Vgs(th) 0.4-0.9V. On-Resistance of only 20 mOhm when powering the gate at only 3V, and can source a bit more than 6A
AO6400 Vgs(th) is 0.65 1.45Volt (typically 1.05 V) capable of delivering almost 7 amps
SiSS52DN Vgs(th) 1-2,2 Volt at 3V3 Gate voltage it should be anle to deliver 100A. (page 3 Transfer characteristics table). It has an Rds(on) in the tens of miliOhms. AFAIK it comes i a Powerpack housing only.

Let me again stress for the novice, that the Vgs(th) is the voltage on the gate at which the FET just starts to open. It is not fully open at that voltage and can only  deliver very little power. The FETs mentioned here however can deliver more power when they have 3v3 at the gate. Check their datasheet though to see if it is enough for your project. (usually you will find it on page 3 in the ‘transfer characteristics graph). If for instance we look at the FQP30N60L That  has a Vgs(th) of 1-2.5 Volt, we can see that at room temperature at 1 Volt…it doesn’t do anything but at 2.5Volt it may do  around 2 ampere. At 3v3 however it can deliver about 11 ampere

fqp30nl60

The STN4NF03L (Vgs(th)1Volt)  for instance can deliver about 4 ampere at 3v3 but almost nothing at 1Volt.

So what about some of the popular ‘chinese web site’ MOSFET moules that are available. for instance this one:
d4184

That has two D4184 powerfets in parallel. The D4184 has a Vgs(th) of 1.7-2.6V. The datasheet (page 3) teaches us that at 3V3 the max current is probably around 1, maybe 2 ampere (it is hard to see in the graph). So the board will do for 3V3 if you only need 2-4 amps. It’s real capability of 2*50 Ampere however needs a gate voltage of 10Volt.

How about this one:

Well, that has an IRF520, that is not even very suitable for 5 Volt.

How about this one:

Well, it seems that one is available with either an FR120, an LR7843 or an AOD4184.
The FR120 has a Vgs(th) of 1-2.5 Volt. The transfercharacteristics in the data sheet though show that even at 3v3 the Drain current is really minimal.
The LR7843 has a Vgs(th) 1.4-2.3V at 3V3 it is capable of delivering high currents. the transfer chracteristics graph shows 40 Amps, but only at short bursts. The max current is 16 Amps.
The AOD4184 is AFAIK similar to the D4184 that is discussed above: the board will do for 3V3 if you only need 2-4 amps. It’s real capability of 2*50 Ampere however needs a gate voltage of 10Volt.

Epilogue
I feel compelled to add a few caveats here. I have focused mainly on whether 3V3 or 5 Volt was an appropriate level to turn on a FET and get a decent current flowing through it (as opposed to just the threshold gate voltage). That does not mean though that every FET I mentioned here as being TTL level, be it for 3v3 or 5 volt is suitable for your specific project. Eventhough 3V3 or 5 volt may be fine to even fully open a FET, there are other factors to take into account when chosing a FET for your project. 2 important ones are the Rds(on) (=Static Drain-Source On-Resistance) and the Ciss (the input capacitance).

To give an example: the AO6400 MOSFET that has a max current of 6.9 Amps can be fully switched on with even 1.05Volt. However the RDS on at a low gate voltage is about twice as high as with a Vg of 10 volt. At 10 Volt it is 28mOhm and at 2.5Volt it is 52mOhm. at max current that would be a power dissipation of 1.3 vs 2.5 Watt. Maybe both not much, but it could be important for your project. The AO6400 has a gate capacitance of 630 pF and the IRLZ44 has a gate capacitance of 3300 pF. In combination with a gate resistor that determines the RC time, or in other words the speed that the FET will react to a specific gate voltage. Again, it might be minimal but it might be of importance for your project