bin10
Posts: 5
Joined: Thu Jan 03, 2019 12:36 am

Looking for resources / new to the hardware aspect

Thu Jan 03, 2019 12:45 am

Long story short, I'm a long time programmer, software engineer by profession. I have that part figured out. However, I'm new to the hardware side, especially designing/building electronic circuits. I have a couple of questions.

First, I know it's possible to have an external power source for a breadboard. I've seen a few topics here on the forum. I see that there should always be a common GND, and I think that makes sense. What I'm still unsure of (due to being noob at this stuff) is how to prevent the external power from making its way back to the Pi. Is it correct that something like a transistor is good for this? I've also seen other components mentioned which shield the Pi from the external voltage.

Then my second question is, with an external power source for, say, a group of LEDs, how do I switch them off/on via GPIO (the Pi) while keeping the Pi's current at a reasonable level?

Maybe this is a lot to ask. Maybe I'm not being specific enough. Do let me know if something is unclear, I'll try to clarify. Not looking for anyone to do the work for me, hence looking for resources. Schematics that demonstrate these techniques, noob resources I can look at to understand how these things work, etc.

I've been on Google and YouTube a lot lately. It's just kind of overwhelming and a lot of the stuff I've found assumes a moderate knowledge of electronic circuits to begin with.

Thanks!

User avatar
penguintutor
Posts: 376
Joined: Tue May 08, 2012 9:11 am
Location: UK
Contact: Website

Re: Looking for resources / new to the hardware aspect

Thu Jan 03, 2019 11:27 am

