Switch power to load using 2 GPIO pins, 5V and 12V - Page 1
Forum section: electronics / beginners

author: dindondee
author_rank: Contributor
timestamp: June 27, 2022, 06:06:04 pm
content: 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!

author: Ian.M
author_rank: Super Contributor
timestamp: June 27, 2022, 06:24:59 pm
content: 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?

author: dindondee
author_rank: Contributor
timestamp: June 27, 2022, 06:43:21 pm
content: Quote from: Ian.M on June 27, 2022, 06:24:59 pmNo, this is just an example. I am yet to adjust for current yet.Is this circuit a better interpretation of what you suggest?

author: Ian.M
author_rank: Super Contributor
timestamp: June 27, 2022, 08:10:13 pm
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: June 27, 2022, 09:20:23 pm
content: Why not use a single IO pin, with an emitter follower with a filter and PWM to adjust the volume?

author: dindondee
author_rank: Contributor
timestamp: June 28, 2022, 01:53:35 am
content: Quote from: Zero999 on June 27, 2022, 09:20:23 pmCould 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!

author: ledtester
author_rank: Super Contributor
timestamp: June 28, 2022, 03:21:15 am
content: 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 Learninghttps://youtu.be/1HA0mkNnV5QNot 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: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! - Afrotechmodshttps://youtu.be/YmPziPfaByw

author: Zero999
author_rank: Super Contributor
timestamp: June 28, 2022, 07:10:46 am
content: 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?

author: dindondee
author_rank: Contributor
timestamp: June 28, 2022, 05:29:51 pm
content: Quote from: Zero999 on June 28, 2022, 07:10:46 amYes, 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/11480417Quote from: ledtester on June 28, 2022, 03:21:15 amThank you so much. This seems more elegant.

author: Zero999
author_rank: Super Contributor
timestamp: June 29, 2022, 11:00:16 am
content: I was thinking filter the PWM so the buzzer is powered from a variable voltage.