I spent two evenings searching for information on the Keyes KY-008 laser module. The search included two reads through the information in the forum. I recognize some of the names on the list, and started with teir info, then searched the Internet for more info.
The module appears in the Keyes sensor shield group, as Paul_B pointed out. However there is little or no information about connections or usage. I went through eBay listings for the rest of the first evening, trying to find out more, but nothing was useful. I did encounter on sketch which had PWM working, I think, but it was late, or early, depending on your time zone, and I lost track of the sketch.
On day two, I decided to try the marginal information that I had. It was no big deal, I bought two modules for ~$2.00, so I decided to keep working with one until it stopped working. There was one other clue. One of the listings had a module plugged into an Arduino board, no jumpers. I could see that the "-" and "S" pins were plugged into GND and 5V, but could not see the middle pin. So I connected "-" and GND; pin 13 (LED) to "S" and ran the classic Blink example from the library. AHah! The laser and pin 13 LED blinked at exactly the same time. I added in the "middle" pin to the the connections, just in case there was a need for a full 5V source.
I called the new sketch Wink, not Blink, and played with it a bit. Seemed to work fine.
So then I used the AnalogWrite program from Tom Igoe to fade the laser in and out, switching to pin 11 because pin 13 does not support AnalogWrite PWM.
Several listings indicated that the "middle" pin had no function, and it appears they are right. Connecting gnd to "-" and the pwm pin (11), to the "S" pin works just as well, whether the "middle" pin is connected or not.
So, does this help to use the mysterious module?
I'm not happy about so many vendors selling this module with no idea of how it works, but the price is right. Even the Youtube tutorials were not very helpful about using it.
/*
_Wink
This example code is in the public domain.
Originally Mega analogWrite() test
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
This sketch was written for the Arduino Mega, and will not work on previous boards.
The circuit and sketch were written by Tom Igoe for the Arduino Mega, but I changed it
to an Arduino Uno as a single Laser.
created 8 Feb 2009
by Tom Igoe
modified 15 Aug 2015
by Jim Grina
*/
int laserPin = 11;// a pmw pin connected to the S pin
// the 3 pin Laser board has - connected to Arduino ground
// and 5V power to the "middle" pin
// the setup function runs once when you press reset or power the board
void setup()
{
// initialize digital pin 11 as an output.
pinMode(laserPin, OUTPUT);
}
// the loop function runs over and over again forever
void loop()
{
for (int brightness = 0; brightness < 255; brightness++)
{
analogWrite(laserPin, brightness);
delay(2);
}
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(laserPin, brightness);
delay(2);
}
// pause off between cycles of Laser:
delay(200);
}
Moderator edit: [code] ... [/code] tags added. (Nick Gammon)