![]()
thanks for you
because of you I can finish also NRF2401L + HCSR04.
code for your connections are correct and the data sent . but the code for your ultrasonic sensors are still wrong . so the distance is sent is " 0 " . for that I perfected using the library NewPing and it worked.
TRANSMITTER
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <NewPing.h>
#define TRIGGER_PIN 6
#define ECHO_PIN 5
#define MAX_DISTANCE 200
int rate;
long previousMillis = 0;
long interval = 1000;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup(){
 Serial.begin(9600);
Â
 Mirf.cePin = 8;
 Mirf.csnPin = 7;
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();
Â
 Mirf.channel = 0;
 Mirf.payload = sizeof(rate);
 Mirf.config();
Â
 Mirf.setTADDR((byte *)"nrf01"); // Le 2eme module va envoyer ses info au 1er module
 Mirf.setRADDR((byte *)"nrf02");
}
void loop(){
 unsigned long currentMillis = millis();
 if(currentMillis - previousMillis > interval)
 previousMillis = currentMillis;
Â
  rate = sonar.ping_cm();
  Serial.print(rate);
  delay (100) ;
 Â
  Mirf.send((byte *) &rate);
  while(Mirf.isSending()){
  }
 }
RECEIVER
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include <SPI.h>
int rate;
void setup(){
 Serial.begin(9600);
 Mirf.cePin = 8;
 Mirf.csnPin = 7;
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();
Â
 Mirf.channel = 0;
 Mirf.payload = sizeof(rate);
 Mirf.config();
Â
 Mirf.setTADDR((byte *)"nrf02");
 Mirf.setRADDR((byte *)"nrf01");
}
void loop(){
 while(!Mirf.dataReady()){
 }
 Mirf.getData((byte *) &rate);
 Serial.print("range of the distance");
 Serial.print(rate);
 Serial.println("cm");
 delay(100);
}
thank you very much!