Answered - Powering laser diode through motorshield?

I'm working on a project that will be powered from a 12V battery with a green laser diode. I'm using an Adafruit Motor Shield with my arduino and I had planned on running my laser diode (this one) through a digital pin.

I had tested my design/code with a tiny laser diode and only just ran into the issue of not having enough current to run the laser.

The digital pin didn't work for the new laser so now I'm looking at powering the laser through the motor shield terminals since they should be able to handle the current and power needed.

I found this article which didn't cover laser diodes but I figured the laser would be similar.

Unfortunately, using the example DC motor code (see below) didn't actually work for me. I had the ground in the arduino ground and in the terminal ground at various points. I also tried having the both sides of the laser in the same terminal block (I've got extra lasers if I broke anything). The laser itself still works fine as I can hook it up to the 5V on the board and it lights up.

/* 
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2 
----> http://www.adafruit.com/products/1438
*/

#include <Wire.h>
#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Adafruit Motorshield v2 - DC Motor test!");

  AFMS.begin(1000);  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  // Set the speed to start, from 0 (off) to 255 (max speed)
  myMotor->setSpeed(255)
  ;
  myMotor->run(FORWARD);
  // turn on motor
  myMotor->run(RELEASE);
}

void loop() {
  uint8_t i;
  
  Serial.print("tick");

  myMotor->run(FORWARD);
  for (i=0; i<255; i++) {
    myMotor->setSpeed(i);  
    delay(10);
  }
  for (i=255; i!=0; i--) {
    myMotor->setSpeed(i);  
    delay(10);
  }
  
  Serial.print("tock");

  myMotor->run(BACKWARD);
  for (i=0; i<255; i++) {
    myMotor->setSpeed(i);  
    delay(10);
  }
  for (i=255; i!=0; i--) {
    myMotor->setSpeed(i);  
    delay(10);
  }

  Serial.print("tech");
  myMotor->run(RELEASE);
  delay(1000);
}

I also tried some simpler codes where I just had the basics of DC Motor code

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"


Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
void setup() {
AFMS.begin();
myMotor->setSpeed(0);

}

void loop() {
myMotor->run(BACKWARD);
}

If this doesn't work out, I'll have to do either a relay or transistor but I'm trying to keep things as simple as possible with the physical components.

So my question is: Should I be able to use the motor shield for that laser? and if so, either what changes should I make to this or should I look into a different baseline maybe a different motor example?

Normally laser diodes require constant current drive, so a switchable constant current circuit is the natural choice. I found this site that shows a simple circuit using two transistors.Simple constant current LED driver | Bryan Duxbury's Blog

Thanks for that idea, I was hoping to use the motor shield since I already had it and I know it has the power/current ability. I don't know anything about transistors and such. I'm looking into it, but it makes everything much more complex.

Cross-post deleted.

That module probably already has a resistor or some active current limiting circuitry in it, since the driving voltage is stated to be 3.6 - 4.2V.

All you need is a transistor switch and a suitable power supply, like the intended 18650 battery. Some possible circuits shown below. I suggest the "low side switch" using an NPN transistor.

This tells you everything you need to know ( and a bit more besides ) about driving a laser.
http://www.repairfaq.org/sam/laserdps.htm

I had planned on running my laser diode (this one) through a digital pin.

That's probably NOT simply a laser diode. The documentation is VERY limited, but I assume there is a an internal resistor or (or other current limiting) inside.

I found this article which didn't cover laser diodes but I figured the laser would be similar.

NO. It's not similar. Neopxels are a special case. They have a built-in driver circuit. Most "things" (including motors) are designed to run from a constant voltage source. A regular power supply (or a motor driver) is constant voltage.... It puts-out a (approximately) constant voltage and the current depends on the load (Ohm's Law).

LEDs are and laser diodes are different from most things. LEDs are driven from a constant-current (or "controlled current" source). Regular little LEDs normally use a series resistor to limit the current. Regular LED strips have a resistor for each LED (or 3 for each RGB LED). Neopixels have current limiting built-into the chip. High-power LEDs use a switchmode constant-current supply where the current is (approximately) constant and the voltage depends on the load (Ohm's Law again).

Laser diodes normally use a special kind of current-control. Laser diodes have 3 pins. The "extra" pin puts-out a voltage proportional to the light output. The current is adjusted moment-to-moment to keep the light output optimum.

But since your laser module has only 2-wires, whatever current limiting it has (probably a resistor) is built into the unit.

A resistor doesn't give you optimum performance, but it may be good enough for your application.

The specs say up to 4.2V. 5V will probably work (allowing for a little voltage loss across the motor driver) but 12V will probably kill it.

jremington:
That module probably already has a resistor or some active current limiting circuitry in it, since the driving voltage is stated to be 3.6 - 4.2V.

Did you notice the "lump" in the middle of the cable?

That lump is indeed interesting. I wonder what is under the shrink tubing, but a PCB with some current limiting circuity would be cool.

Hey all, thanks for the advice! I ended up looking into transistors and getting a mosfet that I will use instead. And if they have a resistor built in like you folks think, that will make it much easier for me.

The whole project is a laser scarecrow, with two servos that run a pan and tilt, the laser as the scarer and a light sensor to turn on when it gets light outside. It's going to be powered by a deep cycle marine battery. I had needed the motor shield for earlier iterations when there were stepper motors involved but now I'm just keeping it so it can regulate the battery. I probably made life a little more difficult by picking this particular laser but I wanted something that was green as the research indicates it is the light that birds see best and was what the original designs by a researcher at URI used.

I felt their designs had some unnecessary parts and really I didn't need to build my own circuit board when the arduino is something that would work as well.

So thank you very much! I appreciate the thoughts and all the answers already on the forum. They help a lot!