Hey guys, here you can find the receiver code and also the transmitter code I have used in my project of the mini RC receiver using Arduino. If you have not yet check it, make sure to check it HERE.

You can also find the list of components and circuit diagram for this project in my previous post.

Before uploading the code, make sure you have the NRF24 library imported in your Arduino IDE. If you don’t have the NRF24 library, go to Arduino IDE and go sketch > include library > manage libraries.
On the search bar, type RF24 and scroll down to the one it says “RF24 by TMRh20” and click on install. This should install the necessary library to use the NRF module. Wait for the installation to complete before uploading the code. You can also check my video below on how to do this.

Receiver Code

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

const uint64_t pipeIn = 0XE8E8F0F0E1LL; //Note that this should be the same for the transmitter also

RF24 radio(7,8); // initialise the CE and CSN pin

struct MyData{

  byte pwm;
};

MyData data;

void resetData(){
  data.pwm = 0;
}

void setup(){

  Serial.begin(9600);
  resetData();

  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);

  radio.openReadingPipe(1,pipeIn);
  radio.startListening();
}

unsigned long lastReceivedTime =0;

void receivedData(){

  while(radio.available()){

    radio.read(&data,sizeof(MyData));
    lastReceivedTime = millis();
  }
}

void loop(){
  unsigned long now = millis();

  if(now - lastReceivedTime >1000){

    resetData();
  }

  analogWrite(3,data.pwm);

  Serial.print("PWM: "); Serial.print(data.pwm); Serial.println("  ");
}
//End of Code


////////////////////////////////////////////////////////////////////////////////////////////////////////



I have also added a Serial.print so that you can see in the Serial Monitor if you are receiving the data from the transmitter. So after uploading the code to the receiver, go to Tool > Serial Monitor.

Transmitter Code

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

const uint64_t my_radio_pipe = 0xE8E8F0F0E1LL; //Remember that this code should be the same for the receiver

RF24 radio(7,8);  //Set CE and CSN pins

// The sizeof this struct should not exceed 32 bytes
struct Data_to_be_sent {
  byte ch1;

};

//Create a variable with the structure above and name it sent_data
Data_to_be_sent sent_data;

void setup()
{
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(my_radio_pipe);

  //Reset each channel value
  sent_data.ch1 = 127;

}

/**************************************************/

void loop()
{

sent_data.ch1 = map(analogRead(0),0,1023,0,255);

  radio.write(&sent_data, sizeof(Data_to_be_sent));
}
// End of code
///////////////////////////////////////////////////////////////////////////////////////////////

You can also download the code here:



Youtube Video