Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Robin Kanattu Thomas
Published © GPL3+

Wireless Connection Between Micro Controllers Using nRF24L01

nRF24L01 radio transceiver provides very efficient and inexpensive way to establish communication between microcontrollers.

BeginnerProtip1 hour23,347
Wireless Connection Between Micro Controllers Using nRF24L01

Things used in this project

Story

Read more

Schematics

nRF24L01 Receiver

nRf24l01 Transmitter

Code

nRF240L1 Transmitter

C/C++
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>

int msg[1];
RF24 radio(9,10);//check your pin number on RF24 github check you have the right
//pin for the arduino you're using. this pin number is diffrent for diffrent arduino models.

const uint64_t pipe = 0xF0F0F0F0D2L;

int buttonPin1 = 5;
int buttonState1 = 0;

void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(buttonPin1, INPUT);
  
}

void loop(void)
{
  buttonState1 = digitalRead(buttonPin1);
 
  
  if (buttonState1 == HIGH)
  {
    msg[0] = 212;
    radio.write(msg, 1);
  }
 
}

nRF24L01 receiver

C/C++
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>      // include the Servo library 
Servo myServo;   

int msg[1];
RF24 radio(9,10);//check your pin number on RF24 github check you have the right
//pin number for the arduino you're using. this pin is diffrent for diffrent arduino models.

const uint64_t pipe = 0xF0F0F0F0D2L;


void setup(void)
{
 myServo.attach(3);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  myServo.write(0);      // initial position of servo at angle 0
 
}

void loop(void)
{
  if(radio.available()){
    bool done = false;
    while (!done) {
      done = radio.read(msg, 1);
      Serial.println(msg[0]);
      if (msg[0] == 212) {
       myServo.write(180); 
      }
      else {   
            myServo.write(0); 
      }
    }
  }
}

Credits

Robin Kanattu Thomas
13 projects • 179 followers
Electronics Enthusiast, Micro controller fan and love Open Source.

Comments