nRF24L01 and 4 Relays

Let me first apologize for this thread, I know someone is going to tell me I should just use the search function or something similar...but i seriously seem to be not smart enough to figure this out by myself.
Also I am a total noob when it comes to programming (i'm looking to change that.)

All i want to do is control a 4 relay array via 2 arduino unos (one as the transmitter controlled by the serial monitor the other connected to the relay array) Both arduinos connected to an nRF24L01-module. I've used the libraries succesfully to ping a "Hello world"-programm, also i added some 47 µF caps to the rf module, all this worked fine.
However I seem too be too slow and/or frustration intolerant to come up with the solution. Obviously there are a lot of examples out there using hardware switches etc to turn the relays on/off.
All i really want to do is e.g. type: "1" or "2" or whatever to adress one of the relays and turn it on and maybe something like "-1" or "-2" to turn it off.

I know anyone who knows their stuff will be able to get this working within an hour tops, however...i dont seem to know my stuff.

So my question really is: What tutorials do i need to read to get this working or can any of you help me with a code i can modify to achieve this?
I know my problem is the result of a lack on basic understanding of programming and too little training to really know what im doing.

Thanks for any help i can get!
Best wishes, Bob

EDIT:
This Arduino- NRF24L01 2.4Ghz Wireless Relay Switch - YouTube is what I am looking to do, but instead of hardware-switches do it via the serial monitor. Also not only for 1 but for 4 relays.

A quick google search turns this up

choose what text you want to switch a certain relay.

if(relay2 == "defined text")
digitalWrite(relay2pin, HIGH);

etc...

Have a look at this Simple nRF24L01+ Tutorial.

A simple way to control four relays is to send "1111" if you want them all on or "0000" if you want them all off. Or any combination like "0101" if you want some on and some off. The position of the 1 (or 0) identifies which relay it refers to.

...R

Alright, I had a little help and we came up with this code.
I know its not perfect because it should be using an array but it does the Job. Still need some modifications though.

//transmitter

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10);

const byte rxAddr[6] = "00001";

void setup()
{
  

  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);
  radio.stopListening();

}

void loop()
{
  while( Serial.available()>0){
    char cmd = Serial.read();
    if (cmd > 48 && cmd < 57){
      radio.write(&cmd, 1);  
    }   
  }  
}
//receiver

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CH1 2  
#define CH2 3 
#define CH3 4 
#define CH4 5


RF24 radio(9, 10);
char cmd;
const byte rxAddr[6] = "00001";

void onPin(int8_t pin) {
  digitalWrite(pin, LOW);
  delay(1000);
  digitalWrite(pin, HIGH);
}

void offPin(int8_t pin) {
  digitalWrite(pin, HIGH);  

}

void setup()
{
  pinMode(CH1, OUTPUT);
  pinMode(CH2, OUTPUT);
  pinMode(CH3, OUTPUT);
  pinMode(CH4, OUTPUT);
  digitalWrite(CH1,HIGH);
  digitalWrite(CH2,HIGH);
  digitalWrite(CH3,HIGH);
  digitalWrite(CH4,HIGH);
  
  radio.begin();
  radio.openReadingPipe(0, rxAddr);
  radio.startListening();
}

void loop()
{
  if (radio.available())
  {
    radio.read(&cmd, 1);

    switch(cmd){ 
      case '1':  onPin(CH1); break;
      case '2':  onPin(CH2); break;
      case '3':  onPin(CH3); break;
      case '4':  onPin(CH4); break;
      case '5': offPin(CH1); break;
      case '6': offPin(CH2); break;
      case '7': offPin(CH3); break;
      case '8': offPin(CH4); break;
    }
    
  }
}

Basically just 1-4 to turn on relay 1-4 and 5-8 to turn relay 1-4 off again.
...not quite what I wanted but itll do for now.

Thanks for your input, I might be back soon..:slight_smile:

Hi,
Welcome to the forum.

Before you leave.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... Good to see you got it working... :slight_smile:

There we go :slight_smile: