I would like to know if it is possible to wake up the Arduino (in this case Nano or One) when it receives a signal by the transceiver. And if it is possible what code could I use?
Currently I have built a code so that, if the receiver does not receive a signal in 10 seconds, it falls asleep. However, I can not find a code to wake him up when he receives a signal again.
To sleep the Arduino I use the libraries <avr / power.h> and <avr / sleep.h> with the void that I will place next.
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_SAVE); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register
// so sleep is possible. just a safety pin
power_adc_disable();
power_spi_disable();
power_timer0_disable();
power_timer1_disable();
power_timer2_disable();
power_twi_disable();
sleep_mode(); // here the device is actually put to sleep!!
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable(); // first thing after waking from sleep:
// disable sleep...
power_all_enable();
}
This is the conditional code with which I manage to make him fall asleep rather than wake him up. If anyone knows any way to wake him up as soon as he receives a signal from NRF24L01, I would be very grateful if he would share it with me.
if(radio.available())
{
count = 0;
int done = radio.read(msgR, 16);
Serial.println(msgR);
radio.stopListening(); // We stop listening to send an answer
radio.write(msgE,16);
}
else
{
Serial.println("Without Signal"");
count++;
delay(1000);
if (count >= 10)
{
Serial.println("Entering sleep mode");
count = 0;
sleepNow();
}
}