RADIO COMMUNICATION : DISTANCE SENSOR

by syams6681 in Circuits > Arduino

1169 Views, 2 Favorites, 0 Comments

RADIO COMMUNICATION : DISTANCE SENSOR

FLOWCHART.jpg

BRIEF

This project demonstrate how to transfer data using wireless RF communication network. In our case, we are going to measure the distance and transfer it to remote device over RF Link communication.

The Project consists of two separate circuits. Transmitter circuit with Ultrasonic sensor and Receiver circuit with buzzer and vibration motor.

Transmitter will send distance value to Receiver, once distance reaches setpoint, Receiver generates an alert. Setpoint-1 is set 50cm and Setpoint-2 is 30cm. when distance reaches to Setpoint-1, Vibration motor will be ON and Buzzer will beep periodically every Second. When it reaches Setpoint-2 both Buzzer and Vibration motor will be ON continuously.

BILL OF MATERIAL

  • ARDUINO UNO x 2
  • nRF24 RADIO x 2
  • ULTRASONIC SENSOR x 1
  • BUZZER x 1
  • VIBRATION MOTOR x 1
  • 9V BATTERY x 2
  • Battery HOLDER x 2

ASSEMBLY

SCHEMATIC.jpg
IMG_3271.JPG
IMG_3270.JPG

Connect all component as wiring diagram above

Upload Transmitter Sketch

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

RF24 radio(9, 10);// CE, CSN

void setupRadio() {
  radio.begin();// Initiate the radio
  radio.setRetries(15, 15);// Define the number of retries sending a packet
  radio.setChannel(30);  // Define the radio’s broadcast channel (0 – 127), Must be the same on the sensor and the master node
  radio.setDataRate(RF24_250KBPS);// Define the radio’s bitrate (using cards lowest bitrate)
  radio.setPALevel(RF24_PA_MIN);// Define the radio’s power amplifier level (RF24_PA_MIN for debugging, RF24_PA_HIGH for longest range)
  radio.enableDynamicPayloads();  // Enable dynamic payloads for packets
  radio.openReadingPipe(1, 0xE8E8F0F0E1LL);  // Open reading pipe
  radio.startListening();  // Start listening for packets
}

float distance ;
int setpoint = 50;
int criticalDistance = 30;
int buzzerPin = 8;
int vibratorPin = 7;


void setup() {
  // Initiate serial connection
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);
  pinMode(vibratorPin, OUTPUT);
  digitalWrite(buzzerPin, LOW);
  digitalWrite(vibratorPin, LOW);
  // RF Radio setup
  setupRadio();
}

void loop() {
  // Check if the radio has received any data
  if (!radio.available()) {
    Serial.println("No Data received");
    digitalWrite(buzzerPin, LOW);
    digitalWrite(vibratorPin, LOW);
  }
  else {
    radio.read(&distance, sizeof(distance));
    Serial.print(distance);
    Serial.print(" : ");
    //Prepare the logic for buzzer
    if (distance < criticalDistance) {
      digitalWrite(vibratorPin, HIGH);
      digitalWrite(buzzerPin, HIGH);
      Serial.println("CRITICAL");
    }
    else if (distance < setpoint) {
      Serial.println("ALERT");
      digitalWrite(vibratorPin, HIGH);
      digitalWrite(buzzerPin, HIGH);
      delay(300);
      digitalWrite(vibratorPin, LOW);
      digitalWrite(buzzerPin, LOW);
      delay(300);
    }
    else {
      digitalWrite(vibratorPin, LOW);
      digitalWrite(buzzerPin, LOW);
      Serial.println("SAFE");
    }
  }
}<br>

Upload Receiver Sketch

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

RF24 radio(9, 10);// CE, CSN

void setupRadio() {
  radio.begin();// Initiate the radio
  radio.setRetries(15, 15);// Define the number of retries sending a packet
  radio.setChannel(30);  // Define the radio’s broadcast channel (0 – 127), Must be the same on the sensor and the master node
  radio.setDataRate(RF24_250KBPS);// Define the radio’s bitrate (using cards lowest bitrate)
  radio.setPALevel(RF24_PA_MIN);// Define the radio’s power amplifier level (RF24_PA_MIN for debugging, RF24_PA_HIGH for longest range)
  radio.enableDynamicPayloads();  // Enable dynamic payloads for packets
  radio.openReadingPipe(1, 0xE8E8F0F0E1LL);  // Open reading pipe
  radio.startListening();  // Start listening for packets
}

float distance ;
int setpoint = 50;
int criticalDistance = 30;
int buzzerPin = 8;
int vibratorPin = 7;


void setup() {
  // Initiate serial connection
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);
  pinMode(vibratorPin, OUTPUT);
  digitalWrite(buzzerPin, LOW);
  digitalWrite(vibratorPin, LOW);
  // RF Radio setup
  setupRadio();
}

void loop() {
  // Check if the radio has received any data
  if (!radio.available()) {
    Serial.println("No Data received");
    digitalWrite(buzzerPin, LOW);
    digitalWrite(vibratorPin, LOW);
  }
  else {
    radio.read(&distance, sizeof(distance));
    Serial.print(distance);
    Serial.print(" : ");
    //Prepare the logic for buzzer
    if (distance < criticalDistance) {
      digitalWrite(vibratorPin, HIGH);
      digitalWrite(buzzerPin, HIGH);
      Serial.println("CRITICAL");
    }
    else if (distance < setpoint) {
      Serial.println("ALERT");
      digitalWrite(vibratorPin, HIGH);
      digitalWrite(buzzerPin, HIGH);
      delay(300);
      digitalWrite(vibratorPin, LOW);
      digitalWrite(buzzerPin, LOW);
      delay(300);
    }
    else {
      digitalWrite(vibratorPin, LOW);
      digitalWrite(buzzerPin, LOW);
      Serial.println("SAFE");
    }
  }
}

Testing

TESTING RADIO COMMUNICATION
  1. Expose the object 1 mtrs in front of ultrasonic sensor
  2. Get closer until it reaches Setpoint-1 (50 Cm)
  3. The buzzer and Vibration Sensor will be ON periodically every second
  4. Move Closer till it reaches Setpoint-2 (30 Cm)
  5. In this point, Both Buzzer and Vibration motor should be ON continuously

See attached video for detail

Conclusion

Wireless RF communication is widely used in where hard wiring is difficult to be implemented.

This Concept can be implemented for :

  1. Water Level monitoring system
  2. Reverse Parking sensor
  3. Smart Blind Stick
  4. Remote monitoring system.

Hope you enjoy this project. Thank You.