I'm sending data from an nfr24l01 to another nfr24l01. But I would like to check the transmitted data to see if it matches a value on the receiving arduino. If it matches I would like to turn on a motor. I tried an if statement but it won't transmit.
Thanks everyone.
Transmitter Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop () {
delay(1000);
char text[] = "Good";
radio.write(&text, sizeof(text));
delay(1000);
Receiver Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <VirtualWire.h>
RF24 radio(7, 8);
const byte address[6] = "00001";
void setup () {
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(9, OUTPUT);
analogWrite(9, 0);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[] = "";
radio.read(&text, sizeof(text));
char c = text;
if (c = "Good") {
Serial.println(text);
digitalWrite(2, HIGH);
digitalWrite(4, LOW);
analogWrite(9, 200);
delay(5000);
digitalWrite(2, LOW);
digitalWrite(4, HIGH);
analogWrite(9, 200);
delay(1000);
}
else {
analogWrite(9, 0);
}
}
}