Devices & Components
Arduino Uno Rev3
SparkFun Transceiver Breakout - nRF24L01+
Switch Actuator, Head for spring return push-button
9V battery (generic)
Software & Tools
Arduino IDE
Project description
Code
Arduino Receiver
arduino
1#include <SPI.h> 2#include <nRF24L01.h> 3#include <RF24.h> 4 5RF24 radio(7,8); 6int LED1 = 3; 7const int buzzer = 2; 8const byte address[6] = "00001"; 9int msg[1]; 10 11void setup() { 12 // put your setup code here, to run once: 13 pinMode(buzzer, OUTPUT); 14 Serial.begin(115200); 15 delay(1000); 16 radio.begin(); 17 radio.openReadingPipe(0,address); 18 radio.setPALevel(RF24_PA_MAX); 19 radio.setDataRate(RF24_250KBPS); 20 radio.startListening(); 21 pinMode(LED1, OUTPUT); 22} 23 24void loop() { 25 26 27 if (radio.available()) { 28 radio.read(msg, 1); 29 String transData = String(msg[0]); 30 Serial.print(transData); 31 if (transData == "1") { 32 digitalWrite(LED1, HIGH); 33 } else if (transData == "0") { 34 digitalWrite(LED1, LOW); 35 } 36 } else { 37// Serial.print("\ 38 Radio not available"); 39 } 40} 41
Arduino Receiver
arduino
1#include <SPI.h> 2#include <nRF24L01.h> 3#include <RF24.h> 4 5RF24 6 radio(7,8); 7int LED1 = 3; 8const int buzzer = 2; 9const byte address[6] = 10 "00001"; 11int msg[1]; 12 13void setup() { 14 // put your setup code here, 15 to run once: 16 pinMode(buzzer, OUTPUT); 17 Serial.begin(115200); 18 delay(1000); 19 20 radio.begin(); 21 radio.openReadingPipe(0,address); 22 radio.setPALevel(RF24_PA_MAX); 23 24 radio.setDataRate(RF24_250KBPS); 25 radio.startListening(); 26 pinMode(LED1, 27 OUTPUT); 28} 29 30void loop() { 31 32 33 if (radio.available()) { 34 35 radio.read(msg, 1); 36 String transData = String(msg[0]); 37 Serial.print(transData); 38 39 if (transData == "1") { 40 digitalWrite(LED1, HIGH); 41 } else 42 if (transData == "0") { 43 digitalWrite(LED1, LOW); 44 } 45 } 46 else { 47// Serial.print("\ 48 Radio not available"); 49 } 50} 51
Arduino Transmitter
arduino
1#include <SPI.h> 2#include <nRF24L01.h> 3#include <RF24.h> 4 5RF24 radio(7,8); 6 7const byte address[6] = "00001"; 8int buttonPIN = 3; 9int pVal = 1; 10int msg[1]; 11 12void setup() { 13 Serial.begin(115200); 14 pinMode(buttonPIN, INPUT); 15 delay(1000); 16 17 radio.begin(); 18 radio.openWritingPipe(address); 19 radio.setPALevel(RF24_PA_MAX); 20 radio.setDataRate(RF24_250KBPS); 21 radio.stopListening(); 22} 23 24void loop() { 25 int val = digitalRead(buttonPIN); 26 if (val != pVal) { 27 msg[0] = val ? 1 : 0; 28 radio.write(msg, 1); 29 Serial.println("data sent---"); 30 Serial.println(val); 31 pVal = val; 32 } 33 34// const char text[] = "nrftest"; 35// radio.write(&text, sizeof(text)); 36 37// delay(200); 38} 39
Downloadable files
Arduino Transmitter and receiver
Arduino Transmitter and receiver

Arduino Transmitter and receiver
Arduino Transmitter and receiver

Comments
Only logged in users can leave comments