Controlling a motor using a 12V line , and using arduino to vary resistance

I recently finished a project to control a DC motor with the L298N module with arduino, however one of the main problems i have encountered is that when using a low duty cycle (when the pulses are short) it does a high pitched whine noise till i get it to about 25% duty cycle then itl will jerk slightly and start spinning slowly. I Want to completely eliminate this problem by instead providing full 12V to the Motors, and instead make the arduino control a resistor to the motors so that way it can operate smoothly from 0-12V, aka no pulses. Just pure 12V DC, 9V DC, 8V DC, etc. I believe i need to use a relay but any sort of guidance on what parts to get would be greatly appreciated. Thank you

These are very old and inefficient drivers.

Try a proper MOSFET driver from Pololu.

No, no, no. That's crazy.
Please post links to the datasheets for the motor and the power supply.
The symptoms You tell about are surely due to a kind of mismatched devices.
A pen and paper schematics could be valuable for solving the issue.

1 Like

I see your name is railroader! im actually trying reactivate an old busted O scale train, when i used the L298N it had alot of whine before starting to move, but im trying to get it to move slowly with out the whine noise.
The motor in question: https://datasheetspdf.com/pdf/1236558/MABUCHI/RS-385SH/1
L298N module: https://components101.com/sites/default/files/component_datasheet/L298N-Motor-Driver-Datasheet.pdf

Ive asked this question also on other hobby shops and they pinpoint the L298N module as the main culprit

any guides out there on how to intergrate it with arduino?
these look like they can get the job Done Pololu - Mini MOSFET Slide Switch with Reverse Voltage Protection, LV

Let’s make some assumptions.

Say your Arduino UNO gets the engine to start moving (without whining) when you do analogWrite(motorPin, 48);

The solution then is to never use less than 48. :thinking:


You can also experiment using the timer one library to generate a higher PWM frequency.


#include <TimerOne.h>

#define pwmRegister OCR1A const int outPin = 9;

long period = 10000; long pulseWidth = 1000;

// the logical pin, can be set to OCR1B // the physical pin

// the period in microseconds // width of a pulse in microseconds

int prescale[] = {0,1,8,64,256,1024}; // the range of prescale values

void setup() { Serial.begin(9600); pinMode(outPin, OUTPUT); Timer1.initialize(period); setPulseWidth(pulseWidth); }

void loop() { }

// initialize timer1, 1000 microseconds

bool setPulseWidth(long microseconds) { bool ret = false;

int prescaleValue = prescale[Timer1.clockSelectBits];

// calculate time per counter tick in nanoseconds long precision = (F_CPU / 128000) * prescaleValue ; period = precision * ICR1 / 1000; // period in microseconds if( microseconds < period) {

int duty = map(microseconds, 0,period, 0,1024); if( duty < 1)

duty = 1;

if(microseconds > 0 && duty < RESOLUTION) {

Timer1.pwm(outPin, duty);

ret = true; }

} return ret;

}

But get a better motor driver too.

The L298 is stone age technology wasting 2 - 4 volts due to the Darlington transistors. Go for MOSFET based H-bridges.
Polulu (?) is said to sell such ones.

Make sure the bearings are lubricated? If they are dry they will produce a screaming noise.

Trust @ LarryD

Try this to see at what PWM DC the motor starts to move.

You need to install the TimerOne.h library.

This line set the PWM frequency:

  Timer1.initialize(100);  //100us = 10khz

Pin 9 goes to ENA
Set your IN1 and IN2 pin levels to set the direction.

//Arduino UNO

#include <TimerOne.h>

void setup()
{
  Serial.begin(9600);
  
  pinMode(9, OUTPUT); //Use pin 9 or 10
  Timer1.initialize(100);  //100us = 10khz
  Timer1.pwm(9, 750);      // 50% DC
  // You can use 2 to 1023
  // 0 & 1 gives a constant LOW
  // 2     gives ~125ns HIGH pulses
  // 512   gives 50us (50%)
  // 1023  gives ~125ns low pulses
  // 1024  gives a constant HIGH
}

void loop()
{
  for (int x = 200; x <= 1024; x++)
  {
    Timer1.pwm(9, x);
    delay(100);
    Serial.println(x);
  }

}

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