Sending and Receiving IR sensor data through NRF24L01

NRF24L01 is known as a multiceiver as it can transmit and receive data at the same time over a distance of 100 meters. It is an inexpensive yet reliable two way RF module. It is a cheap module which could be bought only for 2 bucks online  on various sites making it one of the most inexpensive data communication options that you can get.



Hardware rundown:

Radio Frequency: 2.4GHz worldwide ISM(Industrial Scientific and Medical) frequency band and uses GFSK modulation for data transmission.

Power Consumption: 1.9-3.6V

SPI Interface: It communicates over a 4-pin Serial Peripheral Interface with a maximum data rate of 10Mbps with 125 selectable channels with an SPI configuration.

Modulation Format: GFSK

Maximum Operating Current: 13.5mA

Max Air data rate: 2Mb/s


Infrared sensors
IR sensor also known as Infrared sensor is an electronic device that computes and detects infrared radiation in its surrounding environment. Active infrared sensors both emit and detect infrared radiation. Active IR sensors have two parts: a light emitting diode (LED) and a receiver.
App used:
Code:
Transmitter Side:


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

//By easymathsforyou3@gmail.com

//techrobcrew.blogspot.com

//Youtube: https://www.youtube.com/channel/UCY5O7tihQh7VwO4iWww3iCg

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

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";

struct MyData {
  int sensorState1;
  int sensorState2;
};
MyData data;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  radio.begin();
  radio.openWritingPipe(address);
 radio.setPALevel(RF24_PA_MIN);
 radio.stopListening();
}

void loop(){
  
  int x=digitalRead(A3);
  int y=digitalRead(7);

   if(x==0){
    data.sensorState1=digitalRead(A3);
    Serial.println("A3");
    Serial.println(data.sensorState1);
  }
  if(x==1){
    data.sensorState1=digitalRead(A3);
    Serial.println("A3");
    Serial.println(data.sensorState1);
  }
   if(y==0){
    data.sensorState2=digitalRead(7);
    Serial.println("7");
    Serial.println(data.sensorState2);
  }
   if(y==1){
    data.sensorState2=digitalRead(7);
    Serial.println("7");
    Serial.println(data.sensorState2);
    }
  radio.write(&data, sizeof(MyData));
  delay(100);
}
********************//////////////***************
Receiver code:


********************//////////////***************
//By easymathsforyou3@gmail.com

//techrobcrew.blogspot.com

//Youtube: https://www.youtube.com/channel/UCY5O7tihQh7VwO4iWww3iCg

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

RF24 radio(9,10); // CE, CSN
const byte address[6] = "00001";

struct MyData {
 int sensorState1;
 int sensorState2;
};
MyData data;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    while (radio.available()) {
      //int angleV = 0;
 radio.read(&data, sizeof(MyData));
if(data.sensorState1==0){
   Serial.println("Forward");
}
if(data.sensorState2==0){
   Serial.println("Rewind");
  }
}
  }
}
********************//////////////***************

By:
techrobcrew.blogspot.com

YouTube channel:
https://www.youtube.com/channel/UCY5O7tihQh7VwO4iWww3iCg

Email:
eastmathsforyou3@gmail.com

Comments

Popular posts from this blog

ESP32 Error: A fatal error occurred: Timed out waiting for packet content.

How to calculate Mean, Median and Mode in python

Detecting Obstacles and Warnings with ultrasonic sensor