1

Using the nrf24l01 wireless module I want to control a led with the sketch below. The transmitter automatically sends data at intervals of one second continuously and when the receiver counter reaches 2, it turns on the LED at the desired time and then turns it off. but what I want is when I turn off the power of the transmitter when 2 counts are detected from the transmitter, the led does not light up.

I want to turn the led on and off when I turn off the power of the transmitter after sending 2 signals from the transmitter.

Thank you for all the information you provide.

#include "nRF24L01.h" 
#include "RF24.h"
#include "SPI.h"
int ReceivedMessage[1] = {000}; // NRF24L01 tarafından alınan değeri saklamak için kullanılır
RF24 radio(3, 4); // NRF24L01 SPI pimleri. uno'daki Pin 8 ve 9
const uint64_t pipe = 0xE6E6E6E6E6E6; // 2 NRF24L01 arasındaki iletişim için aynı olması gerekir
int led = A7;
bool flag = false;
bool ledflag = false;
unsigned long previous1 = 0;
unsigned long interval1 = 5000;
unsigned long previous2 = 0;
unsigned long interval2 = 2000;
int button1PushCounter = 0;
void setup () {
 radio.begin(); // NRF24L01'i başlatın
 radio.openReadingPipe(1, pipe); // NRF24L01'i almaya hazır hale getirin
 radio.startListening(); // Bilginin alınıp alınmadığını görmek için dinleyin
 Serial.begin(9600);
 pinMode(led, OUTPUT);
}
void loop () {
 unsigned long currentmillis = millis();
 while (radio.available())
 {
 radio.read(ReceivedMessage, 1); // NRF24L01'den bilgileri okuyun
 if (ReceivedMessage [0] == 111) // switch'e basıldığını gösterir
 {
 button1PushCounter++;
 Serial.println( button1PushCounter);
 delay(700);
 }
 if ( button1PushCounter == 2) {
 flag = true;
 previous1 = currentmillis;
 }
 if ( flag ) {
 if (currentmillis - previous1 >= interval1 ) {
 digitalWrite(led, HIGH);
 ledflag = true;
 previous2 = currentmillis;
 flag = false;
 button1PushCounter = 0;
 }
 }
 if ( ledflag && (currentmillis - previous2 >= interval2 )) {
 digitalWrite(led, LOW);
 ledflag = false;
 }
 }
}
asked Sep 23, 2021 at 15:26
11
  • what problem are you seeing? Commented Sep 23, 2021 at 15:31
  • @ -jsotola when i turn off the power of the transmitter, the receiver does not light the led with the detecting data Commented Sep 23, 2021 at 15:50
  • it seems to me that you used a lot of words to ask how to detect when a transmitter is turned off? Commented Sep 23, 2021 at 15:52
  • This is what happens when the problem is not knowing the language Commented Sep 23, 2021 at 16:09
  • 1
    I don't know how to do it with watchdog unfortunately Commented Sep 24, 2021 at 0:51

1 Answer 1

1

I found solution as below:-

if ( button1PushCounter == 3 ) {
 for (int i = 0; i < 5; i++)
 {
 delay(1000);
 Serial.println(i);
 a = HIGH;
 }
}
if ( a == HIGH ) {
 digitalWrite(led, HIGH);
 delay(1000);
 digitalWrite(led, LOW);
 a = LOW;
 button1PushCounter = 0;
}
Coder9390
5121 gold badge7 silver badges25 bronze badges
answered Sep 24, 2021 at 12:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.