Hello people!
I have little knowledge of Arduino and Programming.
I'm trying to make a motor to move only when a push button is pressed. Move clockwise until it touches crash sensor (END).
When trigger this crash sensor, it should move in the opposite direction, until it touches the other cras sensor (HOME) and stand still until the button is pressed again.
By the time I managed to get the engine to move and change direction when it touches the end sensor, but as soon as he is released he already back to rotate clockwise.
My equipment ...
01 Arduino Uno
01 TB6600
01 Stepper motor 19kgf cm (8 Leads) - Series connection)
02 Crash Sensor
01 Power Source 24v 5A - 120W.
01 Push buttom
My code ...
//Arduino Sketch based on easy driver
int dirpin = 8;
int steppin = 9;
int enable = 7;
int sensorFinal = 3;
int sensorInicial = 5;
void setup()
{
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
digitalWrite(enable, LOW);
pinMode(sensorFinal, INPUT);
pinMode(sensorInicial, INPUT);
}
void loop()
{
int i;
int sensor = digitalRead(sensorFinal);
if (sensor == HIGH) {
digitalWrite(dirpin, HIGH); // Set the direction.
}else{
digitalWrite(dirpin, LOW); // Set the direction.
}
delay(1);
for (i = 0; i<1; i++) // Iterate for 4000 microsteps.
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(2);
digitalWrite(steppin, HIGH);
delayMicroseconds(200); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
}
Thank you for attention.