Arduino NRF24L01 Tutorial Download Page 5

Receiver Code

1./*
2.* Arduino Wireless Communication Tutorial
3.* Example 1 - Receiver Code
4.* 
5.* by Dejan Nedelkovski, www.HowToMechatronics.com
6.* 
7.* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
8.*/
9.#include <SPI.h>
10.#include <nRF24L01.h>
11.#include <RF24.h>
12.RF24 radio(7, 8); // CE, CSN
13.const byte address[6] = "00001";
14.void setup() {
15.Serial.begin(9600);
16.radio.begin();
17.radio.openReadingPipe(0, address);
18.radio.setPALevel(RF24_PA_MIN);
19.radio.startListening();
20.}
21.void loop() {
22.if (radio.available()) {
23.char text[32] = "";
24.radio.read(&text, sizeof(text));
25.Serial.println(text);
26.}
27.}

Summary of Contents for NRF24L01

Page 1: ...le Hello World message from one Arduino to another and in the second example we will have a bi directional communication between the Arduino boards where using the Joystick at the first Arduino we wil...

Page 2: ...ch unit can communicate with up to 6 other units at the same time The power consumption of this module is just around 12mA during transmission which is even lower than a single LED The operating volta...

Page 3: ...used for setting the module in standby or active mode as well as for switching between transmit or command mode The last pin is an interrupt pin which doesn t have to be used So once we connect the NR...

Page 4: ...al 3 Example 1 Transmitter Code 4 5 by Dejan Nedelkovski www HowToMechatronics com 6 7 Library TMRh20 RF24 https github com tmrh20 RF24 8 9 include SPI h 10 include nRF24L01 h 11 include RF24 h 12 RF2...

Page 5: ...rh20 RF24 8 9 include SPI h 10 include nRF24L01 h 11 include RF24 h 12 RF24 radio 7 8 CE CSN 13 const byte address 6 00001 14 void setup 15 Serial begin 9600 16 radio begin 17 radio openReadingPipe 0...

Page 6: ...t the same address and in that way we enable the communication between the two modules 1 radio openReadingPipe 0 address Then using the radio setPALevel function we set the Power Amplifier level in ou...

Page 7: ...ments called text in which we will save the incoming data 1 void loop 2 if radio available 3 char text 32 4 radio read text sizeof text 5 Serial println text 6 7 Using the radion read function we read...

Page 8: ...Joystick Module Amazon Arduino Board Amazon Servo Motor Amazon Pushbutton Amazon LED Amazon...

Page 9: ...addresses 6 00001 00002 15 boolean buttonState 0 16 void setup 17 pinMode 12 OUTPUT 18 radio begin 19 radio openWritingPipe addresses 1 00001 20 radio openReadingPipe 1 addresses 0 00002 21 radio setP...

Page 10: ...1 00002 16 Servo myServo 17 boolean buttonState 0 18 void setup 19 pinMode button INPUT 20 myServo attach 5 21 radio begin 22 radio openWritingPipe addresses 0 00002 23 radio openReadingPipe 1 address...

Page 11: ...d the data to the receiver 1 radio stopListening 2 int potValue analogRead A0 3 int angleValue map potValue 0 1023 0 180 4 radio write angleValue sizeof angleValue On the other side using the radio st...

Page 12: ...but some talented people have written Arduino libraries that make them easy to us They all use the same pinout as shown in the following diagram which is a TOP VIEW Correction Here are details of the...

Page 13: ...o 3 3V not 5 0V although the Arduino itself may run at 5 0V and the signals will be OK The NRF24L01 IC is a 3 3V device but its I O pins are 5 V tolerant which makes it easier to interface to Arduino...

Page 14: ......

Reviews: