Using MOSFETS and an Arduino

Thread Starter

Mock10chicken

Joined Oct 20, 2025
16
Hello, I am trying to make a breadboard design where I have a USB-C breakout board connected to an Arduino which is connected to a MOSFET and then an LED light. I want to make it so that when the USB-C cable is inserted into the breakout board it turns on the LED light and when the cable is pulled out of the breakout board it turns off the LED light. I have bought both N and P channel MOSFETS, an ARDUINO SEEED Studio XIAO SAMD21, a bunch of LED lights, A breadboard, and a 5v breadboard power supply. I would love someones help with how to conenct all of these parts to make it work properly, and how to code the ARDUINO.
 

BobTPH

Joined Jun 5, 2013
11,463
Probably don't want to do that if connecting "a bunch of LED lights", as the TS wrote.
Where did he write that? I see that he wants to turn on “the LED” not a bunch of LEDs. He said he HAS a bunch of LEDs.

Hello, I am trying to make a breadboard design where I have a USB-C breakout board connected to an Arduino which is connected to a MOSFET and then an LED light. I want to make it so that when the USB-C cable is inserted into the breakout board it turns on the LED light and when the cable is pulled out of the breakout board it turns off the LED light.
 

panic mode

Joined Oct 10, 2011
4,867
ok, for a big bunch of LEDs one would probably not want to use USB port as power source.

so connect GND from USB C to negative side of that PSU.
connect gate of NMOS to VBUS of USB C.
connect LEDs in suitable configuration between PSU+ and NMOS drain.

or state actual objective. i am still thinking that TS simply wants to setup his ArduinoIDE so it can program XIAO SAMD21 and as a proof of life, he would like one or more MOSFETs driven by the MCU to turn on some LEDs.

my suggestion is to forget about mosfets (for now). just get one LED with series resistor connected to MCU port, then download and install all software as shown in post #2 and try blink sketch. then we can talk more...
 

BobTPH

Joined Jun 5, 2013
11,463
Post #1
"I have bought both N and P channel MOSFETS, an ARDUINO SEEED Studio XIAO SAMD21, a bunch of LED lights, A"
Fine, read it any way you want. I have a bunch of LEDs myself. That does not mean I will use them all in my next project.

I am going with “and then an LED light”, singular.
 

panic mode

Joined Oct 10, 2011
4,867
possibly it is already toast... did you not check product documentation? or at least pinout?
why is 9V connected to 3.3V? that is a short circuit.
1761150543629.png
 
Last edited:

panic mode

Joined Oct 10, 2011
4,867
this is how XIAO should be powered. you need to use regulator to reduce 9V to 5V and then connect that 5V to XIAO 5V pin.
on the XIAO is small regulator that internally drops 5V to 3.3V.
1761151022070.png
 

panic mode

Joined Oct 10, 2011
4,867
still you had 5V supply (assuming that is pictured as the 9V battery) connected to 3.3V. MCU operate at 3.3V and connecting higher voltage can and probably will destroy it.

1761153726723.png

and here are couple of LEDs with and without MOSFETs. MOSFETs of course need to be logic type
1761154713232.png
 
Last edited:

lichurbagan

Joined Jul 4, 2025
120
Hello, I am trying to make a breadboard design where I have a USB-C breakout board connected to an Arduino which is connected to a MOSFET and then an LED light. I want to make it so that when the USB-C cable is inserted into the breakout board it turns on the LED light and when the cable is pulled out of the breakout board it turns off the LED light. I have bought both N and P channel MOSFETS, an ARDUINO SEEED Studio XIAO SAMD21, a bunch of LED lights, A breadboard, and a 5v breadboard power supply. I would love someones help with how to conenct all of these parts to make it work properly, and how to code the ARDUINO.


You can easily make this project work using your Seeed XIAO SAMD21, a USB-C breakout, and an N-channel MOSFET. Connect the USB-C VBUS (5 V) through a simple voltage divider (10 kΩ and 20 kΩ resistors) to one of the XIAO’s input pins to detect when a USB cable is plugged in. When the cable is inserted, the input pin reads HIGH, and when it’s unplugged, it reads LOW. Be sure all grounds — USB-C breakout, XIAO, and LED circuit — are connected together.


Use the XIAO to drive the gate of an N-channel MOSFET through a 220 Ω resistor, with a 100 kΩ pulldown to ground. The LED’s positive side connects to 5 V (through a resistor), and the negative side goes to the MOSFET drain, with the source connected to ground. When VBUS is detected, the XIAO sets the gate HIGH to turn on the LED; when the cable is removed, the MOSFET turns off, and the LED goes dark.


You can check out a related project. https://www.pcbway.com/project/shareproject/P_Channel_Mosfet_Driver_Breakout_b361c747.html It shows a similar concept of using MOSFETs for switching and control. It’s a useful reference for understanding transistor-based power switching in small circuits like yours.
 

Thread Starter

Mock10chicken

Joined Oct 20, 2025
16
still you had 5V supply (assuming that is pictured as the 9V battery) connected to 3.3V. MCU operate at 3.3V and connecting higher voltage can and probably will destroy it.

View attachment 357483

and here are couple of LEDs with and without MOSFETs. MOSFETs of course need to be logic type
View attachment 357484
is the bottom picture that you attached a revised version of my setup that you think will work
 
Top