nrf24l01+ L293d Problem!

Hi,

I am working on a transmitter and a receiver using nrf24l01+. Now the receiver has a L293d motor driver and 2 dc motors powered by a couple of 18650s.The motors are toy dc and have a 0.1uf caps on their ends and I have a 10uf cap on the pin 8 and ground of the l293d. The transmitter has 4 buttons.
The rf is powered off 3.3V pin of the arduino and has a 10uf cap between the positive and the ground.

The nrf24l01 works fine, L293d works fine, but together, Now things are messed up.

I am using the Tmrh20 library for the rf.

Now if the delay on the receiver end is around 0-10 ms for the entire loop, the rf receives all packets.
As I add delay(10>delay>20) after the analogWrite(), the radio starts to lose packets. Now as the delay is greater than 20 the radio receives a packet and then stops receiving packets and the motors spins continuously according to the received packet.

If I dont add delay, the motors spin very slow. I add delay, the motor spins fast but I lose the rf.

I even tried new hardware(rf,driver ic and arduino) but still no good result.

Here is the code for the transmitter.

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>

#define CE_PIN   9
#define CSN_PIN 10
byte address[][6] = {"1Node"};
RF24 radio(CE_PIN,CSN_PIN);

char v;
char val;
char packet;
int up;
int down;
int left;
int right;

/*struct Packet{
  char val;
  int delayee;
};

Packet packet;*/

void setup() {
  
  Serial.begin(115200);
  val='4';
  v='0';
  //packet.delayee = 100;
  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
  pinMode(4,INPUT_PULLUP);
  pinMode(5,INPUT_PULLUP);
  radio.begin();
  printf_begin();
  radio.setChannel(108);
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate( RF24_250KBPS );
  radio.setRetries(3,5); // delay, count
  radio.openWritingPipe( address[0]);
  radio.printDetails();

  // put your setup code here, to run once:

}

void loop() {
  //int timestart =millis();
  //Serial.print("Start: ");
  //Serial.println(timestart);
  up=digitalRead(2);
  down=digitalRead(3);
  left=digitalRead(4);
  right=digitalRead(5);
  /*int doneRead = millis();
  Serial.print("digitalRead Time: ");
  Serial.println(doneRead - timestart);*/

  if(up==LOW){
    //packet.val = '0';
    val = '0';
  }
  else if(down == LOW){
    //packet.val ='1';
    val = '1';
  }
  else if(left == LOW){
   // packet.val = '2';
   val = '2';
  }
  else if(right == LOW){
    //packet.val = '3';
    val = '3';
  }

  else{ 
    //packet.val ='4';
    val = '4';
  }
  /*Serial.println(packet.val);
  radio.write(&val,sizeof(char));
    //delay(20);
 // Serial.println(millis()-doneRead);
  /*if(Serial.available()){
  serialByte=Serial.read();
  }
  else
  serialByte='4';
  //radio.write(&serialByte, sizeof(char));
  
if(!radio.write(&serialByte, sizeof(char)))
Serial.println("not sent");
delay(20);*/
  /* put your main code here, to run repeatedly:*/

}

The code for the receiver

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>

#define CE_PIN   7
#define CSN_PIN 8

RF24 radio(CE_PIN,CSN_PIN);

int ip1 = 3;
int ip2 = 5;
int ip3 = 6;
int ip4 = 9;

byte address[][6] = {"1Node"};
char val;
/*struct Packet{
  char val;
  int delayee;
};

Packet packet;*/
void setup() {
 Serial.begin(115200);
  // put your setup code here, to run once:
  pinMode(ip1,OUTPUT);
  pinMode(ip2,OUTPUT);
  pinMode(ip3,OUTPUT);
  pinMode(ip4,OUTPUT);

  //Serial.println("SimpleRx Starting");
    radio.begin();
    printf_begin();
    radio.setChannel(108);
    radio.setPALevel(RF24_PA_MIN);
    radio.setRetries(3,5);
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, address[0]);
    
    radio.startListening();
    radio.printDetails();

}

