Laser Spirograph Using Arduino
by John Culbertson in Circuits > Lasers
7365 Views, 19 Favorites, 0 Comments
Laser Spirograph Using Arduino
I was fascinated with Quackmaster Dan's "Four Motor Laser Spirograph" so I decided to build one. The pictures represent about a year and a half of procrastination, and late nights, all in all it probably took me about 80hr. to build as I had to go through a couple revisions of the electrical system, and it was totally worth it.
If you have any questions about components or fabrication, leave them in the comments and I will gladly answer.
Update 2013-10-12:
I am currently working on an updated version of this and plan to have it done by late January 2014 (I will write a full ible for it). In the process of planning that build I found my old arduino code that ran this spirograph, it is very basic, but I might be useful to those working on similar projects:
#include
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
int PotPin1 = 5; // Analog Input from Potentiometers
int PotPin2 = 4;
int PotPin3 = 3;
int PotPin4 = 2;
int Rate1 = 0;
int Rate2 = 0;
int Rate3 = 0;
int Rate4 = 0;
void setup() {
Serial.begin(9600); // set up Serial communication at 9600 bps
Serial.println("Spirograph!");
motor1.run(FORWARD); // Set all fans to run forward. They will not run backwards
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
void loop() {
//Read and Map AI to Rate#
Rate1 = analogRead(PotPin1);
delay(15);
if( Rate1 != 0 ) {
Rate1 = map(Rate1, 1, 1023, 20, 255);
}
Rate2 = analogRead(PotPin2);
delay(15);
if( Rate2 != 0 ) {
Rate2 = map(Rate2, 0, 1023, 20, 255);
}
Rate3 = analogRead(PotPin3);
delay(15);
if( Rate3 != 0 ) {
Rate3 = map(Rate3, 0, 1023, 60, 255);
}
Rate4 = analogRead(PotPin4);
delay(15);
if( Rate4 != 0 ) {
Rate4 = map(Rate4, 0, 1023, 60, 255);
}
output(Rate1, Rate2, Rate3, Rate4);
if( Rate1 == 255 && Rate2 == 255 && Rate3 == 255 && Rate4 == 255){
for(int a=0; a < 255; a+=10){
output(180, 100+a, 250, 0);
delay(500);
}
output(100,0,0
for(int b=0; b < 155; b+=10){
output(180, 0, 0, 100+b);
delay(500);
}
}
}
void output(int m1, int m2, int m3, int m4) {
motor1.setSpeed(m1);
motor2.setSpeed(m2);
motor3.setSpeed(m3);
motor4.setSpeed(m4);
Serial.print("Motor Speeds\t");
Serial.print("\tM#1:");
Serial.print(m1);
Serial.print("\tM#2:");
Serial.print(m2);
Serial.print("\tM#3:");
Serial.print(m3);
Serial.print("\tM#4:");
Serial.println(m4);
}
If you have any questions about components or fabrication, leave them in the comments and I will gladly answer.
Update 2013-10-12:
I am currently working on an updated version of this and plan to have it done by late January 2014 (I will write a full ible for it). In the process of planning that build I found my old arduino code that ran this spirograph, it is very basic, but I might be useful to those working on similar projects:
#include
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
int PotPin1 = 5; // Analog Input from Potentiometers
int PotPin2 = 4;
int PotPin3 = 3;
int PotPin4 = 2;
int Rate1 = 0;
int Rate2 = 0;
int Rate3 = 0;
int Rate4 = 0;
void setup() {
Serial.begin(9600); // set up Serial communication at 9600 bps
Serial.println("Spirograph!");
motor1.run(FORWARD); // Set all fans to run forward. They will not run backwards
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
void loop() {
//Read and Map AI to Rate#
Rate1 = analogRead(PotPin1);
delay(15);
if( Rate1 != 0 ) {
Rate1 = map(Rate1, 1, 1023, 20, 255);
}
Rate2 = analogRead(PotPin2);
delay(15);
if( Rate2 != 0 ) {
Rate2 = map(Rate2, 0, 1023, 20, 255);
}
Rate3 = analogRead(PotPin3);
delay(15);
if( Rate3 != 0 ) {
Rate3 = map(Rate3, 0, 1023, 60, 255);
}
Rate4 = analogRead(PotPin4);
delay(15);
if( Rate4 != 0 ) {
Rate4 = map(Rate4, 0, 1023, 60, 255);
}
output(Rate1, Rate2, Rate3, Rate4);
if( Rate1 == 255 && Rate2 == 255 && Rate3 == 255 && Rate4 == 255){
for(int a=0; a < 255; a+=10){
output(180, 100+a, 250, 0);
delay(500);
}
output(100,0,0
for(int b=0; b < 155; b+=10){
output(180, 0, 0, 100+b);
delay(500);
}
}
}
void output(int m1, int m2, int m3, int m4) {
motor1.setSpeed(m1);
motor2.setSpeed(m2);
motor3.setSpeed(m3);
motor4.setSpeed(m4);
Serial.print("Motor Speeds\t");
Serial.print("\tM#1:");
Serial.print(m1);
Serial.print("\tM#2:");
Serial.print(m2);
Serial.print("\tM#3:");
Serial.print(m3);
Serial.print("\tM#4:");
Serial.println(m4);
}