Switching a laser on/off from digital pin

Hello all :slight_smile: Arduino/electronics noob here looking for some advice. I'm trying to power a laser pointer off my Arduino board. I can do this fine connecting it directly to 3V3/GND, but i need switching control. First thing i tried was to wire a voltage regulator between pin13 and the positive terminal on the laser, and hook up the lasers gnd to the Arduinos gnd. This did not work. Also tried hooking up pin13 to gnd on the laser and 3v3 to the lasers positive terminal with a diode wired in between to regulate flow to 0v when pin13 is up. Still no go. I'm guessing that the digital pins simply cannot output enough current to drive the laser. Running directly, the laser is drawing 189mA from the board, but when I hook it up as mentioned it can only draw around 40. So, my bet is that I'll need a transistor to switch the laser on and off using a digital pin. But now I'm lost :stuck_out_tongue: MOSFET, PNP, NPN?! Yes, I'm a noob :wink: How can I figure out what type of transistor I need to use? Can anyone point me to a resource on how to figure these things out? Specifically, how are transistors "rated", like what collector/base voltages can they take and what do they output? Can I regulate the output voltage/current with resistors? Do I always have to regulate it with resistors? Oh, so many questions! If anyone can shed just a little bit of light, I will be very thankful!

40mA is the MAX value Atmel say for an AVR IO pin, so you were really stressing the chip trying to get 189 from it. You're lucky you still have a working Arduino.

