Projects / Small MOSFET switch with a BS170

Small MOSFET switch with a BS170

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANOBS170

    Check the pinout

    BS170 drain, gate, source with the flat face toward you.

  2. NANO16.7 mA

    Wire the load

    5V through three resistors and LEDs to the drain.

  3. NANO

    Wire the source

    Source to GND.

  4. NANO

    Add the pull-down

    10 kilohm from gate to GND.

  5. NANO

    Wire gate and pot

    D9 to the gate, pot middle leg to A0.

  6. NANO16.7 mA

    Upload

    Turn the knob and watch the LEDs.

  7. NANO16.7 mA

    Measure the switch

    Drain to source voltage with the LEDs on.

  8. NANO

    Find the threshold

    Note the average gate voltage where they start.

In short

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
See the electronics first. This build uses MOSFET switch. Try a MOSFET switch in the circuit builder and watch the voltages and currents before you wire it.

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Nano D9BS170 gatePWM drive
10 kilohm resistorBS170 gate to GNDPull-down so the gate never floats
BS170 sourceNano GNDCommon ground
Three 330 ohm resistorsNano 5V to each green LED anodeOne resistor per LED
Three LED cathodesBS170 drainSwitched side of the LEDs
Pot outer legsNano 5V and GNDSets the duty
Pot middle legNano A0Reads 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.

CheckExpected
Knob at minimumLEDs off, gate at 0 V
Knob in the middleLEDs dimmed
Knob at maximumLEDs fully on
Drain to source with LEDs onAbout 0.05 to 0.2 V
Gate disconnected from the pinPull-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 →

Ask Lark AI

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.