Hey,
I’m building a small lift to carry a marble sized ball up and down a timing belt. Everything works ok but I am running into one issue that is causing some problems. I’m using a timing belt attached to a pulley on top and bottom of the lift length. On top is a limit switch that is pressed when the ball reaches the end of its travel. The problem I am having is that when the limit switch is pressed, instead of the motor shutting itself off, it seems to stall for about one second and then turn off. I’ve measured the current and there is a definite peak of about 1.2 amps at the end of the balls travel. The load current of the motor is 600mA so I’m worried about the peak at the end. The motor does stall at the end and hold the belt tight for a second and then lets go. I really want to be able to have the ball press the limit switch and instantly cut power. I’m attaching my code to see if anything shows up there that seems obvious. Thanks
int motOne = 2; // pin 2 feeding L298n driver in one direction
int motTwo = 4; // pin 4 feeding L298n driver in one direction
int limitOne = 3; // pin 3 as input to read limit switch with pull down
int solTrig = 5; // pin 5 feeding base of transistor triggering solenoid
void setup() {
pinMode (motOne, OUTPUT);
pinMode(motTwo, OUTPUT);
pinMode(solTrig, OUTPUT);
pinMode (limitOne, INPUT);
digitalWrite (motOne, LOW);
digitalWrite(motTwo, LOW);
digitalWrite(solTrig, LOW);
}
void loop() {
delay(1000); // wait for one second to begin motion
digitalWrite(motOne, HIGH); // turn motor on moving up
int limitOneValue = digitalRead (limitOne);
if (limitOneValue == HIGH) { // if limit switch is pressed
digitalWrite (motOne, LOW); // turn motor off
delay(1000); // wait for one second
digitalWrite(solTrig, HIGH); // turn on solenoid
delay(500); // hold solenoid for 0.5 seconds
digitalWrite(solTrig, LOW); // turn off solenoid
delay(200); // wait 0.2 seconds
digitalWrite(motTwo, HIGH); // turn motor on in opposite direction
delay(1000); // keep motor moving for 1 second
digitalWrite(motTwo, LOW); // turn motor off
delay(2000); // wait for two seconds
}
}