Currently trying to finish a project for my university class, and I can't get the signals to send properly from my nRF24L01 transceivers. I'm trying to send a character through the transceiver that will tell a motor what to on the other end. I've been trying to get this to work for a week to no avail. Right now just for simplicity's sake, the code is supposed to change an LED, not worried about the motor just yet. This is my first time posting to the arduino forums so if I did anything wrong in the post let me know too.
Transmitter code:
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//create an RF24 object
RF24 radio(9, 8); // CE, CSN
//address through which two modules communicate.
const byte address = 00001;
void setup()
{
radio.begin();
Serial.begin(9600);
//set the address
radio.openWritingPipe(address);
//Set module as transmitter
radio.stopListening();
}
void loop()
{
//Send message to receiver
char text = '0';
radio.write(text, 1);
Serial.println(text);
delay(1000);
text = '1';
radio.write(text, 1);
Serial.println(text);
delay(1000);
}
Receiver code:
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int LED_pin= 2;
//create an RF24 object
RF24 radio(9, 8); // CE, CSN
//address through which two modules communicate.
const byte address = 00001;
void setup()
{
while (!Serial);
Serial.begin(9600);
radio.begin();
//set the address
radio.openReadingPipe(0, address);
//Set module as receiver
radio.startListening();
pinMode(LED_pin, OUTPUT);
}
void loop()
{
//Read the data if available in buffer
if (radio.available())
{
char text='0';
radio.read(text,1);
Serial.println(text);
if (text=='1')
{ digitalWrite(LED_pin, HIGH);
}
else{
digitalWrite(LED_pin, LOW);
}