MOSFET switch
A 2N7000 switching an LED from a slide switch, with no gate resistor anywhere: the switch a board pin reaches for. There is no microcontroller in it: the simulator solves the 4 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
StarterRuns in your browser. Free, and no account needed.
How it works
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// A MOSFET switch.
//
// There is no microcontroller here. Press Run and the simulator solves the
// circuit: the 5 V rail pushes current through the 220 ohm resistor and the
// LED, down through the MOSFET's channel, and back to ground.
//
// Click the slide switch while it runs. In one position the gate sits at 5 V,
// the channel turns on and the LED lights; in the other the gate is on ground,
// the channel is off and nothing flows. Watch the readout under the part: it
// is the drain current, and it is the same current the LED is lit by.
//
// Two things worth noticing. There is no gate resistor, because the gate takes
// no current. This is the whole reason a MOSFET is the switch of choice for
// anything a board pin cannot drive. And the switch is wired across both
// rails, not just to one: a gate with nothing on it floats, and a floating
// gate turns a switch into a radio aerial.
//
// Things to try. Turn the gate supply down by swapping the 5 V symbol for a
// lower voltage and find the threshold, about 1.8 V for a 2N7000; below it
// the LED goes out completely. Or put the MOSFET in the properties panel and
// change the model to an IRF540N, whose channel is a hundred times lower and
// whose threshold is a good deal higher.
Parts list
6 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × Resistor, 220 Ω
- 1 × LED, red
- 1 × MOSFET
- 1 × Slide switch
How it is wired
5 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- 5 V: Resistor, 220 Ω pin 1; Slide switch pin 3
- Ground: MOSFET pin S; Slide switch pin 1
- Resistor, 220 Ω pin 2; LED, red pin A
- LED, red pin C; MOSFET pin D
- MOSFET pin G; Slide switch pin 2
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.