Full Dip Station Set Up
3.0 Videos
Dip Station Demonstration
LCD Screen to Board
Circuit Diagram II
10K Pot 1 output [Time] --> A1
10K Pot 2 output [Distance] --> A2
"Start" Button to Board
"Reset" Button to Board
#include //needed to drive motor
#include //acceleration library is smoothest
#include //needed for circuits
#include //needed w LCD 12C Library
LiquidCrystal_I2C LCD(0x27, 16, 2); //usual address of LCD Screen with pixels (width, height)IW
AF_Stepper motor1(200,2); //200 steps/rev w motor; Motor connected to port 2 (M3/M4)
void forwardstep() { //wrapping the AFmotor lib for use with accel stepper for forward motion
motor1.onestep(FORWARD, SINGLE);
}
void backwardstep() { //wrapping the AFmotor lib for use with accel stepper for backward motion
motor1.onestep(BACKWARD, SINGLE);
}
AccelStepper motor(forwardstep,backwardstep); //initializing motor as object in accel stepper
int Pot1; //potentiometer 1 (Time: A2 (min))
int Pot2; //potentiometer 2 (Distance: A3 (mm))
int button = A0; //button on analog pin A0
int Time; //Time variable
int RemTime; // Remaining Time
float Dist; // Distance variable (mm)
float mmperRev = 20; //mm in 1 rev of dowel (2*pi*r) r =3.175 (dowel diameter/2)
int numRevs;
void setup()
{
LCD.backlight(); //turn on LCD backlight
Serial.begin(9600); // IW begin serial communication (9600 for LCD)
pinMode(button,INPUT); // IW initialize button as input
LCD.begin();//Initializing display iw
delay(500); // IW delay 500ms
LCD.clear();// IW clear screen
motor.disableOutputs();//disable motor function
delay(500); // delay
}
void loop() // run over and over
{
while (!digitalRead(button)) { //while button NOT pressed (because it is "normally open" button)
motor.disableOutputs();
Pot1 = 1023-analogRead(A1); //// IW finding time from pot 1
int val = 180*(float(Pot1)/1023);// IW finding time
Time = (val-(val%5)+5); // IW finding time
Pot2 = 1023-analogRead(A2);// IW finding dist (A1 on right dip controller/A3 on left dip controller)
Dist = Pot2*0.01*16.49;
// the distance values (mm) displayed on the LCD screen. If you want the dip station to go farther, increase the multipliers here. Current range: up to 160cm.
LCD.clear(); //clear screen
LCD.setCursor(0,0); //1st row 1st column
LCD.print("Time: ");
LCD.print(Time); //print time
LCD.print(" minutes");
LCD.setCursor(0,1); //1st column second row
LCD.print("Dist: "); //print distance
//if (Dist<10.5) {
//LCD.print(0);
//}
LCD.print(Dist,1);
LCD.print(" mm");
delay(100);
}
LCD.clear();
delay(500);
while (digitalRead(button)); //after button has been pressed (5V goes to A0).
LCD.setCursor(0,0);
LCD.print("Remaining Time:"); //print time
long T = millis();
float numRevs = Dist/mmperRev; //total number of revs (total distance/mm per rev)
int numSteps = ceil(numRevs*200); //total number of steps (total revs *200 bc 200 steps/rev)
float seconds = Time*60; //minutes to seconds (total time)
float velocity = numSteps/seconds; //find velocity (steps per second).
motor.setSpeed(velocity); //set speed of motor to this constant velocity value.
motor.enableOutputs();
do { //do while loop. loop exits when remaining time reaches 0.
RemTime = Time-((millis()-T)/60000); //calculate remaining time.
LCD.setCursor(0,1);
LCD.print(RemTime);
LCD.print(" min "); //print remaining time
//motor.setSpeed(steps/second);
motor.runSpeed(); //run the motor at the set velocity at the end of each iteration of loop.
} while (RemTime > 0); //do loop while remaining time is greater than 0.
LCD.clear();
while (RemTime = 0) {
motor.disableOutputs();// after loop disable motor to save power
delay(500);
LCD.setCursor(0,0);
LCD.print("Complete!");
LCD.clear();
LCD.setCursor(0,1);
LCD.print("Please Reset");
delay(5000);
//wait for user to hit reset button
}
}