Small MOSFET switch with a BS170
Build it step by step
0 of 8 doneCheck the pinout
BS170 drain, gate, source with the flat face toward you.
Wire the load
5V through three resistors and LEDs to the drain.
Wire the source
Source to GND.
Add the pull-down
10 kilohm from gate to GND.
Wire gate and pot
D9 to the gate, pot middle leg to A0.
Upload
Turn the knob and watch the LEDs.
Measure the switch
Drain to source voltage with the LEDs on.
Find the threshold
Note the average gate voltage where they start.
How do you build a small MOSFET switch with a BS170?
A small N-channel MOSFET switches three LEDs from a board pin, and you measure the gate threshold and the voltage across the switch. You need Arduino Nano, BS170 N-channel MOSFET, LED 5 mm green × 3, Resistor 330 Ω × 3, Resistor 10 kΩ, Potentiometer 10 kΩ, Digital multimeter, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 75 minutes.
- Level
- Beginner
- Time
- About 75 min
- Parts
- 9
Parts list
- Development BoardsBuyArduino Nano × 1
- SemiconductorsBuy
- SemiconductorsBuyLED 5 mm green × 3
- PassivesBuyResistor 330 Ω × 3
- PassivesBuyResistor 10 kΩ × 1
- PassivesBuy
- Tools & InstrumentsBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Nano D9 | BS170 gate | PWM drive |
| 10 kilohm resistor | BS170 gate to GND | Pull-down so the gate never floats |
| BS170 source | Nano GND | Common ground |
| Three 330 ohm resistors | Nano 5V to each green LED anode | One resistor per LED |
| Three LED cathodes | BS170 drain | Switched side of the LEDs |
| Pot outer legs | Nano 5V and GND | Sets the duty |
| Pot middle leg | Nano A0 | Reads the knob |
Code
A MOSFET is a switch controlled by voltage, not current: the gate draws almost nothing, and a voltage above the threshold lets current flow from drain to source. The BS170 is a small N-channel part, which is why the 10 kilohm pull-down matters, because a floating gate can turn the switch on from stray charge. Check the pinout in the datasheet before you build: a BS170 and a 2N7000 look identical, but the BS170 has drain, gate, source in order from the left with the flat face toward you and the 2N7000 has them reversed. The three LEDs each take roughly 9 milliamps, so about 26 milliamps flows through the transistor, which is well within its small rating. Measure the voltage across the drain and source with the LEDs fully on, and you should see only a small voltage, because the transistor on-resistance is a few ohms, so the loss is about the current times that resistance. To see the gate threshold, turn the knob slowly and watch the LEDs: nothing happens until the PWM average passes about two volts and then they come up. At 5 volts the BS170 is not fully on, so a logic-level MOSFET gives lower resistance for bigger loads, but for a few LEDs it works well. The pot here only selects PWM, so the Nano pin and the transistor stay at safe levels.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int GATE = 9, POT = A0;
void setup() {
pinMode(GATE, OUTPUT);
Serial.begin(9600);
}
void loop() {
int knob = analogRead(POT); // 0 to 1023
int duty = knob / 4; // 0 to 255
analogWrite(GATE, duty); // PWM dims the LEDs through the MOSFET
float gateAvg = duty * 5.0 / 255.0; // average gate voltage
Serial.print("Duty "); Serial.print(duty * 100 / 255);
Serial.print(" % average gate "); Serial.print(gateAvg, 2);
Serial.println(" V");
delay(300);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Duty 50 % average gate 2.51 V Duty 49 % average gate 2.49 V Duty 50 % average gate 2.51 V Duty 49 % average gate 2.49 V Duty 50 % average gate 2.51 V Duty 49 % average gate 2.49 V
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Knob at minimum | LEDs off, gate at 0 V |
| Knob in the middle | LEDs dimmed |
| Knob at maximum | LEDs fully on |
| Drain to source with LEDs on | About 0.05 to 0.2 V |
| Gate disconnected from the pin | Pull-down keeps the LEDs off |
If it does not work
LEDs never light
Check the pinout, it may be reversed.
LEDs always on
Check the pull-down and that the gate is not floating.
LEDs dim even at full
The BS170 is not fully on at 5 V, accept this or use a logic-level part.
Flicker at low duty
Normal PWM behaviour at 490 Hz.
Transistor warm
Check the resistors are 330 ohm.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the small MOSFET switch with a BS170?
Arduino Nano, BS170 N-channel MOSFET, LED 5 mm green × 3, Resistor 330 Ω × 3, Resistor 10 kΩ, Potentiometer 10 kΩ, Digital multimeter, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the small MOSFET switch with a BS170 take to build?
About 75 minutes for a beginner maker, in 8 steps.
How do I know the small MOSFET switch with a BS170 works?
Knob at minimum: LEDs off, gate at 0 V. Knob in the middle: LEDs dimmed. Knob at maximum: LEDs fully on.
LEDs never light: what should I check?
Check the pinout, it may be reversed.
LEDs always on: what should I check?
Check the pull-down and that the gate is not floating.
LEDs dim even at full: what should I check?
The BS170 is not fully on at 5 V, accept this or use a logic-level part.
Flicker at low duty: what should I check?
Normal PWM behaviour at 490 Hz.
