I have a program written for a little garage security system I am making. I can get the radio's to talk using the getting started example, but not with my code. So I'm trying to take just a small section and get it to work...to no avail. I have two Nano Every's. One is transmitting. It has a switch, two wires. One to (-) and the other to pin D3. It's using the built in pullup resistor. When I open the switch, it should go high and start transmitting. It will also let me know via the serial monitor that the switch is working correctly. I have verified it does. It goes from 0 to 1 when I open the switch. Here is that code:
#include <Arduino.h>
#include <SPI.h>
#include <RF24.h>
const int sensorLowpin = 3; // garage door sensor near floor
int LowSensorStatus = 0;
// create an RF24 object
RF24 radio(14, 15); // CE, CSN
// address through which two modules communicate.
byte address[][6] = {"00001", "00002"};
void setup() {
Serial.begin(115200);
radio.begin(); // set radio to receive
radio.setPALevel(RF24_PA_MIN); // radio.setDataRate(RF24_1MBPS);
// set the address
radio.openWritingPipe(address[1]); // writing on 00002
radio.openReadingPipe(0, address[0]); // reading on 00001
// radio.stopListening(); // Set module as transmitter..disabled because NRFL01 radios are not full duplex and must both remain in receive unless they want to transmit
radio.startListening();
pinMode(sensorLowpin, INPUT_PULLUP); // pin d3 for sensor attached to door pulled up to +3.3V
}
void loop() {
if (sensorLowpin == HIGH)
{radio.stopListening();
delay(100);
const char Payload[] = "Payload";
radio.write(&Payload, sizeof(Payload));
delay(1000);
radio.startListening();
}
LowSensorStatus = digitalRead(sensorLowpin);
Serial.print(LowSensorStatus);
delay(1000);
}
The radio that is receiving should just turn on an LED when it gets the signal. The LED turns on for a half second at startup to make sure it works. It turns on. So I know it works. Here is it's code:
// Include Libraries
#include <Arduino.h>
#include <SPI.h>
#include <RF24.h>
// create an RF24 object
RF24 radio(14, 15); // CE, CSN
// address through which two modules communicate.
byte address[][6] = {"00001", "00002"};
const int DoorLEDPin = 5;
void setup()
{
Serial.begin(115200);
radio.begin();
radio.setPALevel(RF24_PA_MIN);
// set the address
radio.openWritingPipe(address[0]);
radio.openReadingPipe(0, address[1]);
// Set module as receiver
radio.startListening();
pinMode(DoorLEDPin, OUTPUT);
digitalWrite(DoorLEDPin, HIGH);
delay(500);
digitalWrite(DoorLEDPin, LOW);
}
void loop() {
if (radio.available())
{
char Payload[32];
radio.read(&Payload, sizeof(Payload));
if (strcmp(Payload, "Payload") == 0)
{
digitalWrite(DoorLEDPin, HIGH); /
delay(100);
}
}
}
Keep in mind, I copy and pasted just a small section of code from the larger program. My aim is to test each sensor and switch independently and find what's wrong. But the first switch I tested doesn't work. Can you see what's wrong with my code?