Motor controlling with Arduino

Hello guys, Welcome back to my channel. Today we are going to talk about motor control. Motor control is a very important topic in learning Arduino. In this article, we will talk about rotating the motor left or right and controlling the speed. This topic is especially important for making robot cars. These motor control functions cannot be performed directly through the Arduino board. We can use a special method for that. That is, using an H-bridge circuit.
What is the H-bridge circuit?
    A circuit consisting of four transistors is called an H-bridge circuit. If we want to turn the motor left or right, the potential given to the motor must be given by switching from anode to cathode. For this purpose, we can use the H-bridge circuit. Today we do not need to make this circuit. The IC  made with these H-bridge circuits are available for purchase. We can buy these. There are two major ICs in the market. They are L298N and L293D. Today we will be using L298N IC for this project. This IC includes two H-bridge circuits. So we can control two motors. A motor control board with this IC is available for purchase in the market. We can use that motor control board for this project.
    This board can be controlled by two motors. So it is controlled 2A current. We can supply 5-36v supply voltage to this motor control board. If you supply more than 12v, the jumper must be removed.
    The board is fitted with a heat sink with L298N IC to withstand a large current. The board includes four terminals for connecting the two motors and three terminals for powering. This board includes six pins for giving inputs through the Arduino board. One motor has three pins and the other three pins use another motor. The pins of one motor are ENA, IN1, and IN2. This ENA pin is used to control motor speed. Uses IN1 and IN2 pins to control motor direction. The same goes for another motor.
Okay, let’s see how to use a single gear motor with this motor control board in practically. The required components are given below.

Components

Ok, let’s do this project step by step.

Step 1

Let’s identify these components.
Arduino Uno board
You can use any other Arduino board.
Motor controller board
This component is described above.
Gear motor
This component is more important for making robot cars.
Jumper wires

Three FEMALE to MALE jumper wires and two MALE to MALE jumper wires are used for this project.

Step 2

Connect these components using the circuit below.
    Connect the Arduino pin D3 pin with the ENA pin. Connect pins D4 and D5 with pins IN1 and IN2. The Arduino board is used to power the motor control board. If the motor does not rotate due to the power provided by the Arduino board, apply external power

Step 3

Look at the code below.
The complete program of this project – Download
void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}
void loop() {
  analogWrite(3, 254);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  delay(2000);
  digitalWrite(5, HIGH);
  digitalWrite(4, LOW);
  delay(2000);
}
This code sets pins 3,4 and 5 as output pins.
void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}
This code controls motor speed. For that, we can give a value between 0-255.
  analogWrite(3, 254);
 
This code controls the direction of the motor. The motor rotates left and right.
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  delay(2000);
  digitalWrite(5, HIGH);
  digitalWrite(4, LOW);
  delay(2000);
 

Step 4

Select board and port.

Step 5

Upload the code and watch it.
Watch the video below. It describes this project.
The circuit diagram and code in the video above are given below.

Circuit diagram

 

Source code

void setup() {
pinMode(9,OUTPUT);//define pin D9
pinMode(10,OUTPUT);//define pin D10
}
void loop() {
digitalWrite(9,HIGH);//motor turn left
delay(1000);//delay
digitalWrite(9,LOW);//motor off
delay(1000);
digitalWrite(10,HIGH);//motor turn right
delay(1000);
digitalWrite(10,LOW);//motor off
delay(1000);
}

We will meet in the next post. Have a good day. Bye-bye.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Scroll to Top