So I did a DIY linear actuator, it consists of a NEMA 17 motor which drives a ball screw and has two steel rods acting as reinforcements alongside some custom 3D printed parts. Mechanically I think it works great, but electronically it's another story. To drive the whole thing I am using an arduino pro mini (3.3V) powered from a 12VDC power supply and LM317 regulator. The stepper motor is driven via a pololu a4988 motor driver and two push buttons to send the carrier to the top or bottom. In order to stop the motor when it reaches a certain limit, the linear actuator has two limit switches and two LEDs indicating which position it is at (top or bottom). Hopefully the diagrams and pictures will make it easier to understand how the system works.
The problem is that the top and bottom limit switches are doing false triggers. Inside the shop where I built it, the false triggers are not very frequent but are noticeable. However in the place where it's supposed to be installed has more EM noise and it's nearly impossible to use the thing because there are lots of false trigger. What happens is I press one of the push buttons and the routine starts but I see random flashes from the LED's which eventually stops the routine. This is because the program only stops the routine if the limit switch at the position it's going to is activated. For example it stops if it's going to the top and the top limit switch is activated, so I might see the bottom LED flashing and the carrier is still moving but when the top LED flashes the linear actuator stops.
All digital inputs are configured as INPUT_PULLUP and the wire that goes to the limit switches is 22 awg stranded and has no shield. I have some CAT5E FTP cable I could use, but I am not sure if that would fix the problem.
The schematic is actually for a pcb board I'd like to make, the current implementation is the same except it's on a breadboard so no JST or Screw terminal connectors are used and things are just connected directly
Code:
// Define pin connections
#define dirPin 2
#define stepPin 3
#define upButton 4
#define bottomButton 5
#define upLimitSwitch 6
#define bottomLimitSwitch 7
#define IsAtTopLED 8
#define IsAtBottomLED 9
#define ESPsignal 10
#define enable 11
boolean upPressed = false;
boolean bottomPressed = false;
boolean IsAtTop = false;
boolean IsAtBottom = false;
void setup() {
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(IsAtTopLED, OUTPUT);
pinMode(IsAtBottomLED, OUTPUT);
pinMode(upButton, INPUT_PULLUP); // send carrier to top
pinMode(bottomButton, INPUT_PULLUP); // sends carrier to bottom
pinMode(upLimitSwitch, INPUT_PULLUP); // goes to limit switch at top
pinMode(bottomLimitSwitch,INPUT_PULLUP); // goes to limit switch at the bottom
pinMode(ESPsignal, INPUT_PULLUP); // ESP trigger signal to close chimney
}
void loop() {
digitalWrite(enable,HIGH); // stepper is OFF, only ON if it has to move
readButtons();
actOnButtons();
readESPsignal();
}
void readButtons() {
bottomPressed = false;
upPressed = false;
if (digitalRead(upButton) == LOW) {
upPressed = true;
}
if (digitalRead(bottomButton) == LOW) {
bottomPressed = true;
}
}
void actOnButtons() {
readStates();
if (upPressed == true) {
digitalWrite(enable,LOW);
digitalWrite(dirPin, LOW);
GoTOP();
}
if (bottomPressed == true) {
digitalWrite(enable,LOW);
digitalWrite(dirPin, HIGH);
GoBOTTOM();
}
}
void GoBOTTOM() {
while(IsAtBottom == false) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin, LOW);
delayMicroseconds(700);
readStates();
// Break if up/bottom buttons are pressed
readButtons();
if(upPressed == true || bottomPressed == true) {break;}
}
}
void GoTOP(){
while(IsAtTop == false) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin, LOW);
delayMicroseconds(700);
readStates();
// Break if up/bottom buttons are pressed
readButtons();
if(upPressed == true || bottomPressed == true) {break;}
}
}
void readStates() {
if (digitalRead(upLimitSwitch) == LOW) {
IsAtTop = true;
digitalWrite(IsAtTopLED, HIGH);
digitalWrite(IsAtBottomLED, LOW);
}
else if (digitalRead(bottomLimitSwitch) == LOW) {
IsAtBottom = true;
digitalWrite(IsAtBottomLED, HIGH);
digitalWrite(IsAtTopLED, LOW);
}
else{
IsAtTop = false;
IsAtBottom = false;
digitalWrite(IsAtTopLED, LOW);
digitalWrite(IsAtBottomLED, LOW);
}
}
void readESPsignal() {
}








