Question 9.4: You want to control the power to a high-power, low-voltage D......

You want to control the power to a high-power, low-voltage DC device such as a 12V LED module.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

These high-power LEDs use far too much current to light directly from a GPIO pin. They also require 12V rather than the 3.3V. To control such a high-power load, you need to use a transistor.

In this case, you will use a high-power type of transistor called a MOSFET (metal oxide semiconductor field effect transistor), which costs less than a dollar but can handle loads up to 30 amps, many times more than is required for the high-power LEDs. The MOSFET used is a FQP30N06 (see “Transistors and Diodes” on page 381).

Figure 9-4 shows how you can connect a MOSFET on a breadboard. Make sure that you correctly identify the positive and negative supply leads for the LED module.

To make this recipe, you will need:

• Breadboard and jumper wires (see “Prototyping Equipment” on page 380)
• 1kΩ resistor (see “Resistors and Capacitors” on page 380)
• FQP30N06 N-Channel MOSFET (see “Transistors and Diodes” on page 381)
• 12V power adapter
• 12V DC LED module

The Python code to turn the LED panel on and off is exactly the same as if we were controlling a single low-power LED without the MOSFET (see Recipe 9.2).

You can also use PWM with the MOSFET to control the brightness of the LED module (see Recipe 9.2).

Discussion

Whenever you need to power anything significant using the GPIO connector, use batteries or an external power adapter. The GPIO connector can only supply relatively low currents (Recipe 8.2). In this case, you’ll use a 12V DC power adapter to provide the power to the LED panel. Pick a power adapter that has sufficient power handling. So, if the LED module is 5W, then you need at least a 12V 5W power supply (6W would be better). If the power supply specifies a maximum current rather than power, then you can calculate its power by multiplying the voltage by the maximum current. So, a 500 mA 12V power supply can provide 6 W of power.

The resistor is necessary to ensure that the peak currents that occur as the MOSFET switches from off to on and vice versa do not overload the GPIO pin. The MOSFET switches the negative side of the LED panel, so the positive supply is connected directly to the positive side of the LED panel, and the negative side of the LED panel is connected to the drain of the MOSFET. The source connection of the MOSFET is connected to GND, and the MOSFET’s gate pin controls the flow of current from the drain to the source. If gate voltage is above about 2V, the MOSFET will turn on and current flows through both it and the LED module.

This circuit is suitable for controlling the power to other low-voltage DC devices. The only real exceptions are motors and relays, which require some extra treatment (see Recipe 10.3).

See Also

Check out the datasheet for the MOSFET.

If you would like to create a graphical user interface with which to control your LED module, see Recipe 9.7 for simple on/off control and Recipe 9.8 for variable control of the brightness with a slider.

Table A-5. Transistors and diodes
FQP30N06 N-channel MOSFET transistor SparkFun: COM-10213, Adafruit: 355
2N3904 NPN bipolar transistor SparkFun: COM-00521, Adafruit: 756
1N4001 diode SparkFun: COM-08589, Adafruit: 755
Table A-3. Prototyping equipment
Description Suppliers
M-M jumper wires SparkFun: PRT-08431, Adafruit: 759
M-F jumper wires SparkFun: PRT-09140, Adafruit: 825
F-F jumper wires SparkFun: PRT-08430, Adafruit: 794
Half-sized breadboard SparkFun: PRT-09567 Adafruit: 64
Pi Cobbler Adafruit: 1105
Table A-4. Resistors and capacitors
270Ω 0.25W resistor Mouser: 293-270-RC
470Ω 0.25W resistor Mouser: 293-470-RC
1kΩ 0.25W resistor Mouser: 293-1k-RC
3.3kΩ 0.25W resistor Mouser: 293-3.3k-RC
4.7kΩ 0.25W resistor Mouser: 293-4.7k-RC
10 kΩ trimpot Adafruit: 356, SparkFun: COM-09806, Mouser: 652-3362F-1-103LF
Photoresistor Adafruit: 161, SparkFun: SEN-09088
220nF capacitor MCM: 31-0610, Mouser: 80-C322C224M5U5HA
9-4

Related Answered Questions

Question: 9.11

Verified Answer:

Assuming you have a 5V volt meter, you can use a P...
Question: 9.10

Verified Answer:

The way to do this is to use a technique called Ch...
Question: 9.9

Verified Answer:

Use PWM to control the power to each of the red, g...
Question: 9.8

Verified Answer:

Using the Tkinter user interface framework, write ...
Question: 9.7

Verified Answer:

Using the Tkinter user interface framework, write ...
Question: 9.5

Verified Answer:

Use a relay and small transistor. Figure 9-5 shows...
Question: 9.1

Verified Answer:

Connect an LED (see “Opto-Electronics” on page 381...
Question: 9.3

Verified Answer:

Use a piezo-electric buzzer connected to a GPIO pi...
Question: 9.6

Verified Answer:

Use a PowerSwitch Tail II (see “Modules” on page 3...