RF communication problem while driving DC motors via LN298N

I have a small robot built on Arduino Mega 2560, using two 12V DC motors to move, which are driven by L298N. 315/433MHz RF units are also used to communicate with a remote controller (another Arduino; Nano connected to a PC. So that, from my PC I can enter commands like f,b, r,l and the robot executes them upon receiving.

The problem is that, if the engines are running the robot (RF receiver or Arduino??) does not receive any more remote commands. When stopped, it can receive commands. I tested following scenarios:

1.) Command f: FORWARD. Robot moves forward. No any other additional controls in the loop. Both motors are enabled and keep going. Never receives any messages afterwards.

2.) Command l, r: LEFT/RIGHT. These are state preserving commands, i.e., if the robot is initially stopped, it makes a left or right turn, and stop again. So, while turning process robot does not receive any message, but when stopped, it does. So I can make successive left/right turns (starting with a STOPped state).

3.) Command b: BACKWARD. Same as FORWARD.

4.) Command s: STOP. While stopped, if I send stop message it is received and aknowledged. But if the robot is on the move, it is not received. Any other message is also received and executed, with results described above.

5.) I connect the Arduino to PC via USB, so the Arduino is ON, but 12V DC is not switched on for LN298N. I send FORWARD message, it is received, but of course the motors do not start, there is no 12V DC power. Then I send a second message like STOP, or LEFT, or RIGHT. And it is RECEIVED.

6.) Same as above, plus the 12V DC is swhitched ON, but the DC motors are disconnected. So, the L298N is ON but there is no real power usage by the motors. ALL MESSAGES ARE RECEIVED, but of course not executed.

7.) From a directly attached PC via Serial interface all commands are received. So the Serial interface is working properly.

So, if motors are ON, then somehow the RF message is lost.

First I thought it was because I was using a bare L298N with no capacitors/diodes around. I added 3 100 uF capacitors, one for each motor and one for 12V DC supply. No change.

Then I bought the L298N Module 2A, with capacitors and diodes and all. Same problem.

I believe the problem has to do with power usage; case 6 clearly shows this but I tried my best. What else can I do?

I wonder if you really mean RFID?

Post a link to the datasheet for the wireless devices you are using.

Make a simple drawing showing how everything is connected and post a photo of the drawing.

Post your program code.

And please post your code between [code] [/code] tags so your code looks like thisand is easy to copy to a text editor

...R

OK, here is some extended info. First the drawing. Inline image paste somehow did not work. I will try attaching the image.

Power comes from 12V 7AH battery. I added parallel power lines from outside the 12V barrel jack input, directly to L298N, to keep the motor circuit out of Arduino. 12V and 5V grounds are connected to have a common ground.

I am not using PWM at the moment, so all L298N inputs are from digital ports, no PWM, simple ON/OFF control.

DC motors are for car windows. At idle they draw about 850 mAmps, each. As far as I know, L298N can support up to 2AMPs for each channel.

Here is the relevant part of the code with initial definitions. I use VirtualWire library for RF communication, and I2C for MPU6050, attached via SCLK, SDA ports.

Code: [Select]


#include <VirtualWire.h>
#include <VirtualWire_Config.h>

#include <Time.h>
#include <TimeLib.h>

#define IN1 33 
#define IN2 34
#define EN1 28

#define IN3 35
#define IN4 36
#define EN2 30

char cmdList[18] = {'s', 'f', 'l', 'r', 'b', 'm', 'd', 'g',
                     '0', '1', '2', '3', '4', '5', '6',
                     '7', '8', '9'};

