Controlling 3V laser with arduino

I want to control laser output power with arduino. It works PWM but I don't want to use it since you can see the blinks when laser moves fast.

Laser needs 40mA and arduino mini pro outputs 40mA, so that seems OK; but Laser needs 3V!

What do I need for adjusting its brightness? DA converter or digital potentiometer? Possibly without additional power supply.

Do you have any hardware specifications on the laser? How fast is your PWM and how fast is the laser moving? Maybe you just need a higher PWM frequency.

Outputting 40mA from an I/O pin is really pushing the limit and you risk damaging the microcontroller. You can maybe use multiple I/O pins in parallel to share the current between them (say 4 I/O pins all driving high --> about 10mA each).

If you follow the I/O pins with two 1N4004 diodes in series that's a quicky and easy way to drop 1.4V (5V --> 3.6V). Given that the I/O pin outputs will be lower than 5V at 10mA you will probably be pretty close to 3V.

Fancier solutions exist, of course :wink:

The only thing I get on laser is 3V and 40mA, 5mW. It does have some regulation circuit inside since it did not burn when I connected it on 5V...but just in case. The mirror laser is pointing at is rotating very fast and I get shopped lines with PWM when I need closed line, so I would need fancier solution (but still cheap).
I have found this SparkFun I2C DAC Breakout - MCP4725 - BOB-12918 - SparkFun Electronics
Does it finish the job? Is there something better?

No, a DAC cannot put out 40mA of current.

But are you SURE that giving the laser, say, 2V instead of 3V will make it dimmer? Something tells me that's not going to work.

What is it that you need the laser to do, and how fast does it need to do it?
Is it a variation of a few % of 40mA, or a full 0 to 40mA?
I am told (but not tested it yet) that it is tricky to modulate low-cost lasers much faster than 5KHz. It can be done, but the electronics gets more complex.

This looks like a good source of info Sam's Laser FAQ which might help.

The laser will need a limit on the current to 40mA. Has the laser module got a current-limiting resistor, or is that part of what you need the electronics to do?

The laser modules I have are relatively relaxed about using higher voltages (an Arduino pin is only 4.2V), but they were more sensitive to current.

Also, I would be nervous about trying to source 40mA from a single pin for long periods. I tend to stay below 20mA max/pin.

Have you access to a copy of the Art of Electronics? That often has very good starting points.

If it is relatively coarse modulation (i.e 8 levels), you could try using a bunch of Arduino pins, each limited to, say, 5mA with a resistor, and just modulate by switching them between on and high-impedance. I wouldn't use digitalWrite, but instead just write into the port.

You might also try asking odicforce.com who sell laser modules and drivers, and are relatively low-cost (for the UK).

I have found the owner very helpful.

HTH
GB

I can't test that but I tried placing 100 Ohm manual potentiometer in between and it dims nicely in range 0-80 Ohm. Unfortunately I can not find Digital potentiometer under 1KOhm so I guess that solution is out

I believe most laser diodes need currentcontrol, not voltage control.
A DAC is primarily about voltage control, so it isn't an ideal way to go.
If you output, say, 1.5V the laser probably doesn't emit light.

The laser will dim with the potentiometer because it's adjusting the voltage, and hence current across the current limiting resistor.

A DAC will give a bit of current control in the same way because the voltage will reduce because it appears across the current limiting resistor.

Try switching on/high-impedance a bunch of current limiting resistors as an experiment, see my previous post - it'll take a few minutes, and use 8 1K-ish resistors.

I think you couldmake a variable current control using a DAC and an Op Amp; have a look in Art of Electronics if you can access a copy.

HTH
GB

It is probably worth adding that you could try make a simple variable current source (the current equivalent of a DAC) using a few different resistor values hanging off the Arduino pins.

As an example, if the laser diode drops 2.5V, say, then
R1 = (4.2V-2.5V)/20mA = 85 ohm = 82 ohm (near value)
R2 = (4.2V-2.5V)/10mA = 170 ohm = 180 ohm (near value)
R3 = (4.2V-2.5V)/5mA = 340 ohm = 330 ohm (near value)
R4 = (4.2V-2.5V)/2.5mA = 680 ohm = 680 ohm (near value)

