nrf24l01 receiver

Hi

My project is to send data from transmitter to receiver every 4 seconds.

i want to make receiver to check the previous and present message and make led on and off.

For example transmitter data is send to turn on led in first 4 seconds now receiver should wait for second message if both messages are same the led should turn on else it should go off.

can someone please tell me what changes i should make in the code

#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
#include <SPI.h>
#include "RF24.h"

// The pin of the tilt LED


#define LED_TILT      3


// The pin of the voltage LED
#define LED_VOLTAGE   4
// The low battery level multiplied by 100 (eg 3v is 300, 2.4v is 240).
#define LOW_BATTERY   230

struct DataPacket {
  int voltage;
  bool tilt;
};

const uint64_t talking_pipes[2] = { 0xF0F0F0F0D3LL, 0xF0F0F0F0C4LL };
const uint64_t listening_pipes[2] = { 0x3A3A3A3AD3LL, 0x3A3A3A3AC4LL };

DataPacket data[2];
unsigned long lastMilis[2];

RF24 radio(7, 8);

// Set watchdog to trigger every 8 sec.
void watchdogSetup(void)
{
  wdt_reset();
  
  WDTCSR = bit (WDCE) | bit (WDE);
  // Set Watchdog settings:
  WDTCSR = bit (WDCE) | bit (WDE) | bit (WDIE) | bit (WDP3) | bit (WDP0);    // set WDIE, and 8 seconds delay
}

void setup()
{
  Serial.begin(9600);

  // Setup the pin direction.
  pinMode(LED_TILT, OUTPUT);

  pinMode(LED_VOLTAGE, OUTPUT);

  radio.begin();

  // set power level of the radio
  radio.setPALevel(RF24_PA_MAX);
  // set RF datarate
  radio.setDataRate(RF24_250KBPS);

  radio.setChannel(0x50);

  radio.openReadingPipe(1, talking_pipes[0]);
  radio.openReadingPipe(2, talking_pipes[1]);

  radio.startListening();

  data[0].voltage = 500;
  data[0].tilt = 1;

  data[1].voltage = 500;
  data[1].tilt = 1;

  lastMilis[0] = 0;
  lastMilis[1] = 0;

  Serial.println("Initialisation complete.");
}

unsigned long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)


void loop()
{

  uint8_t pipe_num;
  if ( radio.available(&pipe_num) )

  {
    // Dump the payloads until we've gotten everything
    unsigned long got_time;
    bool done = false;
    //    while (!done)
    //    {
    Serial.println(pipe_num, DEC);
    // Fetch the payload, and see if this was the last one.
    //DataPacket data2;
    radio.read(&data[pipe_num - 1], sizeof(DataPacket) );
    //done = radio.read(&(data[0]), sizeof(DataPacket) );

    lastMilis[pipe_num - 1] = millis();
    Serial.println(data[pipe_num - 1].voltage, DEC);
    Serial.println(data[pipe_num - 1].tilt, DEC);

    // Spew it
    //printf("Got payload %lu from node %i...",got_time,pipe_num+1);
    //    }

    // First, stop listening so we can talk
    radio.stopListening();

    // Open the correct pipe for writing
    radio.openWritingPipe(listening_pipes[pipe_num - 1]);

    // Retain the low 2 bytes to identify the pipe for the spew
    //uint16_t pipe_id = listening_pipes[pipe_num-1] & 0xffff;

    // Send the final one back.
    radio.write( &got_time, sizeof(unsigned long) );
    //printf("Sent response to %04x.\n\r",pipe_id);
    printf("Sent response to %04x.\n\r", pipe_num);

    // Now, resume listening so we catch the next packets.
    radio.startListening();
  }

  unsigned long currentMillis = millis();

  if (currentMillis > (lastMilis[0] + 20000)) {
    data[0].tilt = true;
    data[0].voltage = 0;
  }
  if (currentMillis > (lastMilis[1] + 20000)) {
    data[1].tilt = true;
    data[1].voltage = 0;
  }
if ((!data[0].tilt))
   
  {//when we receive signal
    
  digitalWrite(LED_TILT, HIGH);

 }
  else
  {
  
  digitalWrite(LED_TILT, LOW);
  
  }

 
  // Check if both devices have good battery.
  if ((data[0].voltage >= LOW_BATTERY))
    digitalWrite(LED_VOLTAGE, LOW);
  else
 //    
    // Check if both devices have LOW battery.
    if ((data[0].voltage < LOW_BATTERY) )
      digitalWrite(LED_VOLTAGE, HIGH);
    else {

      digitalWrite(LED_VOLTAGE, LOW);
    }
}

bmg1234: can someone please tell me what changes i should make in the code

First of all, please describe what that program actually does.

Is it a program you have written yourself? If not post a link to where it comes from.

Also, you need to post both the Tx and the Rx programs.

Why is all that sleep stuff in the program and what is it intended to achieve?

...R Simple nRF24L01+ Tutorial

Robin2: First of all, please describe what that program actually does.

Is it a program you have written yourself? If not post a link to where it comes from.

Also, you need to post both the Tx and the Rx programs.

Why is all that sleep stuff in the program and what is it intended to achieve?

...R Simple nRF24L01+ Tutorial

Hello Robin

Project is transmitter sends the data to receiver every 4 seconds. at receiver side device should compare the previous message and present message. if both are same then device should go to the send step.

for example in one message transmitter sends message to make receiver led high. now receiver should wait for another message which we get in next 4 seconds to confirm the previous message if both are same then the led should go on. same with with the led off.

transmitter code

please find the attachment

adxltransmiterfinaltested.ino (9.14 KB)

bmg1234: Hello Robin

Project is transmitter ...

Please answer the first two questions in Reply #1

...R