oooh! Lasers
Ok, here is what I did: (yes pictures will follow)
12[ch8364]/18$ Computer-controlled laser turret.
(mini-tutorial)
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
Start:
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:
//Arduino:
//*** 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 *************
//Laser
int LASER; //PURPLE cable
//LED's
int LEDblue; //BLUE cable
int LEDred; //ORANGE cable
//Control
int FIRE;
int fire;
//Safety-Switch
int SafeS;
int safes;
//*** Variables ***************
//LASER
int LASmW;
int LASstate;
int LASlow;
int LAShigh;
//Servos
int X;
int Y;
//--- SKETCHING *#+-*#-+-#-+-#-#
int a,b,c,d,e,f;
int count1,count2;
int LASswitch;
byte posXY[3];
void setup(){
//--- Serial Setup -----------
Serial.begin(9600);
//--- Servo attach ------------
ServoX.attach(9);
ServoY.attach(10);
//--- Initialise gear ---------
//Laser
LASER = 11;
//LED's
LEDblue = 7;
LEDred = 8;
//Control
/*
UP = 2;
DOWN = 5;
LEFT = 6;
RIGHT = 3;
FIRE = 4;
*/
//Safety-Switch
SafeS = 12;
//--- Initialise variables ----
//LASER
LASmW = 0;
LASlow = 20;
LAShigh = 200;
//Servos
X = 90;
Y = 90;
//--- Control -----------------
//--- Safety-Switch -----------
pinMode(SafeS,INPUT);
digitalWrite(SafeS,HIGH);
//--- Laser attach ------------
pinMode(LASER,OUTPUT);
pinMode(LEDblue,OUTPUT);
pinMode(LEDred,OUTPUT);
//--- SKETCHING *#+-*#-+-#-+-#-#
count1 = 0;
}
void loop(){
//--- SKETCHING *#+-*#-+-#-+-#-#
/* serial input */
if(Serial.available() >= 2){
switch (Serial.read()){
case 'x':
posXY[0] = Serial.read();
break;
case 'y':
posXY[1] = Serial.read();
break;
case 'b':
posXY[2] = Serial.read();
break;
}
}
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){
digitalWrite(LEDred,HIGH);
digitalWrite(LEDblue,HIGH);
}
else{
digitalWrite(LEDred,LOW);
digitalWrite(LEDblue,LOW);
}
if(count2 == 2000){
count2 = 0;
}
count2++;
}
//--------------------------------
if(safes == 0){
LASswitch = 1;
digitalWrite(LEDblue, ! LASstate);
digitalWrite(LEDred,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;
}
count1++;
}
}
//-------------------------------------
if(fire != 1){
LASmW = LASlow;
}
//### Servo write ############
constrain(X,0,180);
constrain(Y,0,180);
ServoX.write(X);
ServoY.write(Y);
//### Laser write ############
analogWrite(LASER,(LASmW * LASswitch));
}
//Processing
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(){
size(360,360,P2D);
colorMode(RGB, 360);
background(0);
println("Available serial ports:");
println(Serial.list());
Arduino = new Serial(this, Serial.list()[0],9600);
stroke(255);
line(180,0,180,360);
line(0,180,360,180);
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);
Arduino.write(posX);
Arduino.write(posY);
Arduino.write(button);
if(mousePressed == true){
button[1] = byte(1);
point(mouseX,mouseY);
}
else{
button[1] = byte(0);
}
}
cheers!