0
\$\begingroup\$

I'm working on a simple RPi project wherein I can control my garage door with my phone via Tasker. I am using an RPi to connect to my wifi network and power on a remote garage door opener. My current setup is to short out the button on the remote and use the RPi's GPIO pins to supply power to the remote (wired up to the battery terminals) when I want to activate the remote signal. This generally works, but after not being used for a short while (overnight or less) it takes two activations to operate properly, making me suspect that the capacitors are losing charge when the device is unpowered. So I need to make it more complex and traditional, continuously powering the remote via a 3.3 VDC pin from the RPi, and using a switching circuit to make the button connection.

I can easily purchase purpose-built switches for the RPi, but I would like for this to be a fun learning experience, not just a functional final product. Also, I would like to purchase my parts locally from a specific store (in links below).

The remote switch has ~2.85 VDC around it when active. I would have needed to desolder it to see what the current through it would be when active, so I don't know exactly how to spec out a relay. For what it's worth, the current through the battery is 3.2 mA when active.

My beautifully drawn circuit

I does not seem that I can operate a relay directly from the RPi's 3.3 V GPIO pins, since I cannot find any relays with 3.3 V (or lower) coil voltages, so I need to use a 5 V relay. I found a cheap relay that seems appropriate, but I cannot find a datasheet for it, so I'm thinking about this relay instead, even though it is probably overkill. The datasheet I found isn't for the exact model number, but I think it's basically the same. It seems to have a ~140 Ohm coil resistance, so at 5 V it would require 36 mA of current.

Of course, I will now need a transistor, so I think an NPN would be best to make sure my system is not "active" during boot. But I'm not sure what specs to look for. This transistor [(PREVIOUSDOMAIN)/commerce/catalog/product.jsp?product_id=13754&czuid=1481073107852] has the lowest rated current, so I'm guessing that's the current needed at the base? Not sure about the gain or if the voltages matter, or if I need a resistor in line with it. The relay will push 36 mA of current between the collector and emitter, and the RPi will push 5 mA (assuming I'm looking at it right), so does that make it ok? V_CE will be less than V_BE, so I don't know if that's an issue...

And I know I should include a flyback diode, so I'll try to figure out that part once I know the rest makes sense.

Thank you to anyone who can help me evaluate my project!

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Few points.

  1. A switch is a short between two points. To measure current through a switch, just place the multimeter in parallel. The multimeter will act like the switch making it active. In most cases. No need to desolder the switch.

  2. Plenty of 3.3V relays out there. But you never want to power a relay directly from a GPIO anyway.

  3. You know the ICE that you need (35mA), and the max current of the RPI (16mA). So any transistor with a IBE * hFE that is equal or higher to your ICE will work. In this case, any common "jellybean" transistor like the 2n3904 or 2n2222 will work. Don't forget the base resistor.

  4. But it's pointless. You can just as easily use the transistor to directly control the switch. Place the C-E across the switch and your done. No relay needed. If the button is active high, a PNP would work instead, with reversed logic (gpio low enables the transistor).

\$\endgroup\$
5
  • \$\begingroup\$ "Place the C-E across the switch and your done." - assuming that one of the switch terminals is connected to ground, and that E is connected to that terminal. \$\endgroup\$ Commented Dec 7, 2016 at 4:02
  • 1
    \$\begingroup\$ @immibis you forgot the "or pnp" part. A optó isolator would work just as well instead instead. \$\endgroup\$
    – Passerby
    Commented Dec 7, 2016 at 4:07
  • \$\begingroup\$ Thank you for providing answers to all my mistakes, even if those that ended up not mattering. I was confused as to when a transistor actually works and completely missed the obvious solution... \$\endgroup\$
    – Matt
    Commented Dec 7, 2016 at 5:05
  • \$\begingroup\$ I'm still uncertain about the operation of transistors, and online info hasn't completely cleared it up for me. I'm sure for my project I can just buy whatever, but I'd like to understand a little more. Is the base resistor to make sure I don't pull to much current from my RPi pin? Do I want to maximize the base current so that I can also maximize the collector current? Will that drop the voltage of B below C, thus preventing saturation? Thanks! \$\endgroup\$
    – Matt
    Commented Dec 7, 2016 at 5:12
  • \$\begingroup\$ Yes. A transistor base is just a diode. Without limiting the current, you risk burning out both the transistor and the RPi pin. For a transistor as a switch, yes, you want to saturate the base as much as you can, which will open the C-E junction as much as it can. The voltage at the Base of a NPN transistor van be much lower than the voltage at the collector. You just need the base a minimum of the diode drop above the emitter, in the typical connection. \$\endgroup\$
    – Passerby
    Commented Dec 7, 2016 at 5:17

Your Answer

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

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