Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //circuit for NRF24L01
- //MISO - 12
- //SCK - 13
- //CE - 7
- //CSN - 8
- //MOSI - 11
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- RF24 radio(7, 8); // CE, CSN
- const byte address[6] = "00001";
- boolean button_state = 0;
- int led_pin = 3;
- void setup() {
- pinMode(led_pin, OUTPUT);
- Serial.begin(9600);
- radio.begin();
- radio.openReadingPipe(0, address); //Setting the address at which we will receive the data
- radio.setPALevel(RF24_PA_MIN); //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
- radio.startListening(); //This sets the module as receiver
- }
- void loop()
- {
- if (radio.available()) //Looking for the data.
- {
- char text[32] = ""; //Saving the incoming data
- radio.read(&text, sizeof(text)); //Reading the data
- radio.read(&button_state, sizeof(button_state)); //Reading the data
- if(button_state == HIGH)
- {
- digitalWrite(led_pin, HIGH);
- Serial.println(text);
- }
- else
- {
- digitalWrite(led_pin, LOW);
- Serial.println(text);}
- }
- delay(5);
- }
Advertisement
Add Comment
Please, Sign In to add comment