How to transmit and receive one character using nrf24l01?

I'm still a zero level beginner. And I'm trying to control my house lights via my android phone. To do that I'm using master-slave method with nrf24l01 and Arduino Uno. i read this forum Simple nRF24L01 and it helped me to do this so far. that was vey helpful. And thanks for that. However in here I'm trying to receive char from my android phone via Bluetooth (hc-05). And then the same char should forward to the particular node. The char from my android is receiving and I've tested it and its working(when without radio. codes). But the forwarding part is not working . Can anyone help me to identify the problem of this code and fix it?

I think the problem in receiving the char and storing and comparing part from the Node side. But I cannot find out.

Transmitter Code.()

const int pinCE = 9;
const int pinCSN = 10;
RF24 radio(pinCE, pinCSN);
const uint64_t pipe[3] = {0xE8E8F0F0E1LL,0xE8E8F0F0E2LL,0xE8E8F0F0E1LL}; //node addresses

void setup() {
pinMode(8, OUTPUT);
Serial.begin(9600);
radio.begin();
}

void loop() {

if(Serial.available()>0){

char data= Serial.read(); //store recieved charactor from bluetooth

switch(data)
{
case 'a': digitalWrite(8,HIGH);
radio.openWritingPipe(pipe[0]);
radio.write(data,sizeof(data)); //Send stored char to node1
delay(500);
break;

case 'b': digitalWrite(8,LOW);
radio.openWritingPipe(pipe[1]);
radio.write(data,sizeof(data)); //Send stored char to node2
delay(500);
break;

case 'c': digitalWrite(8,HIGH);
radio.openWritingPipe(pipe[2]);
radio.write(data,sizeof(data)); //Send stored char to node3
delay(500);
break;

default : break;
}

}
}

node 1 receiver:

const int pinCE = 9;
const int pinCSN = 10;
RF24 radio(pinCE, pinCSN);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void)
{
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}

void loop(void)
{
if (radio.available())
{
char data;

radio.read(data, sizeof data); //I think the problem is here and after
switch(data){

case 'a': digitalWrite(8,HIGH); //send the signal to relay module to control light
break;

case 'b': digitalWrite(8,LOW); //send the signal to relay module to control light
break;

default: break;
}
}
}

Thank you.

rangana1212:
I’m still a zero level beginner. And I’m trying to control my house lights via my android phone. To do that I’m using master-slave method with nrf24l01 and Arduino Uno. i read this forum Simple nRF24L01 and it helped me to do this so far. that was vey helpful. And thanks for that.

If you have the appropriate example from my Tutorial working why not extend that to send the data from your Android phone rather than starting over with a different program. It will be much easier to help with wireless code that I am familiar with.

…R

PS … When posting code please use the code button </>

so your code 
looks like this

It makes it much easier to help you.

Robin2:
If you have the appropriate example from my Tutorial working why not extend that to send the data from your Android phone rather than starting over with a different program. It will be much easier to help with wireless code that I am familiar with.

…R

PS … When posting code please use the code button </>

so your code 

looks like this



It makes it much easier to help you.

Sorry for that I didn’t know that code typing method. yeah I read your article but all of that examples sending and receiving char arrays. In here i just want to transmit a single character and compare it in the receiver board. And i just want one way transmission .

Transmitter Code.

const int pinCE = 9;
const int pinCSN = 10;
RF24 radio(pinCE, pinCSN);
const uint64_t pipe[3] = {0xE8E8F0F0E1LL,0xE8E8F0F0E2LL,0xE8E8F0F0E1LL};    //node addresses


void setup() {
    pinMode(8, OUTPUT);
    Serial.begin(9600);              
    radio.begin();
}

void loop() {
 
if(Serial.available()>0){  
 
     char data= Serial.read();   //store recieved charactor from bluetooth

     switch(data)
     {
       case 'a': digitalWrite(8,HIGH);            
                    radio.openWritingPipe(pipe[0]);  
                    radio.write(data,sizeof(data));   //Send stored char to node1
                    delay(500);
                    break;
       
       case 'b': digitalWrite(8,LOW);
                    radio.openWritingPipe(pipe[1]);  
                    radio.write(data,sizeof(data));   //Send stored char to node2
                    delay(500);
                    break;
                 
       case 'c': digitalWrite(8,HIGH);
                   radio.openWritingPipe(pipe[2]);
                   radio.write(data,sizeof(data));   //Send stored char to node3
                   delay(500);
                   break;
           
       default : break;
     }

  }
}

Receiver Node1 Code:

const int pinCE = 9;
const int pinCSN = 10;
RF24 radio(pinCE, pinCSN);
const uint64_t pipe = 0xE8E8F0F0E1LL;


void setup(void)
{
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}

void loop(void)
{
if (radio.available())
{  
   char data;

   radio.read(data, sizeof data);     //I think the problem is here and after
   switch(data){

     case 'a': digitalWrite(8,HIGH);    //send the signal to relay module to control light
                  break;
               
     case 'b': digitalWrite(8,LOW);    //send the signal to relay module to control light
               break;

     default: break;      
   }
}
}

i just want to transmit only one character(not char array) from one Arduino to another Arduino using nrf24l01. And receiver must be able to store that received char and use it inside a switch statement. How do i do that?

Receiver code:

if (radio.available())
{   char data;
    radio.read(data, sizeof data);
    switch(data){ 
    }

Transmitter Code:

      char data= 'a';          
      radio.openWritingPipe(pipe[1]);   
      radio.write(data,sizeof(data));

the function bool write(const void* buf, uint8_t len); expects a pointer to byte as its first parameter
therefore you pass the address of data, e.g.

   char data= 'a';         
      radio.openWritingPipe(pipe[1]);   
      radio.write(&data,sizeof(data));

similar with read()

Duplicate topics merged

rangana1212:
i just want to transmit only one character(not char array)

So send an array that just has one element. Or send an array with several elements and ignore all but the first one.

...R

What happens when you use your code in reply #3 ?