(RPM & DIRECTION) Contolling of DC Motors Using Potentiometer

by anuragfulmali in Circuits > Arduino

54 Views, 0 Favorites, 0 Comments

(RPM & DIRECTION) Contolling of DC Motors Using Potentiometer

Screenshot 2024-07-24 112140.png

In this project i got to learn about the pairing of Arduino with Motor Driver and Controlling the DC Motors with the help of Motor Driver L298N and Controlling the RPM of Motors using the Potentiometer(Variable Resistance) of 100k(ohm).

In this Particular Mini Project i controlled the Clockwise and Anti-Clockwise Direction of Motors their speed in either Direction, It's an easy task to pair all of these in a single unit as i provide all the required connections further in the given steps,

The Only Problem i faced while Tinkering the circuit is that the loose connections with the Motors on the Motor Driver, Please be sure that you do not commit the same Mistake as Me, these Actuators can be used in any required Electro-Mechanical Projects as they are easy to operate using the Arduino Microcontroller and L298N Motor Driver.


Another problem i faced after the pairing of all the devices together is that, Motors were not running up to the Desired Output as Set-Up in the CODE, After Brainstorming over this issue i got back to the Basics of of INPUT VOLTAGE(5V),GROUNDING of L298N and Arduino as there must be a common ground in Between them at the Arduino Ground Pin with Connecting Wire(Male to Male). The Image of this grounding is attached as a solution for Resolving the Problem.

Supplies

Screenshot 2024-07-24 112140.png
Screenshot 2024-07-24 112348.png
Screenshot 2024-07-24 112251.png
Screenshot 2024-07-15 140240.png
Screenshot 2024-07-15 135746.png
Screenshot 2024-07-16 120739.png
Screenshot 2024-07-24 112439.png
Screenshot 2024-07-15 140850.png

 1.DC Motors:

2.Potentiometer(b100k):

3.Motor Driver L298N:

4.Connecting Wires:

5.Arduino Uno:

6.Arduino IDE:

DC Motors

Screenshot 2024-07-24 112348.png

DC motors are electric motors powered by direct current (DC) electricity, commonly used due to their simplicity and ease of control. These motors convert electrical energy into mechanical energy through the principle of electromagnetism. When a DC current flows through the motor's armature, a coil of wire within a magnetic field, it generates a force that causes the armature to rotate. This rotation is facilitated by a commutator, which reverses the current's direction, ensuring continuous motion. DC motors have several key components, including the stator (which provides the magnetic field), the rotor or armature (which rotates), the commutator (which reverses current), and brushes (which maintain electrical contact). There are various types of DC motors, such as brushed motors, which are simple and cost-effective but require regular maintenance due to brush wear, and brushless motors, which are more efficient and durable but require electronic controllers. DC motors are widely used in applications like electric vehicles, robotics, home appliances, industrial machinery, and power tools due to their high torque, easy speed control, and compact design.

Potentiometer

Screenshot 2024-07-24 112439.png

A B100K Potentiometer(Variable Resistance) is a type of adjustable resistor commonly used in electronic circuits to vary voltage and control various functions. The "B" indicates that it has a linear taper, meaning its resistance changes evenly as you turn the knob or slide the lever. The "100K" signifies that the maximum resistance it can provide is 100,000 ohms. It has three terminals: two connected to the ends of a resistive element and one to a wiper that moves along this element, allowing you to adjust the resistance between the wiper and each end. This makes it useful for applications like adjusting volume in audio equipment, tuning the output in power supplies, and calibrating sensors, where precise and consistent control is needed.

https://www.mouser.com/datasheet/2/13/RV24AF-1658492.pdf

L298N Motor Driver

Screenshot 2024-07-24 112251.png
Screenshot 2024-07-24 112309.png

The L298N is a popular dual H-bridge motor driver module that allows you to control the direction and speed of two DC motors independently. It is widely used in robotics and other applications requiring motor control due to its versatility and ease of use. The module can handle motors with voltages from 5V to 35V and currents up to 2A per channel. It has four input pins for controlling the motors, allowing you to set each motor's direction and speed by using PWM signals. Additionally, it has onboard protection features like thermal shutdown and current sensing, making it reliable and safe for various projects. The L298N also comes with an onboard 5V regulator, which can be used to power other components in your circuit. This makes it an essential component for hobbyists and professionals working on projects that involve motorized movement.

https://www.handsontec.com/dataspecs/L298N%20Motor%20Driver.pdf

Programme

// Define pin connections for Motor A
const int enA = 9;  // PWM pin to control speed of Motor A
const int in1 = 8;  // Pin to control direction of Motor A
const int in2 = 7;  // Pin to control direction of Motor A


// Define pin connections for Motor B
const int enB = 10; // PWM pin to control speed of Motor B
const int in3 = 5;  // Pin to control direction of Motor B
const int in4 = 4;  // Pin to control direction of Motor B


// Define pin connection for Potentiometer
const int potPin = A0;  // Analog pin to read potentiometer value


void setup() {
  // Set all the motor control pins to output mode
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
 
  pinMode(enB, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);


  // Initialize serial communication for debugging
  Serial.begin(9600);
}


void loop() {
  // Read the potentiometer value (0-1023)
  int potValue = analogRead(potPin);
  // Map the potentiometer value to a range of 0-255 for PWM
  int speed = map(potValue, 0, 1023, 0, 255);


  // Debugging: print the potentiometer and speed values to the serial monitor
  Serial.print("Potentiometer Value: ");
  Serial.print(potValue);
  Serial.print(" | Motor Speed: ");
  Serial.println(speed);


  // Move Motor A forward
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  // Set speed of Motor A
  analogWrite(enA, speed);


  // Move Motor B forward
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  // Set speed of Motor B
  analogWrite(enB, speed);


  // Run the motors for 3 seconds
  delay(3000);


  // Stop the motors
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);


  // Wait for 1 second
  delay(1000);


  // Move Motor A backward
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  // Set speed of Motor A
  analogWrite(enA, speed);


  // Move Motor B backward
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  // Set speed of Motor B
  analogWrite(enB, speed);


  // Run the motors for 3 seconds
  delay(3000);


  // Stop the motors
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);


  // Wait for 1 second
  delay(1000);
}



Hardware Connection

connection.jpg
conc3.jpg
conc2.jpg
WhatsApp Image 2024-07-24 at 11.20.14_06462bad.jpg

These are Hardware Connections are explain in a upward explanation and programme code.

If there is something i may have missed while writing down this blog, please do;

let me know in the comments box.

Downloads