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
Aren't they removeable links like this:
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:
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..