Wireless Communication between multiple arduinos

Hi all
Can I use nRF24l01 Transceiver to communicate from one main arduino to other 6 arduino Boards?
When i do use it , there is a lot of lag
I dont know whether the fault is in the code or Should I add any other devices to it?

Yes. "A lot" depends on the project. Tell us more about that.

Other possibilities could include WiFi boards such as Wemos Mini or one of a whole variety of other RF modules such as rf95 which have ranges over several kilometers.

I dont know whether the fault is in the code or Should I add any other devices to it?

That question did not make much sense to me. What fault? What code? What is "it"?

hyperinfinite:
Can I use nRF24l01 Transceiver to communicate from one main arduino to other 6 arduino Boards?
When i do use it , there is a lot of lag
I dont know whether the fault is in the code or Should I add any other devices to it?

If the Arduinos are within range and the lag is more than a few 10s of millisecs then the fault is in your code.

But as you have given no details about what you are doing I can't say more than that.

...R
Simple nRF24L01+ Tutorial

I am using two Arduino Boards

First one connected to my pc
second one, I have mounted on a gate with an Ultrasonic Sensor such that I open the gate, I receive the real time opened distance from second to the first
For both the arduinos I have connected the nRf24l01 to communicate wirelessly.

Code for the first arduino in my PC

#include <SPI.h>

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

RF24 radio(7, 8);

const uint64_t pipes = { 0xF0F0F0F0A1, 0xF0F0F0F0B1 };

void setup()
{
Serial.begin(9600);
radio.begin(); // Setup and configure rf radio
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
radio.startListening(); // Start listening
}

void loop() {
char rcd_data[100] = {0};
if(radio.available())
{
radio.read(&rcd_data, sizeof(rcd_data));
Serial.write(rcd_data); // Serial.println(rcd_data);
}
delay(150);
}

Code for the second Arduino with Ultrasonic Sensor( ONE at the gate)

#include <SPI.h>

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

RF24 radio(7, 8);

const uint64_t pipes = { 0xF0F0F0F0A1, 0xF0F0F0F0B1 };
int trig = 3;
int echo = 4;
int distance;
long value;
//unsigned char UDM_Data[100];
void setup() {
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
Serial.begin(9600);
value = 0;
radio.begin();
radio.openWritingPipe(pipes[1]); // 00001
radio.openReadingPipe(1, pipes[0]); // 00002
radio.stopListening();
}

void loop() {
char UDM_Data[100] = {0};
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
//pinMode(echo,INPUT);
value = pulseIn(echo,HIGH);
distance = value/58;
//if(distance > 5)
{
sprintf(UDM_Data, “RESP_OPENED_DIST_OF : %d”, distance);
radio.write(&UDM_Data, sizeof(UDM_Data));
}
delay(300);
}

Look at how your code is displayed in the forum.

You didn’t use code tags to post your code. It’s important that you use them - if you don’t, the forum software sometimes interprets sequences of characters in the code as directives to format text in some way. It won’t display those sequences, and it will unexpectedly reformat the rest of the text. When that happens, and someone tries to copy your code and paste it into the IDE, it often throws an error, and readers will complain that the code fails to compile. Using code tags also makes it easier to read, and can be copied with a single mouse click.

Unless the sketch is too large, it’s better if you post your code, rather than attach it. When it’s attached, we have to download it, open it in a text editor, then copy it to the IDE. It’s much easier to just view the code in your post.

The code tags make the code look

like this

when posting source code files.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower left corner of the message. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the [code] and [/code] metatags.

When you are finished that, please read this post:

How to use this forum - please read.

hyperinfinite:
I am using two Arduino Boards

First one connected to my pc
second one, I have mounted on a gate with an Ultrasonic Sensor such that I open the gate, I receive the real time opened distance from second to the first

To make it easier for people to help you please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

You have not said how much lag there is in your system. Your use of delay(300) might have a lot to do with it. The pulseIn() function can also cause a delay.

Have you tried the examples in my tutorial to satisfy yourself that the nRF24s are not the problem?

What version of the RF24 library are your using?

…R

I am using two nRF24l01 transceiver modules,
My applications are

  1. To read data from ultrasonic sensor and transmit ( Transmiter nRF)
  2. To collect the information in my pc ( Receiver nRF)

Am facing lags and sometimes it the receiver does not read at all
So, What could be the problem?

Transmitter Code below:

#include <SPI.h>

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>


RF24 radio(7, 8);

const uint64_t pipes[] = { 0xF0F0F0F0A1, 0xF0F0F0F0B1 };
int trig = 3;
int echo = 4;
int distance;
long value;
//unsigned char UDM_Data[100];
void setup() {
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);
  Serial.begin(9600);
  value = 0;
  radio.begin();
  radio.openWritingPipe(pipes[1]); // 00001
  radio.openReadingPipe(1, pipes[0]); // 00002
  radio.stopListening();
}

void loop() {
  char UDM_Data[100] = {0};
  digitalWrite(trig,HIGH);
  delayMicroseconds(10);
  digitalWrite(trig,LOW);
  //pinMode(echo,INPUT);
  value = pulseIn(echo,HIGH);
  distance = value/58;
  //if(distance > 5)
  {
    sprintf(UDM_Data, "RESP_OPENED_DIST_OF : %d", distance);
    radio.write(&UDM_Data, sizeof(UDM_Data));
  }
  delay(300);
}

Coming to the receiver code

#include <SPI.h>

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>


RF24 radio(7, 8);

const uint64_t pipes[] = { 0xF0F0F0F0A1, 0xF0F0F0F0B1 };

void setup()
{
  Serial.begin(9600);
  radio.begin();                           // Setup and configure rf radio
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);
  radio.startListening();                 // Start listening
}


void loop() {
  char rcd_data[100] = {0};
  if(radio.available())
  {
    radio.read(&rcd_data, sizeof(rcd_data));
    Serial.write(rcd_data);               //    Serial.println(rcd_data);
  }
  delay(150);
}

You seem to be trying to send 100 bytes with a transceiver that sends 32 byte messages ? ? ?

There is no value in sending all this text "RESP_OPENED_DIST_OF :". You can add that at the receiving end. Just send the number as an int (2 bytes).

Don't have any delay() in the receiving code. It should be listening and checking all the time.

Have you tried any of the examples in my tutorial?

...R

Will a wemos d1 mini solve my problem?
and Where can I see your tutorials?

hyperinfinite:
Will a wemos d1 mini solve my problem?
and Where can I see your tutorials?

In the link at the bottom of Reply #2

...R