How to make DC motor go forward for 30 seconds, stop and go reverse for 30 sec?

I need to write a program that goes for 30 seconds stops for 5 seconds and goes in reverse for 30 seconds.

What hardware have you got?- to reverse the direction of a motor you need an h-bridge, and the code will depend on that hardware.

Can't you get the teaching staff there to help you?

For the timing have a look at how millis() is used in Several things at a time.


Adafruit Arduino - Lesson 15. Bi-directional Motor

int enablePin = 11;
int in1Pin = 10;
int in2Pin = 9;
int switchPin = 7;
int potPin = 0;

void setup()
  pinMode(in1Pin, OUTPUT);
  pinMode(in2Pin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  pinMode(switchPin, INPUT_PULLUP);

void loop()
  int speed = analogRead(potPin) / 4;
  boolean reverse = digitalRead(switchPin);
  setMotor(speed, reverse);

void setMotor(int speed, boolean reverse)
  analogWrite(enablePin, speed);
  digitalWrite(in1Pin, ! reverse);
  digitalWrite(in2Pin, reverse);