MisterBotBreak
Published

How to Make a Wireless Communication Using a Radio Module

This project will show you how to transmit variables to control a servo motor.

BeginnerProtip12 minutes46,764
How to Make a Wireless Communication Using a Radio Module

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
Jumper wires (generic)
Jumper wires (generic)
×1
nrf24l01
×2
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics ( transmitter and receiver )

Code

Transmitter

Arduino
#include <SPI.h>      
#include <Mirf.h>    
#include <nRF24L01.h> 
#include <MirfHardwareSpiDriver.h> 
 
void setup() {
  Serial.begin(9600);
  Serial.println("Library initialization; EC/CSN pin and channel definition and module transmission and reception address definition");
  delay(2000);
  Mirf.cePin = 9; 
  Mirf.csnPin = 10; 
  Mirf.spi = &MirfHardwareSpi; 
  Mirf.init();  
  Mirf.channel = 1; 
  Mirf.payload = sizeof(float); 
  Mirf.config(); 
  Mirf.setTADDR((byte *) "radio"); 
  Mirf.setRADDR((byte *) "radi1");
}
 
void loop() {
  float value = analogRead(A0); 
  Serial.println(value);
  
  Mirf.send((byte *) &value); 
  while(Mirf.isSending()); 
}  

Receiver

Arduino
#include <SPI.h>     
#include <Mirf.h>     
#include <nRF24L01.h> 
#include <MirfHardwareSpiDriver.h> 
#include <Servo.h>

Servo servo;

void setup() {
  Serial.begin(9600);
  servo.attach(3);
  Mirf.cePin = 9;
  Mirf.csnPin = 10; 
  Mirf.spi = &MirfHardwareSpi; 
  Mirf.init(); 
  Mirf.channel = 1;
  Mirf.payload = sizeof(float); 
  Mirf.config();
  Mirf.setTADDR((byte *) "radi1"); 
  Mirf.setRADDR((byte *) "radio"); 

  Serial.println("Reception of the value :"); 
}

void loop() {
  float value;

  if(Mirf.dataReady()){
    Mirf.getData((byte *) &value); 
    Serial.println(value); 
    
    int degree = map(value, 0, 1080, 0, 180);
    servo.write(degree);
    delay(15);
  }
}

Credits

MisterBotBreak

MisterBotBreak

48 projects • 149 followers
I love electronics and cats :D !

Comments