nRF24L01 Program Question

I have been trying for hours to create the correct code and cannot figure out how.
I am successfully transmitting servo position and successfully control an servo. What I want to do is be able to turn off the servo with a relay when they is no RF being received. I have been experimenting with just the onboard led to simulate the control of a relay.

What code do I add to simply turn on a LED when there is no data being received?

Thanks in advance for the help,
Tim

the key part of the question is

when they is no RF being received

do you have some sort of time out in mind? is the sender always sending something (like a heartbeat)?

Forgot the code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(7,8); // CE, CSN
const byte address[6] = "00001";
Servo myServo;
int servo;
void setup() {
myServo.attach(5);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
}
void loop() {
if (radio.available()) {
//while (radio.available()) {
int angleV = 0;
radio.read(&angleV, sizeof(angleV));
myServo.write(angleV);
Serial.println(angleV );
}
}

Forgot the code

forgot also the code tags...Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)


so you did not answer how you'll decide that no message is being received? is it OK to turn on a LED 1 microsecond after you received a message since there is no new message? or may be it's better to say "if I did not receive a message for 10 seconds, then turn on the LED"? --> millis() will help you solve that

Just learning this forum. Thanks tips for the how to enter the code.

I like "if I did not receive a message for 10 seconds, then turn on the LED"? --> millis() will help you solve that.
I am not familiar with millis() where would this go and how do I set this up?
//code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
Servo myServo;
int servo;
void setup() {
myServo.attach(5);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
}
void loop() {
if (radio.available()) {
//while (radio.available()) {
int angleV = 0;
radio.read(&angleV, sizeof(angleV));
myServo.write(angleV);
Serial.println(angleV );
}
}

I have never been able to get a radio to work using the smiley face pin for CSN.

Code tags prevent the forum software from interpreting text as HTML tags. Use code tags.

When you receive a message, record the value of millis(). Put a test in loop() that will print a message if the value of current millis minus the recorded millis is over 10000.
millis() tutorials
Several things at a time.
Beginner's guide to millis().
Blink without delay().

Save the value of millis() each time you receive a message successfully
Each time through loop() check whether the current value of millis() minus the save value is greater than 10 seconds. If so, then you have not received a message for 10 seconds so take any necessary action

See millis() - Arduino Reference

Thanks tips for the how to enter the code

it would have been great to use the tip...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.