jvantyn
Published

Fourier Box

Using a blue laser and phosphorescent paper to illustrate what it means to sketch a sine wave around a circle.

IntermediateFull instructions provided6,054
Fourier Box

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
Development Board, Motor Control Shield
Development Board, Motor Control Shield
×2
Stepper Motor, Mini Step
Stepper Motor, Mini Step
×2
Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Custom parts and enclosures

Base box cad file

Laser cut this from plywood. It is the base for the project.

Rack and Pinion

Laser cut this from acrylic.

Schematics

Arduino Wiring Circut (Dual)

Use it to run both motors off of one arduino and shield

Code

Arduino 1 : Sine Wave

Arduino
double ti;
double inp;
double cosine;
double nn;
double pi = 3.1415926535;
int sinSpeed = 126;  // How fast the arm is moving back and forth


#include <AFMotor.h>

AF_Stepper motor(200, 2); // 200 steps per rotation

void setup() {
  Serial.begin(9600);
  Serial.println("Stepper test!");
}

void loop() {
  Moto1();
}

void Moto1() {

  Serial.println("Moto1 init");  
  
/*
With the rack and pinion gears I printed, it is 400 steps from the center of the circle to the edge. Change entries in "@@" marked lines to half the number of steps.
*/
  int in = -200; //@@
  while (in < 200){ //@@
    double cosine = cos( (in * pi) / 400);
    double nn = abs(cosine);
    motor.setSpeed((nn+0.1)*sinSpeed);
    motor.step(1, FORWARD, DOUBLE);
    in++;
  }
  
  in = -200; //@@
  while (in < 200){ //@@
    double cosine = cos( (in * pi) / 400);
    double nn = abs(cosine);
    motor.setSpeed((nn+0.1)*sinSpeed);
    motor.step(1, BACKWARD, DOUBLE);
    in++;
  }
  
}

Arduino 2 : Base Motor

Arduino
#include <AFMotor.h>
#define pinA A0
#define pinB A2

AF_Stepper motor2(200, 1);

void setup() {
  pinMode(pinA, INPUT);
  pinmode(pinB, INPUT);

}

void loop() {
  aState = digitalRead(pinA); 
  if (aState != aLastState){     
    if (digitalRead(pinB) != aState) { 
      value ++;
    } else {
      value --;
    }
    Serial.print("Position: ");
    Serial.println(value);
  } 
  motor2.setSpeed(value);
  motor2.step(1, FORWARD, DOUBLE);
}

Arduino : Dual run

Arduino
Use this code to run the entire machine off of one shield. This is at the risk of putting too much strain on the motor shield.
//Need to download the AFMotor library.

#include <AFMotor.h>
#define pinA A0
#define pinB A2

AF_Stepper motor2(200, 1);
AF_Stepper motor(200, 2);
long previousMillis = 0;
int lLim = 1; 
int uLim = 75; // Set max speed
double ti;
double inp;
double cosine;
double nn;
double pi = 3.1415926535;
int sinSpeed = 126;  /*  How fast the sin wave is going. This is not on the same scale as the motor speeds. In my case, 126 matched up with 16 to draw a cardioid.  */

int value = 0; 
int aState;
int aLastState;

void setup() {
  Serial.begin(9600);
  Serial.println("program initiated...");
  pinMode(pinA, INPUT);
  pinMode(pinB, INPUT);
  Serial.begin(9600);
  aLastState = digitalRead(pinA);
}

void loop() {
  aState = digitalRead(pinA); 
  if (aState != aLastState){     
    if (digitalRead(pinB) != aState) { 
      value ++;
    } else {
      value --;
    }
    Serial.print("Position: ");
    Serial.println(value);
  }
  aLastState = aState;
  
  int in = -200;
  while (in < 200){
    double cosine = cos( (in * pi) / 400);
    double nn = abs(cosine);
    motor.setSpeed((nn+0.1)*sinSpeed);
    motor.step(1, FORWARD, DOUBLE);
    in++;
  }
  
  in = -200;
  while (in < 200){
    double cosine = cos( (in * pi) / 400);
    double nn = abs(cosine);
    motor.setSpeed((nn+0.1)*sinSpeed);
    motor.step(1, BACKWARD, DOUBLE);
    in++;
  }

  if (value<lLim){
    value = 0;
  }
  if (value>uLim){
    value = uLim;
  }
  if ((millis() - previousMillis) >= value){
    motor2.step(1, FORWARD, DOUBLE);
    previousMillis = millis();
  }
}

Credits

jvantyn
0 projects • 2 followers

Comments