0-40ma output from 0-5v?

I am needing some help/confirmation regarding a 0-40ma output from an arduino PWM pin (0-5v). Would the simplest way which will work is to use a resistor which by Ohm's law V/R = I?
So 5v = 0.04A = 125??
Or would someone recommend a separate system to convert it?

It is to be used to control the logic of a variable solenoid in a pneumatic system.

Thanks.

The value of 40mA is the point where damage starts to happen. You are best trying to stick with currents under 35 to 30 mA.
Yes a resistor will limit the current but what are you feeding it into?

You might want to consider something like this, where the Arduino i/o pin switches a transistor.

Grumpy_Mike:
The value of 40mA is the point where damage starts to happen. You are best trying to stick with currents under 35 to 30 mA.
Yes a resistor will limit the current but what are you feeding it into?

I need to achieve the max 40ma as it will control the logic of a variable solenoid valve which will change the air flow. It is a burkert solenoid valve which is connected to a display/controller.

Use an NPN transistor to switch the solenoid, with the transistor base connected to the arduino pin.

Your solenoid should be connected between your + voltage and the transistor collector. Transistor emitter to Ground as Common Emitter. Something like a 1k resistor between the Arduino pin and transistor base should suffice for most transistor Hfe @ 40mA CE. Check the data sheet for whatever transistor you use, but something like a 2N2222 would be more than adequate. Even a 2N3904 will switch 40mA without issues.

Don't forget a fly back diode in reverse bias across the solenoid coil to protect against back EMF damage.

tack:
Use an NPN transistor to switch the solenoid, with the transistor base connected to the arduino pin.

Your solenoid should be connected between your + voltage and the transistor collector. Transistor emitter to Ground as Common Emitter. Something like a 1k resistor between the Arduino pin and transistor base should suffice for most transistor Hfe @ 40mA CE. Check the data sheet for whatever transistor you use, but something like a 2N2222 would be more than adequate. Even a 2N3904 will switch 40mA without issues.

Don't forget a fly back diode in reverse bias across the solenoid coil to protect against back EMF damage.

I need to have the output variable (0-40ma) proportional to 0-5v. The transistor will just put it on the max output which will not help me.

I'd use the arrangement in the attached schematic. The RC network smooths out the PWM and steps it down to 0 to 0.88V, then the op amp and transistor convert that into 0 to 40mA.

I need to have the output variable (0-40ma) proportional to 0-5v. The transistor will just put it on the max output which will not help me.

That is al, that PWM is, it is not a proportional output it is a 0 to 5V output with a variable time for each of the extremes.
You need to know the impedance of what you are driving into before you can think about trying to design filters.
If you truly need a variable current driven into an impedance over 120R then you need extra voltage over and above 5V. This is known as an adjustable constant current drive and is a more complex circuit than just a transistor an a few Rs and Cs.
Post a link to the data sheet of what you are driving.

The other consideration and possible problem is what is the Voltage and Current involved.

What is the resistance of the solenoid valve? You probably need a higher (than 5V) power supply.

Also, check more with the manufacturer's data sheet. I understand that this type of variable valve can often be driven from PWM and does not need a "linear" DC applied to it. Point to the datasheet and we may have more info to help from.

What is the application for this? How fast do you need to change the value?