L298N Noise/Interference with wall wort power?

I'm using the L298N along with Uno R3 Plus to perform simple motor control. See attached diagram showing power connections. The sketch and circuit work fine. My problem is that the circuit seems highly susceptible to interference. Without using the up/down button, the motor will activate by itself. Seems to correlate with other activity on the house circuit where the wall wort is plugged in. I have two of these circuits at different locations - one is in kitchen where a dimmer switch exists and really wreaks havoc with the motor activating in fits and starts. Pretty much makes the circuit unusable in this environment (unless dimmer switch is off). The only thing I have tried is moving the 5V output from the L298N to the 5V on the Uno. Behavior is the same either way. Is there an issue with my circuit wiring? Any advice appreciated. Thank you.

Are you using the Arduino internal pull-up resistors for the switch pins?

Paul

Yes. Here's the code:

#define SWITCH_UP 7
#define SWITCH_DOWN 4
#define MOTOR_EN 12
#define MOTOR_IN1 10
#define MOTOR_IN2 8
 
void setup() {
  // put your setup code here, to run once:
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  ledOff();
  pinMode(SWITCH_UP, INPUT_PULLUP);
  pinMode(SWITCH_DOWN, INPUT_PULLUP); 

  pinMode(MOTOR_EN, OUTPUT);
  digitalWrite(MOTOR_EN, LOW);
  pinMode(MOTOR_IN1, OUTPUT);
  pinMode(MOTOR_IN2, OUTPUT);
  digitalWrite(MOTOR_IN1, LOW);
  digitalWrite(MOTOR_IN2, LOW);

}

void ledOn() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
}

void ledOff() {
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
}

void loop() {
  // put your main code here, to run repeatedly:
  int isCmdUp = digitalRead(SWITCH_UP);
  int isCmdDown = digitalRead(SWITCH_DOWN);

  if (isCmdUp && isCmdDown) {
    digitalWrite(MOTOR_EN, LOW);
    digitalWrite(MOTOR_IN1, LOW);
    digitalWrite(MOTOR_IN2, LOW);
    ledOff();
  } else if (isCmdUp) {
    ledOn();
    digitalWrite(MOTOR_IN1, LOW);
    digitalWrite(MOTOR_IN2, HIGH);
    digitalWrite(MOTOR_EN, HIGH);
    delay(100);
    ledOff();
    delay(100);
  } else if (isCmdDown) {
    ledOn();
    digitalWrite(MOTOR_IN1, HIGH);
    digitalWrite(MOTOR_IN2, LOW);
    digitalWrite(MOTOR_EN, HIGH);
    delay(100);
    ledOff();

  }

}

Looks pretty straight forward.
Time to add serial.Print() capability to your program and begin by printing the values you get from reading the switch pins.

Paul

If you are using the 5V regulator on the L298N board to power the Arduino then it should be connected to the 5V pin NOT to Vin. Vin needs at least 6.5-7V to work reliably.

Steve

jopado1:
Any advice appreciated. Thank you.

If the suggestions above don’t help, you could try connecting a ceramic capacitor, say 10nF, between the +12V and GND terminals. The board has a 220uF electrolytic between them, but a little ceramic will do a better job of cleaning up fast spikes that may be coming from the wall-wart, or maybe getting picked up in the wiring from it. Some types of dimmer switch can produce horrible spiky electrical noise.

I've moved the 5V out from the L298N to the 5V input on the UNO (instead of Vin). Also based on where this unit is installed, I cant get a computer attached so the Serial.Print() won't be feasible. However based on the LED activity it is pretty obvious. When the dimmer is off it works flawlessly. When dimmer is on and at max dim or min dim, also works flawlessly. When dimmer is moving or between approx 40 to 80%, constant noise (based on LED activity). I will try the ceramic cap and report back. Thanks to all for having a look at this.

The cap worked! Quick and dirty install, but works great - no more interference. Thank you!