Built-in project · no microcontroller

LM317 adjustable supply

An LM317 on a 12 V adapter with 240 ohms and a 2 k pot: Vout = 1.25 V x (1 + R2/R1), from 1.25 V up to the dropout, with an LED on the output. There is no microcontroller in it: the simulator solves the 6 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.

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

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

The circuit runs here once the page has loaded.

What you'll learn

  • How a reference voltage and a divider set an output voltage
  • The LM317 formula and what R1 and R2 do
  • Dropout: why the output cannot reach the input
  • Why a linear regulator turns extra voltage into heat
  • Difficulty: Beginner
  • Time: About 15 minutes
  • Parts: 7

How it works

A 12 V adapter feeds the LM317. The chip does one thing: it holds its OUT pin 1.25 V above its ADJ pin. That puts 1.25 V across the 240 ohm resistor, which means about 5.2 mA flows through it.

The same current goes on through the potentiometer to ground, and lifts ADJ above ground. A bigger pot setting means a higher output. The formula is Vout = 1.25 V x (1 + R2 / R1), plus a small term from the ADJ pin current.

At the bottom of the knob the output is 1.25 V. At the top it stops near 10.5 V, because the regulator needs about two volts across itself.

Parts list

7 parts, plus the jumper wires. They retail for about $8.20; on Mokxi they're free.

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
LM317 regulator pin INDC jack and adapter pin V+
DC jack and adapter pin V-Ground
Potentiometer pin 1Ground
LED, red pin CGround
Resistor, 240 Ω pin 2LM317 regulator pin ADJ
Potentiometer pin 2LM317 regulator pin ADJ
Resistor, 240 Ω pin 1LM317 regulator pin OUT
Resistor, 470 Ω pin 1LM317 regulator pin OUT
LED, red pin AResistor, 470 Ω pin 2

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
// An LM317 adjustable supply.
//
// There is no microcontroller here. Press Run and the simulator solves the
// circuit; turn the knob and watch the number under the LM317.
//
// WHAT IT IS. A 12 V wall adapter into the LM317's IN. The LM317 holds its
// OUT 1.25 V above its ADJ leg, and that is all it does. R1, 240 ohms from
// OUT to ADJ, has those 1.25 V across it, so 5.2 mA through it. The same
// current goes on through R2, the potentiometer from ADJ to ground, and lifts
// ADJ off ground by R2 times 5.2 mA. So:
//
//     Vout = 1.25 V x (1 + R2 / R1) + 50 uA x R2
//
// The 50 uA is the current that comes out of the ADJ leg itself, the small
// second term on the datasheet.
//
// THE KNOB. At mid travel R2 is 1 k: 1.25 x (1 + 1000/240) + 0.05 = 6.51 V,
// and the readout says 6.52 V, well inside the spread of the reference (TI
// gives 1.2 to 1.3 V). All the way down, R2 is nothing and the output is the
// 1.25 V reference. All the way up, R2 is 2 k and the formula wants
// 11.77 V, but the LM317 needs about two volts across itself: from 12 V in it
// gives about 10.5 V, and the rest is the dropout.
//
// WHY 240 OHMS. The LM317 has no ground leg, so its own operating current,
// a few milliamps, leaves by OUT. R1 has to take it. Change R1 to 10 k and
// take the LED off: the output climbs toward the input, because nothing is
// there to carry that current.
//
// THINGS TO TRY. Swap the adapter for 9 V in its properties and the top of the
// knob comes down by about 3 V. Or put a 47 ohm resistor on the output at
// 10 V and think about the heat: (12 - 10) V x 210 mA is 0.4 W in the
// regulator, and at 5 V out the same resistor costs it (12 - 5) V x 106 mA,
// 0.74 W. A linear regulator burns what it does not pass on.

Troubleshooting

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

  • The output climbs toward the input at no load This project
    The LM317 needs a minimum load, and the 240 ohm resistor provides it. Keep R1 small and keep the LED and its resistor on the output.
  • The output never goes above about 10.5 V This project
    That is dropout. Use a higher adapter voltage to get a higher output.
  • The output is stuck at 1.25 V This project
    Check the potentiometer wiring: ADJ goes to the pot's middle pin and the pot's end goes to ground.
  • Board gets too much voltage and overheats or dies. DC jack and adapter
    Check the adapter voltage before plugging in. Boards like the Uno want 7 to 12 V on the jack. A 5 V part wired to a 12 V supply can be destroyed.
  • Nothing powers on, or the polarity is backward. DC jack and adapter
    Most barrel jacks are center positive, but some are not. Check the label on the adapter, and make sure the adapter can supply enough current for the load.
  • The output voltage is wrong. LM317 regulator
    Use Vout = 1.25 V x (1 + R2/R1). R1 is between OUT and ADJ, typically 240 ohm. R2 goes from ADJ to ground. Swapped parts give the wrong voltage.
  • The regulator gets very hot or drops out. LM317 regulator
    The input must be at least about 2 V above the output. The dissipated power is (Vin minus Vout) times the current, so add a heat sink for big drops.
  • 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.

Change it and keep it

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