/* UV Cure System with Rotation, Cooling and Purge
*
* by Lyle Stratton, www.HowToMechatronics.com
*
*/
// Defines Pins Numbers
const int ledPin = 12; // UV LED's
const int stepPin = 7; // Stepper Motor Step
const int dirPin = 5; // Stepper Motor Direction
const int enbPin = 6; // Stepper Motor Enable
const int purge = 23; // Place Holder for Pneumatic Valve for Purge Flow
const int fan = 25; // Place Holder for Fan
#define BUTTON_PIN 2
//RGB Pin Numbers
const int pinR = 28;
const int pinG = 32;
const int pinB = 30;
//some global variables available anywhere in the program
unsigned long startMillis;
unsigned long currentMillis;
// Fixed Variables for starting and stopping functions based on time
// Values are in milliseconds
const unsigned long MotorRampTime = 2000; //Runs Motor Slow Till Time Elapses
const unsigned long MotorRampTime1 = 3000; //Runs Motor Slow Till Time Elapses
const unsigned long MotorRampTime2 = 4000; //Runs Motor Slow Till Time Elapses
const unsigned long LEDTimeOn = 6000; //Turns UV LED Lights ON After Time Interval
const unsigned long TimeOn = 8000; //Time Set to Turn Everything OFF After Time Interval
const unsigned long customDelayRamp = 1500; // Defines variable for Stepper Speed
const unsigned long customDelayRamp1 = 1000; // Defines variable for Stepper Speed
const unsigned long customDelayRamp2 = 700; // Defines variable for Stepper Speed
const unsigned long customDelay = 400; // Defines variable for Stepper Speed
static int turnOn; /*Variable Used to Evaluate State Change of Magnetic Switch, Button
is a Place Holder for the Magnetic Switch */
void setup() {
pinMode(BUTTON_PIN, INPUT); // Defines Button/Magnetic Switch as an Inpute
Serial.begin(115200); // Start Serial in case we need to print debugging info
pinMode(ledPin, OUTPUT); // Defines ledPin Variable as an Output
startMillis = millis(); //initial start time
turnOn = false; /* Prevents Start of Functions if Equipment is Turned on With the
Magnetic Switch/Button on HIGH */
// Sets the pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(purge,OUTPUT);
pinMode(fan,OUTPUT);
//RGB Pins Set to Outputs
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
digitalWrite(pinB, HIGH);
digitalWrite(dirPin,LOW); //Enables the Motor to Move in a Particular Direction
}
void loop() {
// if Function That Only Exicutes if Button/Magnetic Switch is High and "turnOn" State is true
if (digitalRead(BUTTON_PIN)==HIGH & turnOn==true) {
currentMillis = millis(); //Gets the Current "time" (The number of milliseconds since the program started)
if (currentMillis - startMillis >= LEDTimeOn) //Test Whether the Time Period has Elapsed
{
digitalWrite(ledPin, HIGH); // If Time Period Elapsed Turn on the UV LED's
}
// Makes Stepper Pulse with Custom Delay Ramp and Ramp Up Time,
if (currentMillis - startMillis <= MotorRampTime) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelayRamp);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelayRamp);
}
// Makes Stepper Pulse with Custom Delay 1 Ramp and Ramp Up Time,
if (currentMillis - startMillis <= MotorRampTime1) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelayRamp1);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelayRamp1);
}
// Makes Stepper Pulse with Custom Delay 1 Ramp and Ramp Up Time,
if (currentMillis - startMillis <= MotorRampTime2) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelayRamp2);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelayRamp2);
}
// Makes Stepper Pulse with Custom Delay After Custom Delay 1,
if (currentMillis - startMillis >= MotorRampTime2) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelay);
}
//Turns Purge Fan and Red LED ON When Lid is Closed,
digitalWrite(purge, HIGH);
digitalWrite(fan, HIGH);
digitalWrite(pinG, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinR, HIGH);
// Turns everything but the fan off when TimeOn has Elapsed
if (currentMillis-startMillis >= TimeOn) {
turnOn = false;
digitalWrite(ledPin, LOW);
digitalWrite(purge, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinR, LOW);
digitalWrite(pinG, HIGH);
startMillis = currentMillis; //IMPORTANT to save the time of the current LED state.
}
}
// Turns Everything off if the Magnetic Swithc/Button is LOW and Resets Time/Counts and "turnOn" State
if (digitalRead(BUTTON_PIN)==LOW) {
digitalWrite(ledPin, LOW);
digitalWrite(purge, LOW);
digitalWrite(fan, LOW);
digitalWrite(pinR, LOW);
digitalWrite(pinG, LOW);
digitalWrite(pinB, HIGH);
startMillis = currentMillis;
currentMillis = millis();
turnOn = true;
}
}