Hello, I am new to all this but am learning and really enjoying it.
I have been working on a project to turn a machine with a motor for a time period then stop and wait for a tiime period then repeat.
This is not working out so I want to change the plan and make it work on a button/motion sensor and limit switches.
This is the code I have and I had alot of help from others on this.
Ideally you would push a button, the motor would run for a time period or hit limit swich then reverse for a time period and stop until button pushed again.
This is the code I have.
// run forwards for 10sec // stop for 2sec // reverse for 10sec, // stop for 3min // repeat the loop endlessly. int r_en = 2; int l_en = 3; int r_pwm = 5; int l_pwm = 6; void setup() { pinMode(r_en, OUTPUT); pinMode(l_en, OUTPUT); pinMode(r_pwm, OUTPUT); pinMode(l_pwm, OUTPUT); } void loop() { forward(); delay(10000); stop(); delay(2000); reverse(); delay (10000); stop(); delay (3 * 60 * 1000); } void stop() { analogWrite(r_pwm, 0); analogWrite(l_pwm, 0); digitalWrite(r_en, LOW); // disable r motor digitalWrite(l_en, LOW); // disable l motor } void forward() { analogWrite(r_pwm, 150); analogWrite(l_pwm, 0); digitalWrite(r_en, HIGH); // enable motor r digitalWrite(l_en, HIGH); // enable motor l } void reverse() { analogWrite(r_pwm, 0); analogWrite(l_pwm, 150); digitalWrite(r_en, HIGH); // enable motor r digitalWrite(l_en, HIGH); // enable motor l }