I am currently making a new piece of equipment for my work. I'm making a gluing machine that uses a geared stepper motor to drive a lead screw. I have 4 potentiometers used to allow user interface to fine tune different variables (like the speed of the motor while gluing, adding additional steps in not enough glue is coming out, etc.). I then have the arduino displaying the potentiometer values on the lcd. These are all working, but if there is any advice on the coding for them I'd gladly listen.
The functions I want in the end product is to have a gluing button that moves down then backs up to relieve pressure off the tube of glue, a pulse button that allows the user to pulse small amounts of glue in needed areas, and an up and down button for obvious reasons. These I all have working for the most part. There are a few other functions that I want to implement and this is where I ran into a few problems. Again any additional advice is appreciated!
-
Limit Switches:
I want to put a limit switch at the top and bottom of the lead screw so that when the bottom limit switch is trigger the motor switches directions and moves up till it hits the top limit switch. I've seen a recent post but I don't quite understand how it pertains to my problem. I'm trying to achieve high tolerance for the amount of glue coming out, as it will be used for gluing parts for retail. As for my code now I only have the empty switch coded and I know its not right because it is an "if" function that the arduino checks once per loop. I'm using a 27:1 geared stepper motor so I'm trying to avoid crashing into the end because it will just destroy the 3d printed parts. so the limit switch must interrupt the code if it is pressed in the middle of the gluing process. -
Increasing RPM:
with the 27:1 geared stepper 250 RPMS is rather slow moving with the lead screw, I know the stepper motor and driver is capable of higher rpms but I run into the problem of lack of knowledge of ramping up the rpms. I know you cant start a stepper at a high rpm because it will just vibrate, so I'm looking for a way to ramp up the rpms slowly when pressing the up or down button. -
There needs to be a "time out'" function, so if the glue/pulse/down button hasn't been pressed in say 1 min, a red led comes on and "locks" the code from gluing again, until a Purge button has been pressed to purge the semi hard glue out of the tube, then the red light turns off and the code goes back to the normal process.
I've seen a couple other posts that have talked about using unsigned long variables, updating the current time every loop cycle, using millis(), and updating the last button press time every time the button is pressed then at the bottom of the code it checks the (current - last button pressed) to see if its exceeded the "time out" limit. But there seems to be a problem with people disagreeing with how to go about this process. I know the millis() will roll over and go back to 0 when it reaches its limit, but this machine will be turned on and off frequently and only be used for a few hours at a time. I'm not sure if this is still relevant but i would like some help and input.
Things I'm using:
-Arduino Mega
-Kuman L298N motor Driver
Kuman L298N motor driver
-Nema 17 bipolar stepper motor 27:1 planetary gear
Nema 17 bipolar stepper motor 27:1 planetary gear
Limit switches are N.O.
Thank you,
Thomas
Code found bellow:
//Testing Buttons with LCD and New Motors
#include <Stepper.h>
#include <LiquidCrystal.h>
//setting up led
int greenLed = 52;
int redLed = 50;
// Setting up int for the control buttons
int glueButton = 53;
int pulseButton = 51;
int upButton = 49;
int downButton = 47;
int emptyLimitSwitch = 22;
// Setting up int for glueing motor
int in1Pin = 6;
int in2Pin = 5;
int in3Pin = 4;
int in4Pin = 3;
const int stepsPerRev = 200;
Stepper glueStepper (stepsPerRev, in1Pin, in2Pin, in3Pin, in4Pin);
// Setting up Constants for LCD
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
//Activating LCD letting the arduino know the LCD is 16 characters x 2 Rows
lcd.begin(16, 2);
//Activating stepper and setting pin mode
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
pinMode(glueButton, INPUT_PULLUP);
pinMode(pulseButton, INPUT_PULLUP);
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(emptyLimitSwitch, INPUT_PULLUP);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
digitalWrite(greenLed, HIGH); //turning on green led
}
void loop() {
//reading pot values and assinging value to a name, mapping the pots to chosen range
int pulseValue = analogRead(A0);
int pulseStep = map(pulseValue, 0, 1023, 0, 500);
int glueStepValue = analogRead(A1);
int glueStep = map(glueStepValue, 0, 1023, 0, 1000);
int glueRpmValue = analogRead(A2);
int glueRpm = map(glueRpmValue, 0, 1023, 0, 201);
int rpmValue = analogRead(A3);
int rpm = map(rpmValue, 0, 1023, 0, 5);
//printing the pot values to the lcd screen and moving cursor and printing blanks to refresh the screen
lcd.print("P=");
lcd.setCursor(2, 0),
lcd.print(" ");
lcd.setCursor(2, 0);
lcd.print(pulseStep);
lcd.setCursor(6, 0);
lcd.print("Gstp=");
lcd.setCursor(11, 0),
lcd.print(" ");
lcd.setCursor(11, 0),
lcd.print(glueStep);
lcd.setCursor(0, 1);
lcd.print("Grpm=");
lcd.setCursor(5, 1),
lcd.print(" ");
lcd.setCursor(5, 1),
lcd.print(glueRpm);
lcd.setCursor(8, 1);
lcd.print("RPM=");
lcd.setCursor(12, 1),
lcd.print(" ");
lcd.setCursor(12, 1),
lcd.print(rpm);
lcd.setCursor(0, 0);
//reading button values
int glueButtonValue = digitalRead(glueButton);
int pulseButtonValue = digitalRead(pulseButton);
int upButtonValue = digitalRead(upButton);
int downButtonValue = digitalRead(downButton);
int emptyLimitSwitchValue = digitalRead(emptyLimitSwitch);
//button code
if (glueButtonValue == LOW)
{
glueStepper.setSpeed(glueRpm);
glueStepper.step(-1500 - glueStep);
glueStepper.step(800);
delay(250);
}
if (pulseButtonValue == LOW)
{
glueStepper.setSpeed(glueRpm);
glueStepper.step (-pulseStep);
}
if (upButtonValue == LOW)
{
glueStepper.setSpeed(275);
glueStepper.step(500);
}
if (downButtonValue == LOW)
{
glueStepper.setSpeed(275);
glueStepper.step(-500);
}
if (emptyLimitSwitchValue == LOW)
{
glueStepper.setSpeed(250);
glueStepper.step(1000);
}
}