Jason_25
Posts: 120
Joined: Tue Oct 20, 2015 6:25 pm

Micro relay for switching a bright LED with the Pi?

Wed Nov 16, 2016 8:35 pm

I would simply like to add a switched LED to my Pi project.

A mosfet is not appropriate because it is electrically complicated and potentially dangerous to the Pi itself. I am unwilling to take the chance on frying a Pi with a wrong connection. One wrong move and it costs $80 to ship another Pi 2 to me in addition to rebuilding the whole project. I am also unwilling to build a board of any kind because there is no room in my project for any of that. It is unfortunate mosfets mostly seem to require a lot of other junk to make them work.

I merely want a one piece small device that can be attached to a Pi GPIO pin on one leg, to a large source of current on one leg, and to a load such as an LED light on the other leg. No other pieces involved.

Here is how something like this works in the automotive world if say you want to drive some offroad lights with a flip switch. You go down to autozone and buy a relay and you're done. No overthinking it.

This is more of a rant that the GPIO pins are too electrically fragile and inflexible than anything else. I am fairly sure there is nothing out there that meets my needs. As soon as I get confirmation that this is in fact impossible under the existing requirements I can put this behind me and move on to something else.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Micro relay for switching a bright LED with the Pi?

Wed Nov 16, 2016 8:43 pm

MOSFETs shouldn't scare you. They are safer than junction transistors for sure - they are voltage driven, not current as per junction, so you will never overload a GPIO pin.

Build your circuit off-Pi, test it, then when you are satisfied all is OK, hook up the Pi's GND & GPIO.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12212
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Micro relay for switching a bright LED with the Pi?

Wed Nov 16, 2016 9:08 pm

if you are that scared, just place a 3.9V zener across the GPIO you are using so that an accident cannot put a voltage larger than 4V on the GPIO.

and agreed Mosfets are safe, and instead using a relay (without sufficient protection logic) can bring its own risks. Relays also cannot be directly driven by a GPIO.
Choose a "Logic level FET", that is a FET that fully goes open with a gate voltage of 3.3Volt.

User avatar
davidcoton
Posts: 4124
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Micro relay for switching a bright LED with the Pi?

Wed Nov 16, 2016 9:10 pm

You are no more likely to cause damage to a Pi using a MOSFET than a relay -- in fact the wiring is simpler, because most relays can't be driven directly by the GPIO. You need a transistor (oh -- maybe a MOSFET??) to drive the relay :o :shock: :?
Are you sure you can't drive the LED directly from the GPIO? (Specification of LED required.)
Remember the LED will need a current limiting resistor, if it isn't built in.
Signature retired

drgeoff
Posts: 9803
Joined: Wed Jan 25, 2012 6:39 pm

Re: Micro relay for switching a bright LED with the Pi?

Wed Nov 16, 2016 9:16 pm

mahjongg wrote: Choose a "Logic level FET", that is a FET that fully goes open with a gate voltage of 3.3Volt.
It's amusing that the terms conventionally used have opposite meanings.. Yes, one normally opens a gate to let things through but when using a switch, or a FET as a switch, it needs to be be closed to let current through!

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Micro relay for switching a bright LED with the Pi?

Wed Nov 16, 2016 9:19 pm

The GPIO are fragile but if they weren't the Pi would be much bigger. If they were happy switching bigger loads they wouldn't suit most people. I can't think of any board that switches high-current loads out-the-box without some external components.

What LED do you want to switch? The current involved will determine the solution.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12212
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Micro relay for switching a bright LED with the Pi?

Wed Nov 16, 2016 9:21 pm

First, there are FETs that are normally conductive unless you put on a gate voltage (but these are rare), most FETs conduct when you add a gate voltage.

But no, a gate does not have to be "closed to let current through", never seen that being said.
Ive not said it either I'm saying that (normally) a FET goes open when you apply voltage to the gate, not the same thing.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12212
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Micro relay for switching a bright LED with the Pi?

Wed Nov 16, 2016 9:28 pm

Its true, the GPIO's on a raspberry PI's (broadcom) SoC were not designed with amateurs and hobbyists in mind, instead the SoC was designed to perform in professionally designed equipment. For example Its a pity they are not latchup protected, so the GPIO's are NOT 5V tolerant.

Stuff like microcontrollers, often have more capable and more robust GPIO's, because these chips were designed to handle inexperienced users. Simple microcontrollers are also normally designed to work on 5V, so by nature they are 5V tolerant.

Jason_25
Posts: 120
Joined: Tue Oct 20, 2015 6:25 pm

Re: Micro relay for switching a bright LED with the Pi?

Thu Nov 17, 2016 12:50 pm

Thoughtful replies as always. I was confident enough already that I was not going to overvolt or short anything. My specific fear was current. The Pi apparently only allows 16 mA per pin. This tutorial is what alarmed me: https://oscarliang.com/how-to-use-mosfe ... -tutorial/ . It mentions that even with a logic level mosfet there should be a resistor in series to limit current. Which implies I will have to build a huge board that I have no room for and will certainly fall apart in my pocket. I want a one piece solution.

So I suppose this rules out a simple and compact way to add a switching "flashlight" style LED to the Pi. A custom made circuit board would be compact but not simple and a breadboard would be simple but not compact. If there is a reliable breadboard and circuit board-less way to do this I would be glad to hear about it.

But I am still considering adding a much dimmer LED as a "notification light" directly to GP21 and GND pins. I'm hoping this will work without blowing anything up: https://www.radioshack.com/products/gre ... 0332058821 . Let me know if you see any problems and help me to avert disaster.

edit:
The "notification light" works. Very cool. Still interested in a compact and simple flashlight switching approach.

User avatar
Burngate
Posts: 6002
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Micro relay for switching a bright LED with the Pi?

Thu Nov 17, 2016 7:07 pm

Surely a circuit-board is just a way to hold and interconnect the components securely, and a breadboard is just a way to do the same while you experiment.
You don't need a huge custom-made circuit-board for a couple of resistors, an FET and a LED - a square inch of Veroboard would be enough, including the connection to the GPIO header.
But if you really don't want either, you could try bird's-nesting. Just solder everything in mid-air, and poor Araldite over the lot.

That tutorial is slightly alarmist, to my way of thinking.
The Pi's GPIOs are spec'd at 16mA, but all that means is that if you attempt to draw more, the voltage will drop.
Trying to feed a STP55NF06L, for example, which according to the pdf takes 30nC to charge its gate, would mean the FET would take about ½μs to fully switch on.
Putting a resistor in series with the gate would slow everything down, but keep the current below 16mA

That radioshack LED: it appears to have a resistor built-in, but there's no info as to what value it is, or the current or voltage the device is wanting.
But you could always build your own, with a LED and resistor inside a piece of tubing. You could even build an FET into it.

Return to “Advanced users”