and you have a 4 bit, 16 level system.
You could use tight tolerance, e.g. 0.1% resistors, but I don't think the laser is anywhere near that precise, so I wouldn't bother.

Health Warning: I have never tried building something like this.
(I have made DAC's using R2R resistor ladders, and they work, but are electrically noisy. This should be better as off is high impedance)

HTH
GB

It was an rather expensive laser module (~50EUR) so I guess it has some drivers and current limiting resistor (it is sealed into case so I can not check it out)

16 levels would be enough...
so then the solution looks like this?
PIN4----R1--
PIN5----R2---
PIN6----R3----
PIN7----R4-----Laser----GND
(with your resistor values)

It was an rather expensive laser module (~50EUR) so I guess it has some drivers and current limiting resistor (it is sealed into case so I can not check it out)

That sounds fancier than mine which were under 10 EUR each.
That may be more complex, though dimming on a potentiometer is very hopeful.

so then the solution looks like this?
PIN4----R1--
PIN5----R2---
PIN6----R3----
PIN7----R4-----Laser----GND

Yes, that's what I'm thinking of.
I'd put a capacitor, about 20-100nF, across the laser to filter out faster noise.

Please note that I haven't tried this, and won't have time for a few days.

Have you got multi-meter, or something you could measure current with, so you could check the values before you try the laser?
A storage 'scope would be perfect, but harder to get access to.

I'd use a pair of diodes and a 12-ish ohm resistor in series as a dummy load to make it practical to measure current.

HTH
GB

Thanks! I will try that after I order some resistors since nearest radioshack is 1000Km away.

thank you also for the book recommendation!

Cheers

A DAC is primarily about voltage control, ...

Leaving aside the fact that, historically speaking, that statement is false, you can make an Arduino controlled current source pretty easily if you just want to test how the laser works at different current levels.

Since using PWM and if necessary, a simple low pass filter, you can produce 0 - 5V on an Arduino PWM pin, all you need add is an NPN bipolar transistor and a 100 ohm resistor to complete the job.

Connect the PWM output to the base of an NPN (for example 2N3904) transistor, connect the emitter of the transistor through a 100 ohm resistor to Gnd, connect the laser ground to the collector of the transistor and the positive input of the laser to the positive terminal of a 9V battery. The negative terminal of the battery will go to ground.

So then to solve for value in analogWrite(pin,value) for a current I in amps,

value = ((I * 100) + 0.7) * 255/5

Example: I = 20 mA = 0.02 A

value = 138

Edit: I only used the 100 ohm resistor because you said you had a 100 ohm pot. If you don't want to use the 9V battery, you can set your pot for 50 ohms or use a 51 ohm resistor. In that case you will be able to attach the laser positive input to 5V. The equation for value will stay the same only substitute 50 for the 100.

EmilyJane taht works but the reason I did not go with PWM is because laser blinks. In your version is also blinks and I need constant output

Did you try adding a low pass filter to your PWM output?

If that doesn't give you the results you want you could use the same technique to create a voltage to current converter from a voltage-out DAC.

Well I did make what you suggested, if that is low pass filter.
However, it does not work if I have that 100ohm resistor, not even 82 ohm
The setup with only transistor still flickers

However, it does not work

Do you mean you get nothing or it still blinks?

Try making the capacitor in the filter bigger.

No, the circuit I suggested is a voltage to current converter. A low pass filter is an RC network you would place between the Arduino PWM output and the base of the transistor.

Can you post the code you are driving the laser with?

2 Grumpy_Mike:
With Resistor on transistor the laser does not light at all, and without resistor it lights but blinks

2 EmilyJane:
Ok, I found now what low pass filter looks like.. how do I determine the capacitor value?
At this moment I just output single analog value of 128 to test if it blinks

So you need a low pass filter, the capacitor is not too important if you don't want to change the brightness very quickly. With your 82R resistor I would use a 47uF capacitor.

What value did you end up with for the emitter resistor for the transistor? That will determine what current flows through the laser with a PWM value of 128. There is probably a minimum current at which the laser will lase. I would start high and work my way down but I can't suggest a value until I know what the emitter resistor is and the voltage you have applied to the laser.

But follow Mike's suggestions about the LP filter first.