Gear Motor Controlling With Arduino

by STEAM-DIY in Circuits > Arduino

145 Views, 2 Favorites, 0 Comments

Gear Motor Controlling With Arduino

Screenshot 2024-10-15 104712.png

Welcome back to my blog. 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 by 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 gear motor with this motor control board practically. The required components are given below.

  1. Arduino Uno board — 
  2. Motor controller board — 
  3. Gear motor — 
  4. Jumper wires —

Supplies

arduino-uno-r3-with-jumper-wires-60-pc.jpg
Gear.jpg
driver.png

Let’s identify these components.

Diagrame

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.


Code

Look at the code below.

  1. The complete program of this project –
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

Now, select the board and port. After, click the upload button.

Now, you can test this project. The full video guide is below. So, we hope to see you in the next project or tutorial. Have a good day.



follow me and subscribe my youtube channel thanks