Thursday 16 December 2021

nrf24L01 data receive and compare with string

 #include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>


//create an RF24 object

RF24 radio(14, 33);  // CE, CSN


String out, chk="welcome" , red="red" , yellow="yellow";

//address through which two modules communicate.

const byte address[6] = "00001";

const char text2[] = "Hello World";

void setup()

{

  while (!Serial);

    Serial.begin(9600);

  

  radio.begin();

  

  //set the address

  radio.openReadingPipe(0, address);

  

  //Set module as receiver

  radio.startListening();

}


void loop()

{

  //Read the data if available in buffer

  if (radio.available())

  {

    char text[32] = {0};

    radio.read(&text, sizeof(text));

   

    Serial.println(text);

    out=String(text);

    if(out==chk){Serial.println("equal");}

    if(out==red){Serial.println("red colour");}

    if(out==yellow){Serial.println("yellow");}

  }

}

No comments:

Post a Comment

Storing the long number(16bits / 32bits) in external flash of arduino or STM32 .

 #include <Wire.h> #define flashaddress 0x50 int liters = 10058 , add1=10 , add2,time1=55; // value of liters save in flash byte data ...