Built-in project · no microcontroller

BSS138 level shifter

One channel of the bi-directional 3.3 V to 5 V level shifter: a BSS138 and two 10k pull-ups. Pull either side low and the other follows. There is no microcontroller in it: the simulator solves the 7 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.

Teaching? Assign it to your class in one click.

Intermediate About 20 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $5.90. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Why 3.3 V and 5 V parts need a level shifter
  • A MOSFET as a two-way switch
  • Pull-up resistors on each side
  • The body diode of a MOSFET
  • Difficulty: Intermediate
  • Time: About 20 minutes
  • Parts: 8

How it works

This is a circuit with no microcontroller. A BSS138 MOSFET sits between a 3.3 V side and a 5 V side. Each side has a 10k pull-up resistor to its own supply. The gate is held at 3.3 V. Two meters show the voltage on each side.

With both switches open, each side sits at its own supply and the MOSFET is off. Close the 3.3 V switch and that side drops to 0 V, which turns the channel on and pulls the 5 V side down too. Close the 5 V switch instead and the MOSFET's body diode pulls the 3.3 V side down until the channel turns on. So signals pass both ways.

Parts list

8 parts, plus the jumper wires and 2 bench instruments. The parts retail for about $5.90; on Mokxi they're free, and so are the instruments.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
MOSFET pin G3.3 V
Resistor, 10k Ω (1) pin 23.3 V
Resistor, 10k Ω (2) pin 15 V
Slide switch (1) pin 3Ground
Slide switch (2) pin 3Ground
Multimeter (1) pin COMGround
Multimeter (2) pin COMGround
Resistor, 10k Ω (1) pin 1MOSFET pin S
Slide switch (1) pin 2MOSFET pin S
Multimeter (1) pin VMOSFET pin S
Resistor, 10k Ω (2) pin 2MOSFET pin D
Slide switch (2) pin 2MOSFET pin D
Multimeter (2) pin VMOSFET pin D

The notes that come with it

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.

sketch.ino
// One channel of a BSS138 level shifter. Left meter: the 3.3 V side (the
// source); right meter: the 5 V side (the drain); a 10k pull-up on each.
//
// Both switches open, each side sits at its own supply and the BSS138 is
// off. Pull the 3.3 V side low and the channel pulls the 5 V side down with
// it. Pull the 5 V side low instead: the body diode drags the source down
// until the channel turns on, so it works both ways.

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • Both meters read 0 V. This project
    Check that each 10k resistor goes to its own supply: one to 3.3 V and one to 5 V.
  • The 5 V side does not follow the 3.3 V side. This project
    The gate must be on 3.3 V, the source on the 3.3 V side and the drain on the 5 V side.
  • The load stays partly on or flickers when the pin is not driving, such as at boot or in input mode. MOSFET
    A floating gate picks up noise. Add a pull-down of about 10 k from gate to source on an N-channel part, or pull a P-channel gate up to its source voltage.
  • The N-channel load is always on or never turns on. Source, gate, and drain legs were mixed up. MOSFET
    Use the N-channel as a low-side switch: load to the supply, drain to the load, source to ground. Check your datasheet pinout, since 2N7000 and BS250 differ. Share the grounds.
  • The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
    Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
  • A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
    Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
  • The input reads random values in one position. Slide switch
    A switch only connects or disconnects. Add a pull-up or pull-down resistor, or use INPUT_PULLUP, so the pin has a defined level when the switch is open.
  • The load never turns on when the switch is flipped. Slide switch
    Use the center (common) leg and one outer leg. The unused outer leg goes nowhere. Check that the switch is in series with the load.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.