SEND ANALOG DATA BY RF24

Analog data RF24 tr

//TRANSMITTER

#include <SPI.h>

#include “nRF24L01.h”

#include “RF24.h”

RF24 radio(8,7);

void setupRadio()

{

// Initiate the radio

radio.begin();

// Define the number of retries sending a packet

radio.setRetries(15,15);

// Define the radio’s broadcast channel (0 – 127)

radio.setChannel(30);

// Define the radio’s bitrate (using cards lowest bitrate)

radio.setDataRate(RF24_250KBPS);

// Define the radio’s power amplifier level (RF24_PA_MIN for debugging, RF24_PA_HIGH for longest range)

radio.setPALevel(RF24_PA_MIN);

// Enable dynamic payloads for packets

radio.enableDynamicPayloads();

}

void setup()

{

setupRadio();

}

void loop()

{

int temperature = analogRead(A0);

// Open a writing pipe on the radio

radio.openWritingPipe(0xE8E8F0F0E1LL);

// Write the temperature to the pipe

radio.write(&temperature, sizeof(int));

}

Analog data RF24 rcv

//RECEIVER

#include <SPI.h>

#include “nRF24L01.h”

#include “RF24.h”

// — Global variables —

RF24 radio(8,7);

//int packetCounter = 0;

// — Functions —

void setupRadio()

{

// Initiate the radio

radio.begin();

// Define the number of retries sending a packet

radio.setRetries(15,15);

// Define the radio’s broadcast channel (0 – 127)

// Must be the same on the sensor and the master node

radio.setChannel(30);

// Define the radio’s bitrate (using cards lowest bitrate)

radio.setDataRate(RF24_250KBPS);

// Define the radio’s power amplifier level (RF24_PA_MIN for debugging, RF24_PA_HIGH for longest range)

radio.setPALevel(RF24_PA_MIN);

// Enable dynamic payloads for packets

radio.enableDynamicPayloads();

// Open reading pipe

radio.openReadingPipe(1, 0xE8E8F0F0E1LL);

// Start listening for packets

radio.startListening();

}

void setup()

{

// Initiate serial connection

Serial.begin(9600);

// RF Radio setup

setupRadio();

}

void loop()

{

// Check if the radio has received any data

if(radio.available()) {

int temperature = 0;

// Read the packet received into the temperature variable

if(!radio.read(&temperature, sizeof(int))) {

// The sensor did not receive the ACK packet

Serial.println(“ACK not received by client.”);

}

// Print the temperature

Serial.println(temperature);

// Wait for serial print to complete

//delay(100);

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s