void loop() {
  //int start = millis();
  //char val = Serial.read();
 if (radio.available()){
    radio.read(&val,sizeof(char));
    delay(30);
  }
 /* else{
   packet.val='4';
  // packet.delayee = 50;
   }*/
 /* int Read = millis();
 
  Serial.println(packet.val);
  Serial.println(Read - start);*/
  
  //forward
  
  if(val == '0')
  {
    //Serial.println("Forward");
    analogWrite(ip1,200);
    analogWrite(ip2,0);
    analogWrite(ip3,200);
    analogWrite(ip4,0);
    //delay(packet.delayee);
  }


  //backward
  else if (val  == '1')
  {
    //Serial.println("back");
    analogWrite(ip1,0);
    analogWrite(ip2,200);
    analogWrite(ip3,0);
    analogWrite(ip4,200);
   // delay(packet.delayee);
  }

  //left
  else if (val  == '2')
  {
    //Serial.println("Right");
    analogWrite(ip1,200);
    analogWrite(ip2,0);
    analogWrite(ip3,0);
    analogWrite(ip4,0);
    //delay(packet.delayee);
  }

  //right

  else if (val  == '3')
  {
    //Serial.println("Left");
    analogWrite(ip1,0);
    analogWrite(ip2,0);
    analogWrite(ip3,200);
    analogWrite(ip4,0);
   // delay(packet.delayee);
  }

  else if(val  == '4')
  {
    //Serial.println("Stop");
    analogWrite(ip1,0);
    analogWrite(ip2,0);
    analogWrite(ip3,0);
    analogWrite(ip4,0);
    //delay(packet.delayee);
  }
  /*Serial.print("Done loop in ");
  Serial.println(millis() - Read);
  delay(40);*/
  // put your main code here, to run repeatedly:

}

Are you sure you are using the TMRh20 version of the RF24 library and not the older ManiacBug version? I had problems with the ManiacBug version when there was long interval between calls to the radio (can't remember if it was on the Tx or Rx side) - but it was nothing to do with a motor.

Is the nRF24 antenna very close to the motor?

On the small motor I have I put three 0.1µF caps - one each from the two terminals to the body and one across the terminals. I don't recall any symptoms like you describe but I don't have an L293D.

...R

Thanks for your reply.

Yes I am pretty sure i use the Tmrh20 lib. I used the library manager to download the lib. Yeah the rf is a few inches away from the motors. I found a funny thing. The system seems to work if the radios are at a distance less than 1 feet and facing each other.
These are the motors I am using.

They are rated for 5 V but I salvaged them from a toy that ran on 10 AA batteries.

If I add an 'else' when the radio doesnt receive a packet, it somewhat solves the problem but the motors lose their speed after a fraction of seconds and the motors rotate kinda funny. The rotation is not at all smooth (continuous) and motors tend to stop for a fraction of a second and start again. The motors are enclosed in a plastic case.

void loop(){
if (radio.available()){
    radio.read(&val,sizeof(char));
  }
else   //  if i add these 2 lines, It somewhat solves the problem. BUT!!!!
    val ='4';//
\\
\\
\\
\\

I have some motors similar to that and have not had problems provided I have capacitors on them.

I presume the power for the motors is coming directly from the battery and is NOT passing through the Arduino?

...R

ok guys.

I said I'm using l293d and output 1 and 2 of the l293 is connected to the terminals of the motor 1 and output 3 and 4 are connected to the motor 2 terminals. The driver is is powered off(pin 16) 5V from the arduino nano, and VCC1 (pin 8) has 3 li ion 18650 in series (3.7*3 V) to power the motors. I hope my configuration is clear to u.

My problem is, when I add a delay greater than 20 ms, the radio starts losing packets. The receiver just gets 1 packet and doesn't receive any more ( until the radios are less than 1 feet apart).

deathlock:
I hope my configuration is clear to u.

Sorry, NO.

Please make a simple pencil drawing showing all the connections and post a photo of the drawing. Please DO NOT use Fritzing.

...R

Can you please upload an image showing the connections you made to connect nrf24l01 and l293d on arduino .