The GPIO ports on the Raspberry Pi are low voltage & low current ports. If you just want to create one or two LEDs then you can connect them directly to the GPIO using a suitable resistor, but if you want to switch multiple LEDs then you may need to use a separate supply. (Sounds like you've worked this out already).

There are various different ways that you can do this, but a transistor as a switch or a FET are quite simple solutions.

In the case of a Bipolar transistor then it can be used as an amplifier or a switch. In the switch mode then you provide sufficient current at the base of the transistor (ground is connected to the emitter) which switches the transistor on and allows current to flow from the collector to the emitter. In this case the emitter is the same for both the input and the output of the circuit (so you connect the Raspberry Pi and external power supply grounds together).

A FET works very similar to the bipolar transistor switch, but provides a high impedence input at the gate and allows current to flow from the drain to the source (so less current is needed from the GPIO pin to switch larger loads).

This is what I did on my recent project where I used a 20V power supply (because that's what I needed for the rest of the circuit) to light up 5 LEDs in series.
http://www.penguintutor.com/news/raspbe ... tmas-house

If you just take the right-most part of the circuit diagram (there are two identical FET LED circuits). You can use a 2N7000 MOSFET with the 470R resistor between the GPIO port and the Gate of the MOSFET. Then choose an appropriate resistor for the LEDs based on your power supply.

The resistor for the LEDs is to protect the LEDs from having two much current, which depends upon the number of LEDs in series and your supply voltage. Subtract the voltage drop across the LEDs (typ 1.8V per LED) from the supply voltage. Divide that by the maximum current through the LED (depends upon the LED size and power - eg. 20mA) and then you have the value of the resistor you need.

bin10
Posts: 5
Joined: Thu Jan 03, 2019 12:36 am

Re: Looking for resources / new to the hardware aspect

Thu Jan 03, 2019 2:47 pm

penguintutor wrote: The GPIO ports on the Raspberry Pi are low voltage & low current ports. If you just want to create one or two LEDs then you can connect them directly to the GPIO using a suitable resistor, but if you want to switch multiple LEDs then you may need to use a separate supply. (Sounds like you've worked this out already).

There are various different ways that you can do this, but a transistor as a switch or a FET are quite simple solutions.

In the case of a Bipolar transistor then it can be used as an amplifier or a switch. In the switch mode then you provide sufficient current at the base of the transistor (ground is connected to the emitter) which switches the transistor on and allows current to flow from the collector to the emitter. In this case the emitter is the same for both the input and the output of the circuit (so you connect the Raspberry Pi and external power supply grounds together).

A FET works very similar to the bipolar transistor switch, but provides a high impedence input at the gate and allows current to flow from the drain to the source (so less current is needed from the GPIO pin to switch larger loads).

This is what I did on my recent project where I used a 20V power supply (because that's what I needed for the rest of the circuit) to light up 5 LEDs in series.
http://www.penguintutor.com/news/raspbe ... tmas-house

If you just take the right-most part of the circuit diagram (there are two identical FET LED circuits). You can use a 2N7000 MOSFET with the 470R resistor between the GPIO port and the Gate of the MOSFET. Then choose an appropriate resistor for the LEDs based on your power supply.

The resistor for the LEDs is to protect the LEDs from having two much current, which depends upon the number of LEDs in series and your supply voltage. Subtract the voltage drop across the LEDs (typ 1.8V per LED) from the supply voltage. Divide that by the maximum current through the LED (depends upon the LED size and power - eg. 20mA) and then you have the value of the resistor you need.
Awesome, thanks! I think this sends me in the right direction, it answers the questions I had. I'm still just overwhelmed by all the variables and all the components (e.g. resistors, transistors, FETs, grounds, voltage drop, etc). Haha. Most of it makes sense, I'm just still trying to figure out how to apply it practically. I'll do some more reading, and examine your schematics further.

bin10
Posts: 5
Joined: Thu Jan 03, 2019 12:36 am

Re: Looking for resources / new to the hardware aspect

Thu Jan 03, 2019 4:29 pm

penguintutor, I just want to make sure I'm understanding this correctly. You mentioned the 2N7000 MOSFET - that's what you used in your Christmas House project, correct? Since the Pi's GPIO pins will output at ~3.3V high (right?) and there is a 470 Ohm resistor between the GPIO pin and the MOSFET gate, how did you determine the 470 Ohm is correct in order to switch the MOSFET "On"? I looked up datasheets for 2N7000, and I'm not sure how to determine that the 470 Ohm resistor is correct based on the "Gate Threshold Voltage".

3.3V from GPIO and a 470 Ohm resistor means ~7mA current (I = V / R). But how does that tie into the MOSFET gate threshold voltage? Or am I going about this all wrong?

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

Re: Looking for resources / new to the hardware aspect

Thu Jan 03, 2019 7:07 pm

The gate of a FET is essentially a small capacitor, and will take almost zero current.
That means there's also no current passing through the 470R resistor, and both its ends are at the same voltage - 3v3 from the GPIO.

The body of a FET acts as a resistor, whose resistance is varied by the voltage on the gate.
Below the threshold, it's very large - call it infinite - so no current will pass through it, but above that, the resistance drops substantially.

If you look at the data sheet, there's a pretty picture of what happens to the drain-source voltage and current as you vary the gate voltage.
As you can see, to be able to pass a reasonable current at a reasonable voltage - say, half an amp with less than a volt across the FET - you'll need to raise the gate voltage to rather more than a Pi's GPIO can supply.
But if you're happy with only 100mA, you can get away with only 3v3 and still have less than a volt across the drain-source.
7000.png
7000.png (13.3 KiB) Viewed 279 times
The 470R resistor isn't really needed, unless you plan on wiring things up so badly that you manage to short the gate to ground. If you do that, the resistor will save the Pi from destroying itself.

User avatar
penguintutor
Posts: 376
Joined: Tue May 08, 2012 9:11 am
Location: UK
Contact: Website

Re: Looking for resources / new to the hardware aspect

Fri Jan 04, 2019 10:50 am

MOSFETs are switched based on voltage (actually charge) rather than current, so there is only a tiny current that will normally flow between the gate and source.

The MOSFET it turned on by having a voltage at the gate that exceeds the threshold voltage. The maximum current that can be drawn does depend upon the gate voltage (also depends upon temperature). In the case of switching LEDs then 100mA should be sufficient (in my case they were in series so is more than enough, if you wanted a number of LEDs in parallel then that may need to be reviewed).

If wanting to drive a higher load then you can look at an IRL520 which can switch around 3A from the GPIO.

The current through the gate will be minimal when operating (typically less than a micro amp). The reason for the resistor between the GPIO and the gate is that the gate to source connection effectively acts as capacitor. So when the GPIO output goes high there will be an in-rush current to charge the capacitance at the gate. This is almost like having a short circuit for a very small duration. With a small MOSFET then this will be quite small and you can most likely omit that resistor completely relying on the internal reistance within the GPIO (which is low, but this is only for a short period of time). I would err on the side of caution and include some kind of resistor.

The actual value isn't too important, but the higher the value will restrict high speed switching by increasing the charge time on the gate. The amount of charge needed is very small, so it would only be high frequency circuits that would suffer from having the resistor. A smaller resistor (say 220R) would improve the charge time, but in reality the difference would be negligible except at high frequencies.

bin10
Posts: 5
Joined: Thu Jan 03, 2019 12:36 am

Re: Looking for resources / new to the hardware aspect

Fri Jan 04, 2019 3:05 pm

Thanks, penguintutor and Burngate! I understand what you're saying. I'm trying to learn more about creating diagrams using Fritzing. I'll work on some basic circuit diagrams and post here for feedback before implementing. I'm watching more YT videos and studying some other diagrams in the meantime.

Thanks again!

Return to “General discussion”