Hi all,
for a project I want to control an electric motor with my arduino mega. For this I use a VMA03 from velleman.
The motor should turn both left and right and the end stops are indicated by 2 pushbuttons. The engine is started by a touch sensor (TTP223B). I can do the running with my code but I have to operate the touch for 4 seconds before giving this signal. The full motor movement from the left ==> right and vice versa also takes ± 4 seconds.
Can I change my code so that I only have to operate the touch for a second and then start the engine?
Another problem is that the engine has no brake. The engine therefore pushes the push button for some time before it is stationary. Can I programmatically stop the engine?
code:
#define ctsPin 7 // Pin for capactive touch sensor
#define eindstop1 8
#define eindstop2 9
int pwm_a = 3; //PWM control for motor outputs 1 and 2
int dir_a = 2; //direction control for motor outputs 1 and 2
void setup() {
pinMode(ctsPin, INPUT);
pinMode(pwm_a, OUTPUT); //Set control pins to be outputs
pinMode(dir_a, OUTPUT);
pinMode(eindstop1, INPUT);
pinMode(eindstop2, INPUT);
}
void loop() {
int ctsValue = digitalRead(ctsPin);
int toetsWaarde1 = digitalRead(eindstop1);
int toetsWaarde2 = digitalRead(eindstop2);
if (toetsWaarde1 == LOW && toetsWaarde2 == LOW) {
digitalWrite (dir_a, HIGH);
analogWrite(pwm_a, 150);
} else {
analogWrite(pwm_a, 0);
delay(4000);
}
if (toetsWaarde1 == LOW && toetsWaarde2 == HIGH && ctsValue == HIGH) {
digitalWrite (dir_a, LOW);
analogWrite(pwm_a, 100);
delay(4000);
}
if (toetsWaarde1 == HIGH && toetsWaarde2 == LOW && ctsValue == HIGH) {
digitalWrite (dir_a, HIGH);
analogWrite(pwm_a, 100);
delay(4000);
}
}
Moderator: Code tags added