L293D Motor Shield

Hi below is my code to run a motor via L293D, i need to run motor for 5 second only, please help me

#include <AFMotor.h>

AF_DCMotor motor(3);

void setup () {
}

void loop() {
motor.setSpeed(50);
motor.run(FORWARD);

}

See this post and the "Blink without delay" example that comes with Arduino, to learn how to use millis() for timing.

Sir i am very new to Arduino.. can you please modify above code for me please.

No.

ok I am trying again, will come back to you soon.

Sir have a look code is fine but not working

#include <AFMotor.h>

AF_DCMotor motor(3);

const long interval = 5000;
unsigned long previousMillis = 0;

void setup () {
}

void loop() {
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {

previousMillis = currentMillis;

motor.setSpeed(50);
motor.run(FORWARD);

}
}

Of course the program is "working", but it may not be doing what you want.

Please read the "How to use this forum" post, for instructions on how to post code, your wiring diagram and how to explain your problems.

Have you studied the Adafruit tutorial on how to use their software?

I developed code by myself , thanks for giving me hint :slight_smile:

#include <AFMotor.h>

AF_DCMotor motor(3);

void setup () {
motor.setSpeed(50); // set the speed to 200/255

}

void loop() {

Serial.print("tick");
motor.run(FORWARD); // turn it on going forward
delay(5000);

Serial.print("tack");
motor.run(RELEASE); // stopped
delay(100000);

}