Go Down

Topic: [Average Difficulty]Mouse-Controlled Laser-Turret (Read 3847 times) previous topic - next topic


oooh! Lasers :-)

Ok, here is what I did: (yes pictures will follow)

12[ch8364]/18$ Computer-controlled laser turret.


Parts needed:

- 2 Servos standart size (each 5[ch8364])
I picked the cheapest I could get, though not very accurate, accurate enaugh for playing around. For accuracy I suggest some very big digital Servos. --> bigger means bigger gear --> means less room between cogs --> greater accuracy.

- empty CD-spindle (for 50 CDs) (free)
Great material to play with, soft enaugh to be cut with a sharp knife.

- cheapest laserpointer you can get (2[ch8364])
The cheaper ones have the advantage of not having a driver chip which can get in the way. Mine just had a resistor soldered to one pin of an encapsulated diode. The Battery was a 4.5V battery so this is ideal to connect to a PWM pin of the arduino. Look for a keyring laserpointer that sits preferably within a plastic dogtagish kind of thing. The ones in metal-tubes are sometimes hard to get out.

You want to have something that looks like this: http://cgi.ebay.com/1-x-650nm-red-5mW-Laser-diode-Module-DOT-3VDC-pointer_W0QQitemZ150351287067QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item2301a2931b

- bamboo tube (well...)
ok the bamboo is just a tube to get the diode in (looks better, and no stray light), I just had some lying around, you could also use the tube from an old pen or whatever.

- cable ties (they make everything better)

-LEDs +resistors (optional)

- cables (caugh)

- Arduino + Processing IDE


Cut a hole into the CD-spindle, the size of your X-Servo. The Servo has a lug where you can put some cable-ties through to fasten it, I used some screws I had lying around but really makes no difference.
Use cable-ties and some tape to fix your Y-Servo on top of the other one.
Put your laserdiode into a tube and attach the tube to your Y-Servo.

Voila finished.

In my construction I added a red LED that is connected to +5V and GND on the Arduino --> Power indicator.
A red and a blue led glued into a white tube (makes exellent purple light) to indicate if the laser is running and whether its firering or not.
A safety plug consisting of stereo-chinch plug.
An optional external power-supply for the servos, controlled with a jumper.

And now the code for Arduino and processing:

Code: [Select]


//*** comments ****************
//BLACK cable --> GND
//RED cable   --> +5V
//PURPLE      --> 11
//BLUE        -->  7
//ORANGE      -->  8
//GREEN       --> 12
//GREEN-BLUE  -->  9
//YELLOW-RED  --> 10
//*** define libraries ********
#include "Servo.h"

//*** define Servos ***********
Servo ServoX;  //BLUE-green cable
Servo ServoY;  //RED-yellow cable

//*** define gear *************
int LASER;  //PURPLE cable

int LEDblue;  //BLUE cable
int LEDred;  //ORANGE cable


int FIRE;

int fire;

int SafeS;
int safes;

//*** Variables ***************
int LASmW;
int LASstate;
int LASlow;
int LAShigh;

int X;
int Y;

//--- SKETCHING *#+-*#-+-#-+-#-#

int a,b,c,d,e,f;
int count1,count2;
int LASswitch;
byte posXY[3];

