Using the L2398N as a potentiometer

Hi folks!

I have an Arduino Uno, an L2398N, a fan, and a 12-volt battery.

I also wrote the following code:

int enA = 9;
int in1 = 2;
int in2 = 3;
int motorSpeed = 0; // Declare motorSpeed variable

void setup() {
    // Set all the motor control pins to outputs
    pinMode(enA, OUTPUT);
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);

    // Turn off motors - Initial state
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    Serial.begin(9600);  // initialize serial communication at 9600 bits per second
}

void loop() {
    // Turn on motors
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);

    // Check for user input
    if (Serial.available() > 0) {
        char input = Serial.read();

        // Adjust speed based on user input
        if (input == '+') {
            if (motorSpeed < 255) {
                motorSpeed += 51; // Incrementing the maximum value
            }
        } else if (input == '-') {
            if (motorSpeed > 0) {
                motorSpeed -= 51; // Decrementing the maximum value
            }
        }

        // Constrain the motor speed to be within 0-255
        motorSpeed = constrain(motorSpeed, 0, 255);

        // Print the current fan status after adjusting the speed
        Serial.print("Fan Status: ");
        Serial.println(motorSpeed);

        // Set motor speed
        analogWrite(enA, motorSpeed);
    }

    // Delay to allow time for the motor to adjust to the new speed
    delay(1000);
}

I connected the battery directly to the fan, then I measured the current and the result was 11.98 volts

Using the L2398N as a potentiometer, I measured the current and the result was 2.09 volts when the "motorSpeed" variable reached its maximum of 255.

My goal is for the output (to the fan) to be about 12 volts (11.98 volts) once the "motorSpeed" variable has reached its maximum of 255.

To obtain the 12 volts (11.98 volts), is there another type of potentiometer I should use, or am I doing anything wrong?

You don't measure current if "result" is xx volts. Unit for current is ampere (A, amps)
L2398N is not potentiometer, it's motor driver, they don't have anything in common.

If you want to measure max voltage output of your motor driver, you can just connect ena pin to 5V and measure fan voltage.
Or you can just define:
int motorSpeed = 255;
and measure voltage.
If your wiring is correct you should measure around 10V, there is voltage drop typically about 2V on your driver

What is the fan's full load current in Amperes?

Correct me if I'm wrong, it appears like the ENA is already linked to 5V based on the image.
Screenshot from 2024-07-08 00-42-24

15 Amperes

You need to better understand the terms:

You are driving the L2398 with a PWM signal. Google PWM to get a better understanding.

What meter are you using to measure? In any case the measurement you are making is voltage in the unit "volts". Not current.

Using the L2398N as a potentiometer, I measured the current and the result was 2.09 volts when the "motorSpeed" variable reached its maximum of 255.

analogWrite(enA, motorSpeed);

Change this line to:

analogWrite(enA, 255);
And re measure the motor voltage

Is your driver an L298? If so, that is 7 times it's current rating.
Post the fan's datasheet or it's brand name and exact part number.

If so, where is your arduino pwm pin 9 going to??
It's better that you present your complete setup. Fan,driver,power supply and wiring.

1 Like

Aren't they removeable links like this:
Jumper Link
Provided so that people who don't want to control the speed don't have to tie up an extra pin on their Arduino.

I can see rectangles in a lighter grey colour on this picture of the PCB you gave us:
PCB links

1 Like


image1 - Shows the motor I'm using, it is from a car fan '006453t'.

image2 - Shows my connections from the motor controller, the Arduino, the battery terminals and the car motor fan.

image3 - Shows the current when I connect the battery directly to the fan motor

image4 - Shows the resulting voltage.

If 15Amps is your current, you need driver that can handle it.
The driver L2398 is unknown to me, and L298 wouldn't be sufficient for that current.

1 Like

Thank you for your help and patience in explaining all of this things :smiley:

A H-bridge is for spinning motors both ways, and is the wrong choice for that fan.

Use a mosfet (module), so your fan spins only one way.
Something like this (click) could work.
Leo..

I found the BTS7960B I think it also works for what I want(need)

Which is another H-bridge.

You don't want a H-bridge for a squirrel cage fan that only works in one direction.
Just use a mosfet switch. You can PWM the fet for speed control.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.