First, a mosfet is a much better choice than the op-amp here because it is much simpler, involves fewer components and calculations, and can handle much higher currents than an op-amp, like this (sorry not sure why I was on the op-amp kick):
Next, as for your relay, let's run the numbers. It's handy that it comes with a board, but a cheap protoboard like the
pre-etched ones they sell at RadioShack will offer you a bit more flexibility at a cheaper price (
Futurelec is even cheaper although the boards are large, SparkFun has
this little guy which is the perfect size for your project although you'll want to check out
this nice perfboard soldering tutorial). Secondly, that relay is physically much larger than what you'll actually need for this project. But, I digress. Anyways, the relay:
Let's assume you're using a +5V line from a USB port to power this. By default USB can source 100mA (that's per hub not per port mind you).
Look at the datasheet for that relay:
https://www.sparkfun.com/datasheets/Components/T9A_DS.pdf. Look at the coil data table on page 1.
- 5V coil current is 185mA or 200mA (depending on model). This is greater than the 100mA maximum from USB.
- Minimum contact load 1A @ 5VDC, which is significantly larger than your 300uA signal.
So as you can see, this relay will not meet your requirements. This relay is designed to switch higher voltages and currents and is not appropriate for your project.
Let's assume you are using the circuit I just posted (parallel port control) with power from the USB line (5V, 100mA max) and work from there (I am also assuming all your measurements are correct):
First, the relay. Basic electrical requirements are:
- <= 5V coil voltage, < 100mA coil current.
- > 7.7V switching voltage, > 300uA switching current max.
- Minimum switched load < 300 uA.
- normally-open contact (if SPST, but SPDT is fine too).
Head to Mouser's
relay section (or Digikey if you prefer) and do a search for these requirements. Sometimes it is also easier to search mfr sites directly e.g. Omron has a nice parameterized search for relays that includes more parameters than mouser. Anyways I found these:
-
https://www.mouser.com/ProductDetai...=JK6Bpmia/mt8qYhd9YNgoHf5e0I1m4I06RzPVdcpAAQ=
-
https://www.mouser.com/ProductDetai...T-US-DC5/?qs=lK7M36XCk6KssDG60issud7i8qmOKDUC
I mention the first one because it's super cheap and would be perfect except the datasheet states it has a minimum 10mA contact load (the minimum exists to guarantee that your signal will overcome normal corrosion and wear-and-tear of the switch, among other things). So unless your switch current was actually something larger, this one isn't guaranteed to work. Also the first one's pin spacing doesn't match a standard breadboard.
So, let's check the datasheet for that second one:
https://components.omron.com/compon...68E53B182485257201007DD6A0/$file/G6E_0911.pdf
- Maximum load: 2A @ 30VDC, which exceeds your 300uA @ 7.7VDC requirement.
- Minimum load: 10uA @ 10mV, which is much lower than your signal, so no problem.
- Nominal coil voltage and current: 40mA @ 5V, which USB power can easily handle.
- Pick-up voltage 70%, which means it will turn on above 5*0.7 = 3.5V (and this should answer your USB 4.5V relay question).
- Drop-out voltage 10%, which means it will turn off below 5*0.1 = 0.5V.
- Max voltage 190% (at room temperature), which means you need 9.5V to blow it up.
- Coil resistance 120 ohm (just make note for later).
- Max close time 5ms (also make note; this means you need to send your trigger signal for at least 5ms to guarantee that you close it).
- Also make note of pinout on page 76 of datasheet (standard coil type).
So it looks like this is your relay (Omron G6E-134P-ST-US-DC5). I can't guarantee it's the cheapest but I can guarantee it's not the most expensive. :lol: Also it will fit nicely on that 1" perfboard from sparkfun I mentioned earlier.
Great! Next step is to pick a MOSFET. You want an n-channel MOSFET. MOSFETs are a bit fuzzier with requirements. Your requirements are pretty easy:
- Minimum gate-source breakdown voltage: >= 10V (that'll let you run the gate off your 4.2V line + lots of padding).
- Minimum drain-source breakdown voltage: >= 18V (that'll let you run power to the +12V line if you want + lots of padding).
- Maximum drain current: >= 80mA (your relay coil is 40mA nominal, + some padding)
- Threshold voltage somewhere in the middle of your 0-4.2V signal e.g. 1-3V.
There are other considerations too so I'll just cut to the chase and say a common Fairchild 2N7000 mosfet will get the job done fine (and they're super cheap):
-
https://www.mouser.com/ProductDetai...mdCx%2bAA2NB///eDBYfiAxm8hO%2bvIx3eNCzWH3m2A=
Next, resistor R1. You actually don't want this resistor if you're using VCC=5V. But I want to mention it because you'll have to include it if you use higher VCC to drop the voltage down to the relay coils nominal voltage. Recall the coil resistance is 120Ω and nominal voltage is 5V. V/R=I so 5V/120Ω≈42mA nominal current. Now let's say you have VCC=12V. You want the voltage drop across R1 to be 12-5=7 volts (to limit relay voltage drop to 5, also mosfet on resistance is small enough that we'll pretend it's 0 to simplify things, this doesn't need to be super precise). R=V/I so 7 volts / 42 mA = 166Ω so if you use a 12V source R1≈166Ω (166 is not a common resistor value, but 160 is and is fine) will be necessary to protect the relay.
In general you can simplify the above math to R1 = (VCC - 5) / 5 * 120.
That's about it for components. As you can see it's a very easy circuit to build! A couple of notes about using the components:
- You'll notice the relay coil has +/- polarity markings on the coil. Not all relays do but this one does. This is because the relay has some circuitry inside it to suppress inductive kickback when the coil is deenergized, which could otherwise damage your components e.g. the mosfet. Many small consumer relays have this but if you ever find one that doesn't you'd want to put a reverse biased diode across the coil to absorb the voltage spike.
- The mosfet orientation is also important because of the built-in body diode; for n-channel mosfets be sure to connect drain to a higher potential than the source (so here source to ground and drain to relay).
- If it is more convenient for your design you can put R1 (if you use it), the mosfet and the relay all on the same pcb over by the garage door switch, and run VCC, ground, and parallel port data out through your cat5 cable. Or put R1 on the computer side. Or whatever. As with programming, modularity is a general design consideration although for this project it is not really important.
Hope that helps! I am not really an EE, I'm also a programmer by trade, so if anything is confusing above it's probably my fault :lol:!
- - - Updated - - -
This will give a clear picture of the mosfet switch, X-axis is mosfet Vgs (voltage from the data line of your parallel port) Y axis is voltage across relay. You're switching between X=0 and X=4.2 (over whatever the rise and fall time of your parallel port data line is). Note current beings to pass at Vgs(th)=2.1V which you can find on the data sheet, and the curve flattens out corresponding to the Vds≈5 saturation point which you can see in figure 1 of the datasheet.