Arduino Constant Current source

I have to make a programmable constant current source with my arduino for a project. I plan to use the PWM output of the Arduino and filter it into a dc signal which varies from 0 to 5 volts. I need the current to stay at the programmed level no matter what the load is. So I need some way to have the arduino monitor the current and adjust the voltage depending on the load in order to keep the current constant. Any help would be greatly appreciated.

Constant current circuits can be tricky. If you do it wrong then you have melted wires and fire.
As a prerequisite you need a power supply with its own current limiting circuit. Ideally this will be a bench power supply with a display showing the current, but can also be as basic as a LM317T voltage regulator configured as a constant current source, or a poly-fuse.

This is placed upstream from the circuitry that you build and is purely there as a safeguard should your Arduino system fail to limit the current as expected.

The next thing you need is a low value 'shunt' resistor that will generate about 100mV at the maximum current you intend to pass. Connect one side of the resistor to ground and the other end to an analogue input, and the source pin of a logic level N channel mosfet bolted to a large heatsink.

Connect the drain pin of the mosfet to one side of your load and the other side to your power supply. Connect your Arduino generated dc signal to the mosfet gate.
In your main loop gradually increase/decrease the voltage to the mosfet gate in small steps until you see a voltage across the shunt resistor that corresponds to the desired current.

As they say, the devil is in the detail. Your Arduino filtered PWM voltage is going to be slow to respond to changes therefore you need to take this into account when designing your control loop. Given this limitation you also need to have realistic expectations of how 'constant' the current will be under changing load conditions.
You also need to do power dissipation calculations for the shunt resistor and the mosfet. You'll get extra points for putting a temperature sensor on the heatsink so you can shutdown the circuit if it gets too hot. You'll lose points if the audience can smell burning. Any smoke is definitely a fail.

Thanks for the advice. Do you have a link to a circuit diagram or anything along the lines of your suggestions?

What compliance voltage do you need?

Try Google "current mirror". I think sourcing current over known resistor with PWM and mirroring it to unknown load may work much more reliable than trying to measure current over shunt resistor and trying to set PWM to get the right current.
There are also other possibilities such as using voltage regulators as current sources.

To design this you need to know :

  • the maximum voltage across your load

  • the power supply voltage

  • the maximum current you wish to control

  • whether the load is earthed at one end, or connected to the +ve supply.

  • the accuracy to which you wish to set the current.

If you can supply this information I may be able to help.

Allan.

There exist simple circuits which provide a constant current - no need to adjust anything unless the desired current changes.

As Allan suggested, more information about your circuit is required for more detailed help.

My input voltage is a dc voltage from 0-5v. I tried using a Howland current pump today but since I can't get resistors which are perfectly matched, the performance is very poor. I'm just trying to make a circuit which can give a constant current to a varying load of around 0-1k and have the current stay constant. My circuit design knowledge is very basic so if anyone could provide a circuit diagram or point me in the right direction for this it would be very much appreciated.

This is a simple current source circuit.

Will that provide a steady unvarying current irrespective of a changing load? Ideally I would be able to monitor the current on the arduino and adjust it when the load changes in order to keep the current constant but if I could get a circuit which provides a steady load current of anything between maybe 0-20/30mA that would also be helpful.

30 mA into 1k implies a 30v supply. But if you want to deliver this into a low resistance should be OK.

A simple Wilson current mirror should do the trick - see enclosed. It will only go up to within about 1v of the supply.

Accurate to perhaps 2 or 3% if Q2 and Q3 are matched - ie from the same batch.

And that presumes the 5v from the arduino is accurate - could easily be 10% out.

If you want more accuracy things get nore complicated.

Allan

isrc1.pdf (17.4 KB)

To maintain a constant current, I programmed my code to vary voltage in accordance with a current reading. The voltage would be adjusted via filtered PWM. The current would be read by a current reading breakout board, connected to an analog pin, which is nothing more than a calibrated hall-effect sensor. You can find those on Ebay rated for pretty high current values. After that you just need a power supply feeding an amplifier or MOSFET or something like that and you're pretty much done. It's all in the software how you limit the current.