Hi, I'm trying to use an NRF24l01 transceiver to control a led and keep it on, so far I've managed to control the led with a push button but I have to keep pushing it to keep it on. So I'm trying to integrate the code to keep it on but I have no idea how to. I also want to control the LED with different brightness settings, I posted a topic about this earlier trying to use someone else's code but it only made it more difficult to understand
My code for the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//int msg[1];
int ReceivedMessage[1] = {000}; // Used to store value received by the NRF24L01
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.setPALevel (RF24_PA_MAX);
radio.setDataRate (RF24_250KBPS);
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);}
void loop(void){
while (radio.available()){
radio.read(ReceivedMessage, 1); // Read information from the NRF24L01
if (ReceivedMessage[0] == 111)
{delay(10);digitalWrite(LED1, LOW);}
else {digitalWrite(LED1, HIGH);}
delay(10);}}
//else{Serial.println("No radio available");}}
My code for the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define SwitchPin 7
int SentMessage[1] = {000}; // Used to store value before being sent through the NRF24L01
//int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;
void setup(void){
pinMode (SwitchPin, INPUT_PULLUP);
digitalWrite(SwitchPin,HIGH); // Set Pin to HIGH at beginning
Serial.begin(9600);
radio.begin();
radio.setPALevel (RF24_PA_MAX);
radio.setDataRate (RF24_250KBPS);
radio.openWritingPipe(pipe);}
void loop(void){
if (digitalRead(SwitchPin) == LOW){ // If Switch is Activated
SentMessage[0] = 111;
radio.write(SentMessage, 1); // Send value through NRF24L01
}
else {
SentMessage[0] = 000;
radio.write(SentMessage, 1);
//if (digitalRead(SW1) == HIGH){
//msg[0] = 111;
//radio.write(msg, 1);
}}
Code I would like to integrate (with different brightness settings)
So I have two arduinos, both are connected with an NRF24l01 transceiver and one of them is connected to a LED and the other one has a simple push button wired to the digital input. When I press the button the LED goes on but doesn't stay on because of the code I have right now so I want it to stay on with just one push
I looked at it and I get how it works if there's only one arduino but I don't get how to do it with two (with the transceivers connected to them). The code I have for the transmitter Arduino and the receiver Arduino has to stay in place and I want to implement the 3rd code I wrote in my question but I don't know how when you have to transmit the button push. Do I only have to implement the 3rd code into the receiver code or do I have to divide it and put a part in the transmitter code and a part in the receiver code
I get how it works if there's only one arduino but I don't get how to do it with two
You only have to do it on the receiving end, not both. Instead of testing whether an input becomes HIGH and was LOW, for instance, test whether the message received becomes 123 and was 456 for instance.
Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.
The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work
The first part works perfectly, I only added the transmitter and receiver code to my post because maybe I thought it would help to know the code for integrating the 3rd code I posted
Bri913:
The first part works perfectly, I only added the transmitter and receiver code to my post because maybe I thought it would help to know the code for integrating the 3rd code I posted
So, in my post I added the code I used for the transmitter part for one arduino and code for the receiver part for the other arduino, with this code I can press a button on the transmitter arduino, it sends a signal to the receiver and the LED goes on but it only stays on when I keep te button pressed. I've found a code wich I also added to my post that I want to add to my previous codes of the transmitter and receiver so that I can do just one button push to keep the LED on and one to switch it off like a simple lightswitch. The problem is I don't know how to integrate this code into my previous ones.
Basically I just want my transmitter arduino with the push button on it working as a simple lightswitch, I don't want to keep the button pressed to turn on the LED
Yes I've read the example but it doesn't help me with the wireless application. I've done it without the wireless function (just one arduino) with this code, this switches the LED on and off with just a button push, I don't have to keep the button pressed:
The problem is when i want to add it to my codes for wireless I don't know how to substitute the (pinmode (switchpin): INPUT) because the input is a radio signal not the button because I work with two Arduinos
This is the code for the receiver (first arduino connected to the NRF24l01)
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//int msg[1];
int ReceivedMessage[1] = {000}; // Used to store value received by the NRF24L01
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.setPALevel (RF24_PA_MAX);
radio.setDataRate (RF24_250KBPS);
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);}
void loop(void){
while (radio.available()){
radio.read(ReceivedMessage, 1); // Read information from the NRF24L01
if (ReceivedMessage[0] == 111)
{delay(10);digitalWrite(LED1, LOW);}
else {digitalWrite(LED1, HIGH);}
delay(10);}}
//else{Serial.println("No radio available");}}
And the code for the transmitter (second Arduino connected to the NRF24l01):
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define SwitchPin 7
int SentMessage[1] = {000}; // Used to store value before being sent through the NRF24L01
//int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;
void setup(void){
pinMode (SwitchPin, INPUT_PULLUP);
digitalWrite(SwitchPin,HIGH); // Set Pin to HIGH at beginning
Serial.begin(9600);
radio.begin();
radio.setPALevel (RF24_PA_MAX);
radio.setDataRate (RF24_250KBPS);
radio.openWritingPipe(pipe);}
void loop(void){
if (digitalRead(SwitchPin) == LOW){ // If Switch is Activated
SentMessage[0] = 111;
radio.write(SentMessage, 1); // Send value through NRF24L01
}
else {
SentMessage[0] = 000;
radio.write(SentMessage, 1);
//if (digitalRead(SW1) == HIGH){
//msg[0] = 111;
//radio.write(msg, 1);
}}