0
\$\begingroup\$

I will like to use 2 GPIOs on a raspberry pi to switch on a device (piezo buzzer), using 5V or 12V at a time.

My idea is to use two MOSFETs and place pullup resistors on the gates of the MOSFETs from the GPIOs to ensure they are on when needed. Then a program ensures the 2 GPIOs can never be on at the same time, just one at a time.

Is this safe/legal? I know that I will need P-channel MOSFETS, here's a schematic of my thought process and I hope you can correct or tender suggestions with better solutions.

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
5
  • \$\begingroup\$ Is the load just an example or R6 is really an external resistor in series with the buzzer, and 1k is really its value? \$\endgroup\$
    – devnull
    Jun 25, 2022 at 19:54
  • 1
    \$\begingroup\$ @devnull they're both just examples \$\endgroup\$
    – user49706
    Jun 25, 2022 at 20:02
  • \$\begingroup\$ Thanks. I wonder (in a XY Problem sense) if the question isn't really: I'd like to control a buzzer with two volume levels using GPIOs. I have 3.3V, 5V and 12V rails available and the MCU is connected to the 3.3V rail. Does this circuit work for this? \$\endgroup\$
    – devnull
    Jun 25, 2022 at 20:10
  • 1
    \$\begingroup\$ @devnull i appreciate the correction, that is a clearer explanation of what i am trying to do, thanks. \$\endgroup\$
    – user49706
    Jun 25, 2022 at 20:27
  • \$\begingroup\$ Which piezo buzzer is it? \$\endgroup\$ Jun 26, 2022 at 20:37

1 Answer 1

1
\$\begingroup\$

One problem with your circuit is that you would not be able to turn off the PMOS given that your GPIOs can drive up to 3.3V only, when high.

When GPIO13 and GPIO18 are driven low, no issues, the PMOS will see high enough voltage differential between gate and source to fully turn on. When those GPIOs are driven high (3.3V), there is still a significant differential between gate and source, especially with the PMOS driven by GPIO18 — 3.3V at the gate minus 12V at the source means -8.7V, more than enough to turn on a PMOS. In the case of the PMOS driven by GPIO13, the differential would be 3.3V-5V = -1.7V, maybe not enough to fully turn it on, but enough to be partially on.

You may want to do something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

It flips your logic. Now a high on GPIO13 for example, means M1 will conduct and vice versa. This configuration will ensure the PMOS are truly OFF when they need to be. Notice how the gates of the PMOS are pulled-up to the same voltage as what's at the source terminal, that way, when the low side NMOS are not active, the voltage across gate and source on those PMOS is 0V, keeping them off.

There's a complication though. When the 12V PMOS is turned on, current will still find a path from 12V to 5V through M1's body diode, so you need to protect the 5V rail by adding a diode, for example (See D1). Another possibility is replacing M1 with a PNP transistor, that way you would not need D1 but will need a resistor to the base to limit the current through it.

\$\endgroup\$
3
  • \$\begingroup\$ thanks for the suggestion. circuit lab simulation seems to show no voltage at the buzzer's node. perhaps, could i be doing something wrong? \$\endgroup\$
    – user49706
    Jun 25, 2022 at 20:29
  • 1
    \$\begingroup\$ @Big6 Don't the FETs have internal parastic diode in them? If you turn on the 12V to buzzer, current would flow from 12V to buzzer node, and via diode of M1 to 5V, likely destroying something in the process. \$\endgroup\$
    – Justme
    Jun 25, 2022 at 23:29
  • \$\begingroup\$ @Justme Thanks for pointing that out! \$\endgroup\$
    – Big6
    Jun 26, 2022 at 14:46

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.