EasyManua.ls Logo

Arduino NRF24L01

Arduino NRF24L01
14 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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.}

Related product manuals