void setup(){
//--- Serial Setup -----------

//--- Servo attach ------------

//--- Initialise gear ---------
 LASER = 11;

 LEDblue = 7;
 LEDred = 8;

 UP = 2;
 DOWN = 5;
 LEFT = 6;
 RIGHT = 3;
 FIRE = 4;

 SafeS = 12;

//--- Initialise variables ----
 LASmW = 0;
 LASlow = 20;
 LAShigh = 200;

 X = 90;
 Y = 90;

//--- Control -----------------

//--- Safety-Switch -----------

//--- Laser attach ------------
//--- SKETCHING *#+-*#-+-#-+-#-#

count1 = 0;


void loop(){
//--- SKETCHING *#+-*#-+-#-+-#-#

/* serial input */

 if(Serial.available() >= 2){
   switch (Serial.read()){

   case 'x':
     posXY[0] = Serial.read();
   case 'y':
     posXY[1] = Serial.read();
   case 'b':
     posXY[2] = Serial.read();


X = posXY[0];
Y = posXY[1];
fire = posXY[2];


//### Read Safety-Swtich #####
safes = digitalRead(SafeS);

//### Process Safety-Switch ##

if(safes == 1){
 LASswitch = 0;
 if(count2 <= 1000){
 if(count2 == 2000){
   count2 = 0;

if(safes == 0){
 LASswitch = 1;

 digitalWrite(LEDblue, ! LASstate);
 LASstate = LASmW;  

 if(fire == 1){
   if(count1 >= 300){
       LASmW = LAShigh;
       digitalWrite(LEDblue, HIGH);
       digitalWrite(LEDred, HIGH);
   if(count1 < 300){
     LASmW = LASlow;
     digitalWrite(LEDblue, LOW);
     digitalWrite(LEDred, HIGH);
   if(count1 == 400){
     count1 = 0;


if(fire != 1){
 LASmW = LASlow;

//### Servo write ############

//### Laser write ############

 analogWrite(LASER,(LASmW * LASswitch));


Code: [Select]


import processing.serial.*;
Serial Arduino;

byte[] posX = new byte[2];
byte[] posY = new byte[2];
byte[] button = new byte[2];

char X;
char Y;
char B;

void setup(){
 colorMode(RGB, 360);
 println("Available serial ports:");

 Arduino = new Serial(this, Serial.list()[0],9600);


X = 'x';
Y = 'y';
B = 'b';


void draw(){

 posX[0] = byte(X);
 posX[1] = byte((360 - mouseX) / 2);
 posY[0] = byte(Y);
 posY[1] = byte((mouseY) / 2);
 button[0] = byte(B);


 if(mousePressed == true){
   button[1] = byte(1);

   button[1] = byte(0);




intresting :)

would be kool to see this running direct from a mouse (ps2) connected to the arduino or a touch pad, or even analog stick :)

cut out the middle man as it were ;)


thanks :-)

Actually I had this thing wired to a touch pad, and a simple button-control, but decided it would be much cooler to control this via the PC^^


No idea -Waiting for the pictures -I have the parts needed.


Sounds cool.

I understand basically what you did, but I too would love to see the pictures (and hopefully a video of it working?) ;).



Good boy!

You succeeded in not understanding what I wrote combined with mocking about it.


OK so you just exposed yourself .You are the one .
Notice you did not answer either



Good O  so what do you do with it ? Shoot spots on the wall?WoW.

Yes you got the idea correct, since the title of my post says [average difficulty] and I wrote that this is a quick tutorial, guess what? It's meant to be a tutorial! And for what? For people who are new to programming/processing/arduino. In the process of creating this you can learn how to interface arduino with processing and a mouse. Which consequently means you can try to build more complex/better things than before.

I'm wondering how much power it consumes and will it run on a battery for long.
For what? Its hooked up to a computer for the interface, what's the point of running this on battery?

My laser which looks identical to yours
Hmm where did you see my laser? It's not visible in the picture I made.
takes about three amps
Take a look at my initial post where it says: "get a cheap laserpointer" and not "get a handheld doomsday device"

If you don't have any useful questions please save yourself (and me) the time and don't post anything.



A laser taking 3 amps?

What the hell kind of laser did you get? Are you trying to build a laser-saw? 3 amps is nuts... I've played with a few lasers... a pistol mounted laser only puts out from 60ma to 100ma.. and those are fairly strong.

Yeah Ty.. geeze! All this negativity.. :P

Have you thought about making it wireless? Plug it into a wall outlet and control it via RF link and put it in your lawn, lol, and time how long it takes for the police to arrive. :D


time how long it takes for the police to arrive.

You could probably make the Arduino do that too! :D

I was thinking the exact same thing lmao!


Not the lawn but the roof! To get rid of that darn pigeons  ;)

Well long term goal is to make it aim at flies or mosquitos, but its a long way until then, since I don't have any idea how to detect mosquitos. I also have other projects I'm currently working on so there will be no progress on this any time soon.



Nov 30, 2009, 09:36 pm Last Edit: Nov 30, 2009, 09:40 pm by tytower Reason: 1
Such knowledgeable chaps . Full of cynicism but low on brain.
Some don't work with Lasers much.
Another gives a URL and forgets.

If you can't take valid criticism then don't claim achievment, you'r not finished yet . Its a fashion these days to pat yourself on the back before its finished but it still ain't right.

Some of the posts on Exhibition are simply brilliant .  Others mundane,some a pain


If you can't take valid criticism then don't claim achievment, you'r not finished yet . Its a fashion these days to pat yourself on the back before its finished but it still ain't right.

Um...It kind of is done..

The goal was apparently to create a Mouse-Controlled turret with a laser pointer, and the OP has succeeded.  Personally, having no knowledge of Processing, I find it fairly impressive.  It is listed as "Average Difficulty", so you can hardly expect perfection.

You can't honestly tell me that you've never completed a project, and then realized it would be cool to add something else..  That's simply what the OP was implying;  ideas tend to hit you whilst building (or afterward), and those are just improvements upon the original finished product.


Thanks :-) Thats the whole point about this, as an arduino starter you are glad if you can find something of average difficulty, to take your knowledge just a bit further.
The hardest part for me was to figure out how to pass multiple variables to arduino, since the "control-led-brightness-with-mouse"-tutorial explains this only with one variable.


Go Up