Using A Voltage Regulator As A Constant Current Source

[Afroman] contacted us to share his new video on the LM317. The humble LM317 adjustable voltage regulator is everywhere. From wifi routers, to high spec lab equipment. Given a noisy input and a variable load, a voltage regulator will give a nice clean, stable output voltage. We’ve covered the basic operation and usage of the LM317 many times. But even the most common of parts can be used in new and interesting ways.

In his video [Afroman] describes how the LM317 can be used to regulate current rather than voltage to provide a constant current source under varying load. This can useful for a number of applications including driving LEDs and laser diodes. While this circuit may not be as efficient as an LED driver module or a switching solution the LM317 is cheap and readily available. [Afroman] also describes how the circuit works in detail allowing us to enjoy this ubiquitous part in this slightly unusual application.

77 thoughts on “Using A Voltage Regulator As A Constant Current Source

      1. yeah, everyone who doesn’t have the same level of knowledge as someone with a degree in electrical engineering is a “looser”. teenagers are so dumb, amirite?! LOL!!!one112jio!!!oijfsdla;

        take you elitism and leave.

        1. This is a really basic stuff that every amateur used to know. You don’t need a degree to read datasheets. I don’t have one. Knowing basic circuits with basic components is just one of those things that helps developing better designs. Even master Arduino programmer can’t do much without learning analog circuit design.
          I expected HaD readers and editors know, how to use basic circuit from a datasheet to limit current. Turning this into article is just pointless. My expectations were too high. It seems that I could write an article about using a pushbutton as an input for Arduino and it will be posted here as an article because that would be revelation for some…

          1. > This is a really basic stuff that every amateur used to know.
            the same can be said about lots of things. how are your hunting, farming and survival skills? you know how to make a fire using a strip of leather right? come on, this is really basic stuff even kids know!

            > My expectations were too high
            take you elitism and leave, you arrogant piece of shit.

        2. This isn’t elitism. It’s been very well know and used for decades, even by hobbyists. This is on the same level as putting a resistor in series with a LED. It’s not front-page worthy.

          1. I agree that making this out to seem like a new/amazing thing, but everyone deserves to learn the basics, ESPECIALLY little lego circuits like this one. No need for anyone to act like they are too smart for the basics.

          2. Yes, it’s a handy little thing which people should know and learn as some sort of basic electronics learning. I just don’t think this is the place to learn it, displayed as a “hack” right there on the front page…

          3. So is half of the other stuff [Afroman] has been posting in a video series aimed at TEACHING THE BASICS! I think there might even *gasp* be a video describing Ohm’s law. Best go find a fainting couch.

          4. @Quin
            Its one thing to teach basics to people and it’s completely different thing to post it to hacker news. News is Afroman is making (good?) video series to teach basics not that one lessons teaches you 1+2=4 :-)

      2. A common use for LM317 configured as a current source is as a high impedance load for a power MOSFET source follower. Every DIY audiophile has stumbled across this as the output stage of a headphone amplifier. Google ‘Szerkes headphone’ for numerous examples. Within its voltage ratings it also works pretty well as a high impedance anode load for vacuum tubes, as documented by Walt Jung.

      3. As someone coming from a Mechanical background and learning more about the Electrical side, how would I have known to look at the datasheet? Datasheets are great if you know what you’re looking for (pinouts on 7-segment displays, from personal examples), but for someone new how are they to know a voltage regulator can do more than regulate voltage?

        And yeah I have started with Arduino, and placed an order for a few AVR chips today to build standalone circuits, everyone has to start somewhere and build on what they learn.

        1. Well.. for starters, a constant current source usually employs slightly different hardware and a shunt resistor that is used to measure the current being output by the device. The hardware outputs a variable voltage depending on the voltage drop across the shunt resistor.
          Knowing this means that many of use will instinctively think of using a constant voltage source and a well chosen resistor to turn a small voltage regulator into a current regulator.
          As someone just starting out, tricks like this and the intuition about bending electronics to your will is not quite there yet, and that’s no big deal. You’ll pick it up as you learn.
          It’s also a good practice to at least glance at the datasheet for any component you use in a project to confirm that you have not exceeded input or output specifications.

          And yeah… I do agree that this is not really front-page worthy. HaD is not only for the ‘elite’, but is also for a lot of hobbyists… I guess the line was drawn a little too close to the entry level hobbyists on this one.

      4. You do have to understand your basic parts in mechanical engineering – material strength, types of screws, and know about the parts you are using. Is that a bit too much to read the datasheet at least for the parts that you are using? It is not like you have to read 1000+ pages of user manual for an ARM chip here.

        There are 8 millions search results on google for constant current. The front page would already point you to some good sources. wiki also have such a basic topic.

    1. This HaD post is both a good thing and a bad thing: 1. Bad Thing: Very basic knowledge, this post never should have made the cut. 2. Good Thing: This post is NOT about a HaD Contest!

  1. A circuit like hat is even more useful as a over current limiter – I use a 3.3V regulator and a 100 ohm resistor as a limiter in a power supply that tests 4-20mA current loop devices, so that they don’t smoke the power supply or themselves.

    1. ^ This.

      This is the reason why posts like this are excellent and should keep on coming. Not everyone has the same level of education, and some of us are just getting started. If you already know about this, great. But don’t make those who don’t, for whatever reason, feel like crap just because you’ve learned something they haven’t.

    2. The only thing wrong with this post is the sentence “But even the most common of parts can be used in new and interesting ways.”
      It’s a very common use of the LM317. But I think more education pieces are a good thing.

    3. Exactly. You don’t know what you don’t know. I’ve used voltage regulators before, but haven’t read the datasheets, so I didn’t come across the information covered in this video, and didn’t realize that it was possible. What’s more, I’m sure that there are at least a few people who watched it that have been buying pre-made CC PSU’s for their low-current projects, and are now slapping their foreheads before heading over to eBay.

  2. It is worth front-paging very basic analog electronics. It’s possible that a hobbyist without any formal tech training would be unaware of this.
    The corollary to this: anyone unaware of the relationship between simple voltage and current regulators should admit that there’s a lot they don’t know and keep learning basics.

  3. You know, if the articles are beneath your knowledge level, you don’t need to read them. Amazes me the # of elitist idiots here who forget they were once beginners too. Even if you aren’t a beginner, there’s no life rule that states you know every basic use that there is to know of a part. It’s a product of the “me generation”, the elitist only care about themselves, beginners and every1 else be damned. Good thing everyone doesn’t think this way, or education would be dead. I, for one, would like to thank Hackaday for continuing to post educational posts. I don’t always learn something new, but I realize others might – and that’s a good thing. Thanks Hackaday!

    1. Absolutely agree. When I think back to when I was a kid, I now realize how little I knew about the world (without realizing it then). After my Bachelors I thought “now I know everything”. After my Masters I thought “now I know everything”. After my PhD I thought “why did I waste my time on doctoral work?”. But in my 40’s I think back to when I was a teenager and think “man, I was an idiot back then”.

      Everyone starts somewhere. And with the broad fan base of Hackaday, no article can suit all the readers. I have read comments from just about every field I can thing of- from ME’s and EE’s to machinists, software engineers, medical students, and teenagers that are still interested in learning more about the world.

      It is a wonderful mixture of backgrounds and knowledge bases, and I enjoy reading the constructive comments some people leave. But as you said, some people think they know everything, so I just skip over those.

    2. Some of those people will grow up eventually. Some of them will need to work with as many scientists and engineers as I have before they realize how little they know.

  4. For the folks who learned something from this article, here’s something else you might like.

    The LM317 is a simple part to understand. It just pushes out more power until the voltage on its feedback pin reaches 1.2V, and then adjusts power up or down as needed to hold that same feedback voltage. When used as a constant voltage (CV) regulator, you attach a voltage divider between output, feedback, and ground, so that it produces 1.2V feedback at the desired output voltage. Here, [Afroman]’s shown how to use a single resistor between the load and ground, with the feedback connected between the load and the resistor, to make a constant current (CC) regulator instead..

    A complete switching regulator IC and all the associated circuitry is harder to understand. But ignore everything except the feedback scheme, and guess what? They all work the same as the LM317! Well, the voltage it tries to maintain on the feedback pin is probably different. For example, a MP2307 tries to keep it at 0.925V, versus the LM317’s 1.2V. Other switching regulator ICs will have different voltages too, but a quick datasheet check will give you the feedback pin and the expected voltage; without having to understand the whole datasheet.

    This means that if you already have one of those cheap, adjustable voltage, switching power supply modules from Ebay or whatnot on hand, you can disconnect the existing resistors/potentiometers/trimmers from the feedback pin, connect a single resistor like [Afroman] shows instead, and voila – you’ve got a switching constant current supply! An easy solution if you want to save some power, or if your LM317 was getting too hot.

    1. suppose I wanted to bias a transistor amp in ab but to avoid thermal runaway i wanted to restrict the max current but keep the voltage constant at a set voltage because i don’t understand what i’m doing. . could i series a voltage regulator after the current regulator?

      1. You could, but what you should think about is if the current regulator has some runaway or not and how much it is compared to the regular way.
        It is not really done because that current regulator will need to drop some voltage to function, but as design safety or experimenting, go ahead.

        1. I already have that regulator but did not know it could do current and voltage simultaneously. I was having difficulty understanding how to implement it so I left in in a box.

  5. Don’t forget a plain old JFET makes a dandy constant-current source too. Programmable via resistor if desired, or not: It’s a simple two-terminal, one-component solution if you choose the FET with the current you want.

    1. Is there a way to choose a JFET for a particular current, within a reasonable tolerance (say 20%), from datasheet specs only? The articles I read about using JFETs as current limiters were strangely silent on this detail. I tried a few varieties I had on hand, but couldn’t find a good correlation between real-world results and any datasheet value. Forward gate current (Igf) seemed slightly predictive, but there were still differences up to 50%.

      For the tested varieties I also had SPICE models for, simulations came quite close to real-world. So there’s that, but it’s dependent on having a model (and that it be accurate), plus it’s still a trial-and-error process I’d prefer to eliminate.

      1. Horowit’s new book had a beautiful graph that shows that I believe I saw in LadyAda’s interview. Either way the 3rd edition is worth getting I think. Afraid it’s going to wait for my Christmas list this year.

        1. I was going to mention H&H in their 2nd ed. comment on the relatively poor precision. After your comment I went and looked at my 3rd. ed. and, yes, the 3rd ed. has expanded a lot on it: 3+ pages on JFET current sources, in section 3.2.2 (pp. 142-146).

          I think you are referring to figure 3.25, which shows 7 samples of 2N5486 exhibiting a range of sink currents from 5.7-9.5 mA (in this case with a 140 ohm source resistor — with no resistor, currents are higher and have even more range, roughly 10-20 mA)

      2. I don’t think so, it is a very uncontrolled parameter and fabricated devices are not binned per such parameter. (like white LEDs can be binned based on colour temperature and bough to match whatever you desire).

    2. JFET current sources are very sensitive to changes in temperature. Lots of better solutions abound. Do some research before going down the seemingly trivial simple JFET current source path. The Devil lurks in the details.

  6. To all those who are saying this is nothing new and you should just know it,,,,I’m 40 years old and have never needed to use this, so I didn’t know. Remember that for every 2 things you know there are a hundred you DON’T. It may not be elitist to say that all people should just know it, but it sure as hell is ignorant. Not everyone learns that same things at the same time.

      1. I have seen that happened in one of my early products. The heating cause non-linearity in my programmable constant current source at high output. I didn’t know about tempco of the sampling resistor back then.

  7. I think the reason why everyone is pissed is because this basic and regular knowledge while it is being presented on a website that deals with “hacking” as in using things the way they were not intended to. We expect to come here and learn about cool new ways to bend the rules, not follow them.
    Now I am not against such articles and people learning, but i think that everyone would be happier if such articles were covered under some basics category, like if the tile was ‘Basics: using a voltage regulator as a current source’.
    The knowledgeable / “elite” / whoever heard about this could just skip the article and let everyone confused about the title go in and learn about it.

    1. You’ve nailed it Bogdan. I don’t think it is elitism, it is just that we come to HaD to see innovative ideas – people creating cool things by using parts in ways that are a little different to ordinary, or using clever manufacturing techniques etc. Using a VReg in this manner doesn’t really qualify as that. I have no problem with this website have a Basics or a Getting Started section. It would probably be very useful for many readers. But to present something that is basic, common, and in the datasheet as “new and interesting ways” just doesn’t cut it. What next – someone uses a darlington pair to drive a 10W LED from an Arduino and it gets called a “new and interesting way to use transistors”?

      If the HaD creators are reading this, I encourage them to have a Getting Started section on the website that offers basic electronics tutorials. There are many readers who would benefit from something like that. But please don’t publish basic electronics that have been around for nearly as long as the device has been around (45 years), as “new and interesting ways”.

      1. If you think that will get rid of the folks who have fun typing “not a hack” “get rid of this crap” and so on, then please try trolling for a while.

        No, wait, I’m serious here!

        Maybe because of when I got access to the internet (teenager) there was a behavior everyone I knew went through for some period of time. We trolled. Maybe it was playing a character of the opposite gender in a game and offering text “favors” for gear before disappearing, or just telling people they were stupid for not knowing something. Even if we didn’t know something, other people were idiots for not knowing something so basic in their field of interest. Why? The fun isn’t in typing out the “u r stupid, this ez crap needs removed”, the fun is in thinking that every reply is being typed by someone going apoplectic because you’ve angered them. The origin section of has a comic that almost covers that intentional trolling: typing something uninformed or nonsensical, then just sitting back and laughing like stoned teenages. Yes, those trolls know they are imagining their targets getting apoplectic, but it’s still funny.

        I grew out of that phase quickly. Some people never do, but there is always a supply of new trolls to fill the ranks. And if you’ve never done it, go some place you hate try it out while drunk or stoned. Just remember to walk away afterwards.

    2. I figure part of being a hacker is helping train the next generation of hackers. Put basic-level articles in a separate section, it might reduce the amount of complaints. But it might also reduce the number of experienced people who frequent that section.

      I’ve seen it on some large forums. Sometimes the user base can get so segregated that someone can ask for help in a beginner’s section, receive wrong info, and no one who knows better is around to say it. Or sometimes there’s an expert or two who deliberately makes the effort to help out in that section, they can almost always be recognized by how grumpy they are, from shouldering that burden alone.

      Omitting the nonsense in the comments here, I’m pretty impressed by the interaction between folks of various levels. And the information shared ranges far beyond basic-level.

    3. > figure part of being a hacker is helping train the next generation of hackers.
      but there is no obligation to help those who don’t even try. All you would do is create a dependency for the lazy people who don’t even want to try. Been there, done that.

      One of the things a hacker would try to do is to gather as much info on a subject to exploit things, to find how things work. With the internet and search engines, pretty much you have access to most of the vendors’ datasheet, app notes on your finger tips. Wiki most of the time have enough info for a newbie to start.

      Go directly to the source, why the hell someone want to learn from 3rd parties who might or might not even know a subject well enough? Some webcelebs can’t even draw a schematic or do a proper layout correctly or barely would get by as a junior engineer at all and will get fire in less than 6 months.

      1. Yep, self-education is always the best. But if you don’t know about something, you might not know it even exists, or have enough information to Google it. And that’s especially a problem with novices, who have few points of reference.

        I’m not a novice anymore, but in a prior article’s comments, I said that I only recently discovered the diamond buffer. A useful little discrete circuit that really deserves mention in anything describing Class B amps, yet I’d never seen mentioned in any book or online tutorial. Maybe the experts who wrote those books/tutorials didn’t know about it either.

        And in this article’s comments, [Ross Hershberger] posted a link to a depletion-mode MOSFET. I thought those were myths and legends, from days of yore. Seriously, I looked them up years ago when I first encountered a reference, and several seemingly knowledgeable folk said no one manufactured them anymore. So I put them in the mental file for archaic components, right next to manufactured vactrols, and forgot about them. Yet behold, here one is, currently manufactured.

        And so it ends up that I did in fact learn something, when not expecting it, from a tutorial now well beneath my level. A nice little supplement to my self-education. Sometimes nothing beats a *conversation*.

        As for lazy folk who don’t try to self-educate at all, screw ’em. I have a little rule. Whenever I have to request help on a forum, I help at least three other people. Regardless of their skill level, and I take time to write detailed and clear replies. But I never help lazy people, or do someone’s work for them. It’s usually pretty easy to weed them out, as they don’t take the time to write detailed and clear questions. Nor have they attempted to break down a problem, they’ll ask “how do set up a MCU timer?”, rather than “here is my code, why isn’t my timer interrupt working?”. And if I see a “plz” other than in jest, nope.

  8. Remember reading a post somewhere where someone asked for some pointers to modifying the “Blink” app, for the Arduino to blink a LED in an fake car alarm application!!!

    The best source for educating yourself about circuit magic is the simple single function circuits from Elektor or other sources or compilations from around the net. Googling discrete circuits first is almost always the best approach before considering firing up the Arduino IDE. Any further Complexity in your circuit, and microcontrollers are the winners. I’ve built several discrete DC motor controllers, and current limiting is much more robust and instantaneous in an analog circuit.

  9. A note on this; there is a minimum current (TI datasheet lists 3.5mA typ, 10mA max minimum) that this will work tow to, and some minimum system voltage levels too; if this is giving you peculiar performance search for two-transistor current source or transistor zener current source for another simple circuit that gives you more fine control over its parameters (at the expense of the simplicity and parts count that the LM317 constant-current source offers).

    And to the vitriolic above:

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.