Rotation of DC motor

How to write the code to run the DC motor clockwise as well as anti-clockwise direction.

You will need a motor driver IC like L293d for this, since the DC motor requires 9V but Arduino supplies max of 5V.
For driving it forwards and backwards, we only have to reverse the polarity.
You have to make connections as shown, and connect the Input pins to Arduino GPIO pins, 9V battery should be connected to ground and even the ground pin of Arduino should be connected to ground pin of L293d.

Code:
const int IN1=2;
const int IN2=3;

int EN1=8;

void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT); // this is only for 1 DC motor
pinMode(EN1, OUTPUT);
}
void loop() {
digitalWrite(EN1, HIGH); //enabling L293d

digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW); //Moving Clockwise

digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH); //Moving Anti-clockwise (if it moves opposite, exchange HIGH and LOW)
}

hello @sakshikamal.cs18 thank you for your information.

Is it possible to run the DC motor without arduino ?

@Niranjan Yes, but you will need motor driver circuit (eg. L239D) and you will have to give 12 volt battery supply (9V for smaller motors) at least to run the motor because Bolt module(5V) cannot supply enough current to run the motor. Also, you wont need the above mentioned Arduino program given by @sakshikamal.cs18 , you can simply run the motor using led or buzzer program given in the course.
Just connect two GPIO pins to motor terminals in L239D and in the program give HIGH to one of the pins and LOW to another for forward RUN, and vice-versa (LOW to 1st pin and HIGH to 2nd) for backward RUN.
NOTE: LED/Buzzer program uses return path as GND terminal. But in this case, DO NOT use GND terminal for connection as we cannot program the GND terminal. Select two GPIO terminals in the hardware configuration and program accordingly as mentioned in the above paragraph.

hai @akshaykumar.kumar198 thank you for your information

  1. I have L298 is that enough ?
  2. In the above code @sakshikamal.cs18 mentioned void setup() is it required ?

@Niranjan Yes enough and No, void setup NOT required!

Yes your solution is easier, I was working on Arduino at that time so thought of this!
Anyway thanks!