The on-board 3v3 is not up to that either (I'm surprised that worked, I thought the FTDI chip was only good for about 50mA).

One way to do it is to use a seperate 3v3 regulator (say the MCP1700) from the Arduino 5v and switch the output of that with a FET.

You could also regulate from VIN but this would need a different regulator.


Oh, so many questions!

Yes! I'm not complaining, but I wanted to point you to your own understanding of the fact that you are just getting started....

And as such, you need to be more careful. You may have damaged your Arduino when you tried to use one of the digital pins to drive the laser pointer directly.

The resistance of the laser pointer is, in simple terms, fixed. When you applied 3v3 to it, that resistance was low enough that 190mA "should" have flowed. What actually happened, I suspect, is that the pin never managed to rise to 3v3, and thus your Arduino's output may have been spared... although it may have been "weakened"... i.e. been made unreliable and/ or brought closer to the point where it will later fail.

Moral of story: Resist going too far, too fast! SEarch the web, including this forum and....


.... the Arduino playground for things that would be fun to do. Do them, noting along the way what is allowed, how/ why things work.

Sounds dull... but in no time, you will be able to be a little more adventurous.

You might also benefit from thje following Arduino COURSE....

... and this intro to digital electronics....

And yes, the answer to your question is: Connect an output from the Arduino to a transistor's base, and "switch" the supply (or connection to ground) for the pointer with the transistor.

Can I regulate the output voltage/current with resistors?

A resistor only restricts current NOT voltage.

Do I always have to regulate it with resistors?

Depending on what "it" is then no.

how are transistors "rated",

Lots of parameters but for this application the collector current is the key, all the other stuff you want is well within the reach of every transistor on the planet.
See this:-

Oh and use another pin, your pin 13 is toast, or at best not reliable any more.

Thank you very much for your replies!

Aah, that's what the Vin is for :slight_smile: thought it was actually for CONNECTING power :stuck_out_tongue: well, stupid me, good thing I didn't try that. I think that would work actually, since I'm running the board off a 9v supply anyways to power stepper motors. And I already have a regulator that should be able to do the job.

Whoops, well lucky I didn't break it. I've always been a big fan of try first, ask later, even if that means breaking a few things in the process :wink: Learning by doing (and failing). I guess a lesson learnt here is to be a bit more careful though. Hope nothing is seriously wrecked :wink:

Funny thing was that I measured the current the laser was drawing when connected to the digital pin, and it was barely drawing anything. tkbyd, thanks for clearing that up, I guess that's what happened.

But seriously, shouldn't I be able to pull, say 200mA from the 3V3 or 5V ports if I'm connected to an external power supply? Didn't know that was supplied by the FTDI. I guess there's LOTS I still don't know :wink:

I still don't completely get the transistor "specifications", but from what I have been able to gather from reading the interwebs after posting these questions, my idea was to use a NPN transistor with a saturation voltage around the 5V the pin is outputting, and a maximum collector current of about 300mA (just to be on the safe side, and avoid too much heat). Would those be somewhat correct assumptions? Or is it really smarter to go with a MOSFET? And if so, why? I'm planning on being able to turn the laser on and off rapidly. Does the type of transistor have any effects on that?

So, I've got a few old prints lying around, and if I can manage to find a transistor with a suitable collector current on one of them, I should practically be able to use it? Or would the better noob route be to go down to my local electronics shop and buy one I know would work? I'm guessing the second is probably the smartest. Number one is a bit more fun though :slight_smile:

Again, thank you for your very informative replies!


Oh, wait, a MOSFET and a FET is not the same :stuck_out_tongue: wikipedia here I come :slight_smile:
edit: and turns out a MOSFET is a type of FET. Hooray for learning :stuck_out_tongue:

the laser is drawing 189mA

That's either a pretty powerful or very inefficient laser - are you wearing eye-protection?

I'm connected to an external power supply? Didn't know that was supplied by the FTDI.

AFAIK the only source of 3v3 on the Arduino is the FTDI chip and the regulator in the chip is rated at 50mA. Jusy quickly looking at the schematics I can't see anywhere else the 3v3 can come from, but I might be wrong.

You can however draw your 200mA from 5v.

That was my reason for suggesting another regulator from eithet 5v or VIN.


Wait, that was supposed to be 18.9mA, not 189! But my, that would have been sweet though! It's a 523nm rated at 50mW, the measurement of 18.9mA at 3.3V comes out to 62.4mW, and I guess a bit of that is lost before it's turned into light.

My error corrected, shouldn't i be able to draw about 200mW off the 5V digital pins? (5V*40mA = 200mW). If so, that should be plenty to power the laser, shouldn't it?

and I guess a bit of that is lost before it's turned into light.

That sounds suspiciously too good a conversion rate for a laser.

Lasers are by their nature very inefficient, but a typical 1mW (emitted) laser module will draw around 30-40mA at around 5V (appox 150mW)


That makes a BIG difference, no wonder it worked from the 3v3.


Grumpy_Mike, How much would you assume is lost in the conversion?

Maybe it's my voltage regulator that is at fault. Just measured it now, and it's only outputting 2.28V when connected to GND and pin12 (set to HIGH). Do I need a resistor or something?

Graynomad: haha, yeah, my bad :slight_smile:

(5V*40mA = 200mW).

While this is true you don't get 5V out of an output when drawing 40mA from it.
40mA is not a safe limit anyway, you are better off restricting it to 30mA but if you are only drawing 20mA that is fine.

[edit]Just seen you have spotted that[/edit]

and it's only outputting 2.28V when connected to GND and pin12 (set to HIGH). Do I need a resistor or something?

So you connect pin 12 to ground and set it to high?

Another pin bites the dust.

Funny thing was that I measured the current the laser was drawing when connected to the digital pin

People frequently say things exactly the way you have said it.... but they really shouldn't... it gives beginners no end of incorrect ideas.

The laser doesn't really "draw" current.

The current you get is what you get. What you get depends simply on the voltage the circuit is sustaining.... a BIT like the water pressure behind the spinkler on your garden hose... although that old analogy is fraught with things to confuse the beginner, too.... and on the "resistance" of whatever path(s) is/(are) available for the electricity to flow though. High voltage. low resistance? You WILL get high current.

"Resistance", in the world of digital electronics gets tricky in places, too. For instance, an LED doesn't have a simple resistance, and a transistor is REALLY not "simple" "resistance"... but even so, everything, with qualifications, boils down to resistance. You can say that more elegantly by talking about "effective resistance". The trick is learning where the effects come from, and how they work!

If it was easy, would it be any fun?

But it is most fun when the components you are working with haven't been fried, and until you know more it is sometimes hard to tell....

So you connect pin 12 to ground and set it to high?

Measured between positive on voltage regulator and ground on board, with voltage regulator connected to pin 12 and GND of course, I'm not that stupid :wink:

The laser doesn't really "draw" current.

Correction accepted :slight_smile:

If it was easy, would it be any fun?

Exactly. The last two days of tinkering, reading, failing, reading, asking, tinkering and eventually having a bit of success have been some of the most educative and fun in a while :slight_smile: When I started this project my electronic knowledge was limited to building mobile soundsystems, so moving into this realm has definitely been a new and exciting world for me.

What I'm hoping to build in the end is a XY laser scanner controlled from a programmable MIDI controller (via a computer). It's quite a "daunting" project for someone as green in electronics as I am, but hey, no challenge no fun.

I ended up going with a NPN transistor and two voltage regulators, going from 12V to 5V to 3V, since that was what I had on hand :slight_smile: The high current 3V is then controlled with the NPN transistor from a digital pin on the board. I've currently got one stepper motor (hooked up through an Adafruit Motor Shield) controlling a mirror, which the laser is reflected through.

Here's a few photos: