Need Help In Arduino Uno, L298N and Dc Motor

BTW, what is the voltage rating of your motor ?

I dont Know, I am using the motor that came with

Do you have a jumper on the M1 ENABLE header pins ?

yes. is it neccessary to put on both or only the one facing towards outwards. Bye gotta go..

Try this simple sketch: (NOT TESTED)

Arduino to motor driver header connection:

Arduino pin A0 connect to wiper of the joystick

Arduino pin 2  connect to IN1
Arduino pin 3  connect to IN2
Arduino pin 9  connect to ENA A (motor 1 enable)
int Xpin       = A0; //connect to wiper of the joystick
int m1Pin1     = 2;  //connect to IN1
int m1Pin2     = 3;  //connect to IN2
int m1SpeedPin = 9;  //connect to ENA A (motor 1 enable)

int Xval;
int m1Speed;

void setup()
{
  Serial.begin(9600);

  pinMode(m1Pin1, OUTPUT);
  pinMode(m1Pin2, OUTPUT);

  pinMode(m1SpeedPin, OUTPUT);
  analogWrite(m1SpeedPin, 0);

  digitalWrite(m1Pin1, HIGH);
  digitalWrite(m1Pin2, LOW);
}

void loop()
{
  Xval = analogRead(Xpin);

  m1Speed = Xval / 4;
  analogWrite(m1SpeedPin, m1Speed);

  Serial.print(" m1speed = ");
  Serial.println(m1Speed);

  delay(100);
}

Remove the ENA and ENB jumpers for regular motor operation when using analogWrite to control these pins for PWM speed control.

I can't understand what to do. I have removed the jumpers and it a wire on them

**You need to make these connections from the Arduino to the Motor Controller header.**

Try the sketch I offered you.

Arduino pin 2  connect to Motor Controller   IN1
Arduino pin 3  connect to Motor Controller   IN2
Arduino pin 9  connect to Motor Controller   ENA A (motor 1 enable)

I hav already made connections. I am trying to control my motor using joystick

please tell if I should use code in post 43 or post 48

I have tested this code and it worked in serial monitor just the way I wanted it to. Is there any thing wrong in this. Xval and Ubal are of joystick

The sketch in post 48 is just to check to see if the motor speed can be controlled.

Did the sketch from post 48 control you motor speed ?

Let me try. I seem to have misplaced my L298d

@LarryD are you saying the jumper which is by default there? or a jumper wire.

The module usually comes comes with with a jumper installed, you do not want the jumper for simple motor control.
Motor 1 (enable) connects to Arduino D9 (PWM pin) for speed controlling.

Arduino pin 9 connect to Motor Controller ENA A (motor 1 enable)
i.e. analogWrite(m1SpeedPin, m1Speed);

couldnt understand it pls clarify

should i remove jumper and store it or keep it on. i had tested the motor using 9v battery and it worked when i touched the wire from 5v to in1 or in2. i connected it using arduino removed jumper and it did not work @LarryD

will 2 9v battery work? if yes how to use it

Avoid 9 volt PP3 batteries they cannot supply very much current.

//Forum URL  https://forum.arduino.cc/t/need-help-in-arduino-uno-l298n-and-dc-motor/870113/43

//Version  YY/MM/DD  Description
//1.00     21/06/23  functioning code
//

//The value read from the potentiometer is used to control the speed of the motor

const byte Xpin         = A0; //connect to wiper of the joystick
const byte m1Pin1       = 2;  //connect to IN1
const byte m1Pin2       = 3;  //connect to IN2
const byte m1SpeedPin   = 9;  //connect to ENA A (motor 1 enable) <----<<<< **jumper must be removed**
const byte heartbeatLED = 13;

int Xval;
int m1Speed;

//timing stuff
unsigned long heartbeatMillis;


//*****************************************************************************
void setup()
{
  Serial.begin(9600);

  pinMode(heartbeatLED, OUTPUT);

  pinMode(m1Pin1, OUTPUT);
  pinMode(m1Pin2, OUTPUT);

  pinMode(m1SpeedPin, OUTPUT);
  analogWrite(m1SpeedPin, 0);

  //clockwise CW
  digitalWrite(m1Pin1, HIGH);
  digitalWrite(m1Pin2, LOW);

  //counter clockwise CCW
  //digitalWrite(m1Pin1, LOW);
  //digitalWrite(m1Pin2, HIGH);
  
} //END of setup()


//*****************************************************************************
void loop()
{
  //*************************************
  //the heartbeat LED indicates if the sketch is 'BLOCKING'
  //time to toggle the heartbeat LED ?
  if (millis() - heartbeatMillis > 500)
  {
    //restart the TIMER
    heartbeatMillis = millis();

    //toggle the heartbeat LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*************************************
  //adjust the motor speed
  Xval = analogRead(Xpin);          //read the potentiometer i.e. 0-1023
  m1Speed = Xval / 4;               //convert to 0-256
  analogWrite(m1SpeedPin, m1Speed); //send PWM to the motor controller

  Serial.print(" m1speed = ");
  Serial.println(m1Speed);


} //END of loop()

//*****************************************************************************

I can already do that without code

Did you try the wiring and sketch found in post #61 ?