Author Topic: Switch power to load using 2 GPIO pins, 5V and 12V  (Read 955 times)

0 Members and 1 Guest are viewing this topic.

Offline dindondeeTopic starter

  • Contributor
  • Posts: 21
  • Country: us
Switch power to load using 2 GPIO pins, 5V and 12V
« on: June 27, 2022, 06:06:04 pm »
Hello everyone,

I'd like to control a buzzer with two volume levels(voltages) 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? My idea is to use 2 MOSFETs, one for the 5V and another for the 12V rails 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. Thank you very much!

 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12852
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #1 on: June 27, 2022, 06:24:59 pm »
No.  You need to level shift each gate drive as it needs to get all the way up to the respective supply rail to fully shut-off a P-MOSFET, so M2 will be hard on all the time (with min. -8.7V Vgs).  Also the body diode of M1 wont block voltages above 5V (the rail feeding its source), so it will dump the 12V from M2 (less one diode drop) onto your 5V rail, letting out the magic smoke from the rest of your circuit.

To fix the level shifting issue, use low Vgs threshold N-MOSFETs to drive the P-MOSFET gates, with a pullup resistor to the P-MOSFET's supply rail.  To fix the reverse conduction through M1 (via its body diode), add a schottky diode in series with M1's drain.

Does your buzzer actually work properly with 1K in series with it?
« Last Edit: June 27, 2022, 06:26:57 pm by Ian.M »
 

Offline dindondeeTopic starter

  • Contributor
  • Posts: 21
  • Country: us
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #2 on: June 27, 2022, 06:43:21 pm »
Does your buzzer actually work properly with 1K in series with it?

No, this is just an example. I am yet to adjust for current yet.

Is this circuit a better interpretation of what you suggest?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12852
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #3 on: June 27, 2022, 08:10:13 pm »
The level shifting looks sane, and as a whole it will probably work, but to be certain it doesn't do anything odd at the moment of GPIO18 switch-off, due to stored gate charge in M1 from its source being dragged up to ~11V via its body diode, I'd put D1 in series with M1 drain, not M1 source where you have it.

Caution: if the buzzer is electro-mechanical add a diode in parallel with it, cathode positive to suppress any back-EMF.
« Last Edit: June 27, 2022, 08:11:52 pm by Ian.M »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #4 on: June 27, 2022, 09:20:23 pm »
Why not use a single IO pin, with an emitter follower with a filter and PWM to adjust the volume?
 

Offline dindondeeTopic starter

  • Contributor
  • Posts: 21
  • Country: us
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #5 on: June 28, 2022, 01:53:35 am »
Why not use a single IO pin, with an emitter follower with a filter and PWM to adjust the volume?

Could you please point me to a resource, I'd like to learn an alternative method... my google search for emitter follower pwm is not yielding much. Thank you!
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #6 on: June 28, 2022, 03:21:15 am »
Here's a video demonstrating PWM drive with an LED and buzzer:

LAB 8 PWM using Arduino (LED and Buzzer) || Arduino Series || Circuit Diagram || Code || Project - Keep Learning
https://youtu.be/1HA0mkNnV5Q

Not all buzzers are the same so it's worth trying it out with your particular buzzer. In the video the LED and buzzer are driven directly from an I/O pin. You'll probably want to use a MOSFET like this:

1523938-0

where the "5V" rail is really your 12V supply.

For more details on PWM you might find this video helpful:

What is PWM? Pulse Width Modulation tutorial! - Afrotechmods
https://youtu.be/YmPziPfaByw
« Last Edit: June 28, 2022, 03:25:18 am by ledtester »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #7 on: June 28, 2022, 07:10:46 am »
What sort of buzzer is it?

By the looks of it ledtester assumed it required an external drive circuit and I thought it has an internal driver.

Does the buzzer work, when connected directly to 12V?
 

Offline dindondeeTopic starter

  • Contributor
  • Posts: 21
  • Country: us
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #8 on: June 28, 2022, 05:29:51 pm »
What sort of buzzer is it?

By the looks of it ledtester assumed it required an external drive circuit and I thought it has an internal driver.

Does the buzzer work, when connected directly to 12V?

Yes, the buzzer works with 12V.
Here's more information on it - https://www.digikey.com/en/products/detail/cui-devices/CPI-1762-90-SMT-TR/11480417

Here's a video demonstrating PWM drive with an LED and buzzer:

LAB 8 PWM using Arduino (LED and Buzzer) || Arduino Series || Circuit Diagram || Code || Project - Keep Learning
https://youtu.be/1HA0mkNnV5Q

Not all buzzers are the same so it's worth trying it out with your particular buzzer. In the video the LED and buzzer are driven directly from an I/O pin. You'll probably want to use a MOSFET like this:

(Attachment Link)

where the "5V" rail is really your 12V supply.

For more details on PWM you might find this video helpful:

What is PWM? Pulse Width Modulation tutorial! - Afrotechmods
https://youtu.be/YmPziPfaByw

Thank you so much. This seems more elegant.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Switch power to load using 2 GPIO pins, 5V and 12V
« Reply #9 on: June 29, 2022, 11:00:16 am »
I was thinking filter the PWM so the buzzer is powered from a variable voltage.
 
The following users thanked this post: ledtester


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf