Arduino NRF24L01 Tutorial page 9

Wireless communication transceiver module
Table of Contents

Advertisement

Source codes : Here are the two codes and below is the description of them.
Transmitter Code
1./*
2.* Arduino Wireless Communication Tutorial
3.* Example 2 - 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.#define led 12
13.RF24 radio(7, 8); // CE, CSN
14.const byte 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.setPALevel(RF24_PA_MIN);
22.}
23.void loop() {
24.delay(5);
25.radio.stopListening();
26.int potValue = analogRead(A0);
27.int angleValue = map(potValue, 0, 1023, 0, 180);
28.radio.write(&angleValue, sizeof(angleValue));
29.delay(5);
30.radio.startListening();
31.while (!radio.available());
32.radio.read(&buttonState, sizeof(buttonState));
33.if (buttonState == HIGH) {
34.digitalWrite(led, HIGH);
35.}
36.else {
37.digitalWrite(led, LOW);
38.}
39.}

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the NRF24L01 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents