Setting up the transmitter and the receiver

So i am still waiting for the level shifters to come, meanwhile i wrote a code that would form the framework for the codes for the RC car so that i would not have to spend a lot of time in debugging.

I made a shield for the receiver node that would rest on the RC and a controller for the transmitter node using the joystick that i had hacked earlier. As of now we will not use the joystick , we will send some custom messages. Now when we are in room it is pretty easy to debug using serial monitor but for finding the maximum range and probably some other stuff we cannot possibly use serial monitor on laptop (we can but that would be tedious and overkill) . So i connected some LEDs as a visual indicator to indicate when we are receiving messages and when we have stopped receiving messages.

What i basicaDSC02020lly do is that i transmit some message from TX and the RX keeps on looking for them. If it receives the message then it glows a BLUE led and once it stops receiving data it glows a RED led. So as soon as the RED led on RX starts glowing we can come to know that we have reached the maximum range.

DSC02023

 

 

The backside of the shield.

 

 

DSC02183

 

 

This is what the transmitter looks like –

 

 

 

TX side code –

#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
int msg[1] = {1};
RF24 radio(9, 10);
const uint64_t pipe[1] = {0xF0F0F0F0E1LL};

void setup()
{
  Serial.begin(57600);
  radio.begin();
  delay(100);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.enableDynamicPayloads();
  radio.stopListening();
  radio.openWritingPipe(pipe[0]);
  radio.setRetries(15, 15);
}
void loop()
{
  if (radio.write(msg, sizeof(msg)))
  {
    msg[0] += 3;
    if (msg[0] >= 100)
    {
      msg[0] = 1;
    }
  }
}

Rx side code –

//red glows and blue stops glowing when no reception is there
//blue glows and red stops glowing when reception is proper
#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
const uint64_t pipe[1] = {0xF0F0F0F0E1LL};
RF24 radio(9, 10);
int msg;
const int red = 6;
const int blue = 7;
void setup()
{
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  Serial.begin(57600);
  radio.begin();
  delay(100);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.enableDynamicPayloads();
  radio.openReadingPipe(1, pipe[0]);
  radio.startListening();
  radio.setRetries(15, 15);
}
void loop()
{
  if ( radio.available() ) {
    radio.read( &msg, sizeof(msg) );
    //Serial.print("integer got is : ");
    //Serial.println(msg);
    digitalWrite(blue, HIGH);
    digitalWrite(red, LOW);
    delay(10);//this delay is very important as it prevents the red
    //led from glowing simultaneously with blue as you know that
    //transmissions from TX are not continuous,remember the datasheet.
    //also remember that there is no delay in the TX code.
  }
  else
  {
    //Serial.println("no radio");
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);
  }
}

RESULTS

DSC02185 copyDSC02188 copy

Advertisements

About Shantam Raj

Currently I am a final year B.Tech undergraduate majoring in “Electronics and Communication Engineering” from IIT Guwahati. I am passionate about electronics and robotics. Apart from that I love writing, visit https://medium.com/@shantam_raj for some of my works. I am a die hard soccer fan. I also love to play badminton. I am a hardware hacking enthusiast and a tinkerer !!.
This entry was posted in Arduino, DIY, Hacking, nRF24L01+, Wireless and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s