void setup() {
  Serial.begin(115200); 
  vw_set_rx_pin(11);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2400);	// Bits per sec
  vw_rx_start();       // Start the receiver PLL running
  vw_set_tx_pin(8);

  MPUsetup();
  
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(EN1, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(EN2, OUTPUT);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(EN1, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  digitalWrite(EN2, LOW);

  targets[0][0] = 0.0;
  targets[0][1] = 0.0;
  targets[1][0] = 1.20;
  targets[1][1] = 0.84;
  targets[2][0] = 0.32;
  targets[2][1] = 0.94;

  /*int myEraser = 7;
  TCCR2B &= !myEraser;
  int myPrescaler = 2;
  TCCR2B |= myPrescaler;*/
  
    dmsg[0] = 'S';
    dmsg[1] = 'L';
    dmsg[2] = 'I';
    dmsg[3] = 'V';
    dmsg[4] = 'E';
    dmsg[5] = '\0';
    report(dmsg);
  }

void loop() {
    
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    char letter = "";

    if (vw_get_message(buf, &buflen)) letter  = char(buf[0]);
    else if (Serial.available() > 0) letter = Serial.read(); 
    
    if (isElmInArray(letter, cmdList)) {
      Serial.print("Command received: ");
      Serial.println(letter);
  
      if (letter == 'f') forward();  
      else if (letter == 's') fullStop(1); 
      else if (letter == 'b') reverse();  
      else if (letter == 'l') turnLeft();
      else if (letter == 'r') turnRight();
      else if (letter == 'm') revMan();  
      else if (letter == 'd') targets(); 
      else if (letter == 'g') gotoPos(1.12, 0.54); 
      else if (letter == '0') turnDegs(-50.0); 
      else if (letter == '1') turnDegs(10.0); 
      else if (letter == '2') turnDegs(20.0); 
      else if (letter == '3') turnDegs(30.0); 
      else if (letter == '4') turnDegs(40.0); 
      else if (letter == '5') turnDegs(50.0); 
      else if (letter == '6') turnDegs(-10.0); 
      else if (letter == '7') turnDegs(-20.0); 
      else if (letter == '8') turnDegs(-30.0); 
      else if (letter == '9') turnDegs(-40.0);
      return; 
    } 

  MPUloop();
  extern float targetX;
  extern float targetY;
  extern float SetPt;
  extern int turnFlag;
  extern bool posFlag;
  extern int state;
  extern float x0;
  extern float y0;
  extern float gzm;
  if (turnFlag > 0) turn();
  if (posFlag > 0) {
    keepHeading();
    goTo();
  }
}

int fullStop(int dly){
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  digitalWrite(EN1, LOW);
  digitalWrite(EN2, LOW);
  delay(dly);
  state = -1;
  Serial.println("4 - BOTH STOP");
  return dly;
  }

void reverse(){  
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  digitalWrite(EN1, HIGH);
  digitalWrite(EN2, HIGH);
  state = 0;
  Serial.println("5: REVERSE");
  return;
  }

void forward(){
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  digitalWrite(EN1, HIGH);
  digitalWrite(EN2, HIGH);
  state = 1;
  Serial.println("1 - FORWARD");
  return;
  }  

void turnRight() {
  Serial.println("3:  RIGHT");
  turnDegs(-90);
  return;
  }
    
void turnLeft() {
  Serial.println("2:  LEFT");
  turnDegs(90);
  return;
  }

void revMan(){
  fullStop(100);
  turnDegs(180);
  return;
  }

 boolean isElmInArray(char element, char array[]) {
 for (int i = 0; i < 18; i++) {
      if (array[i] == element) {
          return true;
      }
    }
  return false;
 }

  void gotoTargets() {
    targets[0][0] = 1.12;
    gotoPos(targets[0][0], targets[0][1]);
 }

Image from Reply #2 so we don't have to download it. See this Image Guide

...R

You have not provided the connection diagram that I requested. That is essential to determine if the motors may be interfering with the Arduino or the wireless. And please show ALL the connections.

It looks like you are using 433MHz wireless devices. They have nothing to do with RFID and it would help if you modify your original post and correct the title so people know what your problem really is.

I am not familiar with those wireless devices myself.

You seem to have a wireless receiver and a wireless transmitter connected to your Arduino. What is sending the data to the Arduino and what data does the Arduino send back?

Going back to your Original Post, do you mean that the robot can be controlled over the serial connection to the PC but that it cannot be controlled by wireless when the motors are moving?

And do you mean that you have the PC connected at the same time as the wireless receiver? Or are you trying them separately.

...R

OK, first I have corrected the original post from RFID to RF. Thanks for pointing out that.

Second, answers to your questions:

Robot can be controlled both via Serial connection and/or RF connection. Serial connection works OK no matter what; that is, whether the motors are ON or OFF and whether ther RF fails or not. I send commands from another pC via remote controller, and it fails, but right afterwards, I send commands from directly attached pc via serial, and it works OK. Normally of course I will not use this direct connection. That is used for diagnostics purpose. In summary, serial connection works fine under all conditions, but that is not whta I want. RF connection fails after the first command, if the motors are ON.

RF units are one of the most commonly used cheapest units. Here is the technical info about the RF units with a link to datasheet. I use VirtualWire as comms library:

At the moment, remote controller (arduino NANO) sends commands to the robot (Arduino MEGA). Robot does not send back any info at the moment. Just execute the command. Later I will be sending some status info like robot position, etc.

And the funny thing is tthat this setup was working on a Arduino NANO, which I had to replace due to memory limitations and move to MEGA.

I will prepare the detailed connection drawing, which may take some time. The essential info is already provided on the attached image with relevant pin numbers given.

I would bet the OOK or ASK modulation from those cheapy radios is totally swamped by the commutation noise from the motors, you need to step up to more sophisticated radios with FSK and FM or PM modulation and more TX power.

A photo of a simple pencil drawing of the connections is better than many of the "sophisticated" diagrams that are posted here.

You may wish to consider using nRF24L01+ 2.4GHz transceivers. Simple nRF24L01+ Tutorial

...R

And here is the detailed drawing showing all the connections. I will try to implement the funny method to make it visible. First try, attaching it.

And now we edit to insert the image in line

Then you fail, bacuse of 5 mins limit. And wait for five minutes.

"

The message has the following error or errors that must be corrected before continuing:
You have exceeded the number of posts you can make in a 5 minutes period. Please try again later.

"

  • RF filters on motor leads.

This setup was working with Nano, which I had to leave because of memory limitations.

I thought all that complex circuitry of the L298N Module with capacitors and diodes would handle that kind of noise problems.

Definitely need ceramic caps on the motor terminals if brushed motors, and ferrites on the motor leads
is good. Motor leads should be twisted pair, optionally shielded. In fact all high current wiring
is best as twisted pair really.

Keep the RF receiver well away from the motors and drivers too.

Rather than have an OOK TX and separate RX, a proper transciever using GFSK would be way more
robust to interference (but you still want to reduce the motor interference as much as possible).

khbilen:
Then you fail, bacuse of 5 mins limit. And wait for five minutes.

That goes away after you have make 50 or 100 posts (can't remember which). It's purpose is to combat SPAM, but I agree it is a PITA.

...R

Yes, a PITA, but needed. We Moderators couldn't keep up with all the spam, couldn't ban fast enough to keep the flood of spam across multiple forums out and delete all the trash being posted. New posters just have to grin and bear it now.

I found the problem.

It is the jumper on L298N Module. It says remove it if you are using larger than 12V. Assuming the battery is 12V DC I did not bother with it, and kept it there.

But after trying everything else, I looked at the manual back again, and this time I decided to remove the jumper, just in case. And it works.

Thanks for all attention and suggestions.

Just for the documentation to be complete I will embed the relevant image here.

Well, this time it did not like the attachment picture. I will try to add the link, if possible.