Lab 2
Lab 2
Objectives:
Introduction
Motor speed and direction control is a fundamental aspect of robotics
and automation, playing a pivotal role in determining the movement,
precision, and functionality of robotic systems. Whether it's in industrial
automation, mobile robots, or even hobbyist projects, the ability to
precisely manage the speed and direction of motors is the cornerstone of
achieving tasks efficiently and with precision. By modulating the
rotational speed and steering of motors, we unlock a world of
possibilities, from the precise positioning of robotic arms to the
navigation of autonomous vehicles. In this realm of control, we delve
into the technologies and methodologies that empower us to manipulate
motors with finesse, turning them into the obedient workhorses of our
mechanized world.
Direction of a DC Motor:
To change the direction of a DC motor, you need to reverse the polarity of the voltage applied
to the motor. This can be accomplished in several ways, depending on your application and the
available components. Here are some common methods for reversing the direction of a DC
motor:
A
Robotics Lab LAB 2
1. H-Bridge Circuit:
An H-bridge is a popular and versatile circuit for changing the direction of a DC motor. It uses
a combination of transistors or relays to control the voltage polarity to the motor.
- Depending on the logic level applied to the control pins of the H-bridge, you can make the
motor rotate clockwise, counterclockwise, or stop it.
3. Relay Circuit:
A relay is an electromagnetic switch that can be used to reverse the direction of the motor.
Connect the motor to the common terminal of the relay and use the normally open (NO) and
normally closed (NC) contacts to change the motor's direction.
5. Microcontroller or Arduino:
If you're using a microcontroller like Arduino, you can control the motor direction by writing
code that controls the GPIO pins connected to the motor driver. For example, by changing the
state of specific pins, you can reverse the motor's direction.
H Bridge:
Circuit containing 4 switching elements + 4 catch diodes
Switching elements are usually bipolar transistors or MOSFETs
Catch diodes are used to prevent short circuiting
Path of current controlled by switches
Robotics Lab LAB 2
Incorrect path
L298n Specifications
● Input Voltage: 3.2V~40Vdc.
● Driver: L298N Dual H Bridge DC Motor Driver
● Power Supply: DC 5 V - 35 V
● Peak current: 2 Amp
● Operating current range: 0 ~ 36mA
● Control signal input voltage range :
● Low: -0.3V ≤ Vin ≤ 1.5V .
● High: 2.3V ≤ Vin ≤ Vss.
● Enable signal input voltage range :
● o Low: -0.3 Vin 1.5V (control signal is invalid).
● o High: 2.3V Vin Vss (control signal active).
● Maximum power consumption: 20W (when the temperature T = 75 °C).
● Storage temperature: -25 °C ~ +130 °C.
● On-board +5V regulated Output supply (supply to controller board i.e. Arduino).
● Size: 3.4cm x 4.3cm x 2.7cm
Schematic Diagram:
Robotics Lab LAB 2
Connection Examples:
Controlling 2-DC Motor with +5V Arduino onboard Power Supply:
Below is the circuit connection use the on-board +5V power supply from Arduino board, and
should be done without the 5V Enable Jumper on (Active 5V). This connection can drive two 5V
DC motors simultaneously.
Robotics Lab LAB 2
Sketch Listing:
// Definitions Arduino pins connected to input H Bridge
int IN1 = 4;
int IN2 = 5;
int IN3 = 6;
int IN4 = 7;
void setup()
{// Set the output pins
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop()
{// Rotate the Motor A clockwise digitalWrite(IN1, HIGH);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
delay(2000);
// Motor A
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
delay(500);
// Rotate the Motor B clockwise
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
delay(2000);
// Motor B
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
delay(500);
// Rotates the Motor A counter-clockwise
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
delay(2000);
// Motor A
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
delay(500);
// Rotates the Motor B counter-clockwise
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
delay(2000);
// Motor B
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
delay(500);
}
The below provided Arduino code is designed to control a DC motor using an L298N H-Bridge
motor driver, a potentiometer for setting the motor speed, and a push-button to reverse the
motor's direction.
The result is that you can use the potentiometer to control the motor speed, and pressing the
push-button reverses the motor's direction.
Robotics Lab LAB 2