Hello,
after some days of researches in the forum without success, I would like to share the problem I am facing with this transceiver.
My project is about 2 nrf24l01+pa+lna. I use an arduino mega 2560 with the emitter and arduino nano with the receiver. What happens is that I need to light up a bulb that is located in the receiver.
For that, I use a relay. I did it properly but there is one case in which I need to blink the bulb with a period of 1 second (see the code please). When it happens, it only blinks three or four cycles and then it shuts off, so I need to restart both arduinos, it works and again the same problem appears.
If I remove the 220 vac bulb, I mean the relay without load, it works perfectly. The relay works 1 second closing its NO contact and 1 second closing it and so on. I was thinking that it could be any interference between the 220 vac bulb and the nrf24l01 but I am not sure.
Here is the code
Emitter
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
int datos[2]; // Array a transmitir
RF24 radio(9,53); // Creamos un objeto radio del tipo RF2$
const uint64_t pipe = 0xE8E8F0F0E1LL; // Usamos este canal
const int fci1 = 4;
const int fci2 = 26;
int pulsador = 46;
void setup(void)
{
pinMode(pulsador, INPUT_PULLUP);
radio.begin();
radio.setDataRate (RF24_1MBPS);
radio.setPALevel(RF24_PA_MIN);
radio.openWritingPipe(pipe);
delay(200);
} // Abrir para escribir
void loop(void)
{
if (digitalRead(pulsador)==LOW)
{
datos[0] = 0;
radio.write(&datos, sizeof(datos));
}
else if (digitalRead(fci1)==HIGH)
{
datos[0] = 1;
radio.write(&datos, sizeof(datos));
}
else if (digitalRead(fci2)==HIGH)
{
datos[0] = 2;
radio.write(&datos, sizeof(datos));
}
}
Receiver
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
int datos[2];
int bandera = 0;
int LED = 7;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
unsigned long tiempo;
void setup(void)
{
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
radio.begin();
radio.setDataRate (RF24_1MBPS);
radio.setPALevel(RF24_PA_MIN);
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop(void)
{
if (radio.available())
{
radio.read( &datos, sizeof(datos) ); // Get the data payload (You must have defined that already!)
if (datos[0] == 0) // TODO TRANQUILO
{
bandera = 0;
}
else if (datos[0] == 1) // PLATOS LLENOS
{
bandera = 1;
}
else if (datos[0] == 2) // NO HAY DULCES
{
bandera = 2;
}
}
else
{
if (bandera == 0)
{
digitalWrite(LED, LOW);
}
else if (bandera == 1) // PLATOS LLENOS
{
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}
else if (bandera == 2) // NO HAY DULCES
{
digitalWrite(LED, HIGH);
}
}
}
Look that I used "bandera" because when no message is detected, it will continue blinking the bulb. Also, I tried to use millis but my code did not work. Furthermore, the delay is outside the radio.available, so using delay is ok for me.
So, for now, I replaced the 220 vac bulb with a 24 vdc bulb that is commonly used in industry and it works properly. However, the problem is with the 220 vac bulb and I did not find a similar problem in the forum. That's why I am sharing this.
Thank you!