Can someone please tell me what's wrong

my NRF24l01 wont work when i press a button, for transmitter i use uno, for reciever i use nano

transmitter

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

RF24 radio(5,3);

const byte address[6] = "00002";

void setup() {
  // put your setup code here, to run once:
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_HIGH);
  radio.stopListening();
  pinMode(7,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(7) == HIGH)
  {
    int code = 1;
    radio.write(&code, sizeof(code));
  }
}

reciever

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

RF24 radio(3,5);

const byte address[6] = "00002";

void setup() {
  // put your setup code here, to run once:
  radio.begin();
  radio.openReadingPipe(0,address);
  radio.setPALevel(RF24_PA_HIGH);
  pinMode(6,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  radio.startListening();
  
  if(radio.available())
  {
    int code;
    radio.read(&code, sizeof(kode));

    if(code == 1)
    {
      digitalWrite(6,HIGH);
    }
  }
}

Does it give you an error for that line? Look carefully at what you wrote.

If that's not it then please describe what you mean by "not working". What do you expect to see? What actually happens?

/home/me/Documents/sketchbook/Uno_R3/test/test.ino: In function 'void loop()':
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:24:30: error: 'kode' was not declared in this scope
     radio.read(&code, sizeof(kode));
                              ^~~~
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:24:30: note: suggested alternative: 'code'
     radio.read(&code, sizeof(kode));
                              ^~~~
                              code

The error in your receiver code seems quite straight forward. Have you tried the compiler's suggested fix?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.