Radar System in Banana Pi

Radar System in Banana Pi

5th September 2019 0 By Tanna TechBiz

Introduction

  • The RADAR system generally consists of a transmitter which produces an electromagnetic signal which is radiated into space by an antenna.
  • When this signal strikes any object, it gets reflected or re radiated in many directions.
  • This reflected or echo signal is received by the radar antenna which delivers it to the receiver, where it is processed to determine the geographical statistics of the object.
  • The range is determined by the calculating the time taken by the signal to travel from the RADAR to the target and back.
  • The target’s location is measured in angle, from the direction of maximum amplitude echo signal, the antenna points to. To measure range and location of moving objects, Doppler Effect is used.
  • So this basic principle we are going to use here, to make prototype model of the RADAR system.
  • In this model we will use Ultra sonic sensor to send and receive the signal according to RADAR principle.

Component

First of all you need to boot up your bananapi for that visit : https://bananapiblog.com/2019/05/02/how-to-install-linux-based-os-images-except-android/

Connection

Bpi-M2UServo Motor Ultrasonic Sensor
Pin 39GND (Brown wire)
Pin 37Control pin (Orange wire)
Pin 2VCC (Red wire)
Pin 4VCC
Pin 6GND
Pin 7Trig
Pin 11Echo

What we are going to do ?

  • Here our basic concept is to configure the sensor because Ultrasonic Sensor has ability to transmit and receive the Ultra sonic waves.
  • Basically HC-SR04 is used to measure the distance of object from particular place.
  • So we use this concept to make our RADAR.
  • In our RADAR we use this concept, so basically HC-SR04 sensor transmit the the Ultra sonic wave, and that wave get reflated back after striking with objects and it received by the HC-SR04 sensor.
  • As HC-SR04 receive the signal we need to write some lines of code to calculate the distance.
  • Now what we are going to do is, we use the servo motor to rotate our HC-SR04 sensor so we can catch range at multiple angles.
  • In original RADAR has graphical representation of the all system so to make our prototype more attractive we will do some coding to generate graphics which represents o/p of the HC-SR04
  • Now to configure all this things here we use the python programming and to generate graphics we will use Python Turtle module.
    (see this : https://www.blog.tannatechbiz.com/basics-of-python-turtle-module/)
  • Now what i am going to do here is, i will rotate my hand of graphics to 0-180 degree and at the same time i will also rotate the servo motor from 0-180 degree but here issue is that we need to rotate the hand of our graphics and servo at same angle. So for that we need to do some mathematical calculation.
  • By doing this we can easily calibrate our motor with our graphics.
  • Now here we can count that how many object is detected and according to that we will going to display it on our graphics.

Code

  • Here we are going to use Python programming.
  • First of all open the terminal in bpi-M2U anmake empty python file using below command.
$ sudo nano radar_system.py
  • After making file, open that file using below command.
$ cd radar_system.py
  • Now you need to copy and past below code in that file.
 import Rpi.GPio as GPIO
 import time
 import turtle

 count = 0

 GPIO.setmode(GPIO.BOARD)
 servo_pin = 35
 GPIO.setup(servo_pin, GPIO.OUT)
 p = GPIO.PWM(35, 25)

 trigger = 7
 echo = 11
 GPIO.setup(trigger, GPIO.OUT)
 GPIO.setup(echo, GPIO.IN)

 pen = turtle.Turtle()
 wn = turtle.Screen()
 pen.ht()

 x = 300
 y = 300

 wn.title("Tanna TechBiz")
 wn.setup(width = x, height = y)
 wn.tracer(0)
 wn.bgcolor('black')

 def redar_screen():
     pen.color('white')
     pen.up()
     pen.goto(0, -y/2)
     pen.down()

     angle_1 = 180
     for i in range(7):
         pen.setheading(angle_1)
         pen.fd(x+y)
         pen.up()
         pen.goto(0, -y/2)
         pen.down()
         angle_1 -= 30

 pen1 = turtle.Turtle()
 pen2 = turtle.Turtle()
 pen3 = turtle.Turtle()
 pen3.color('green')

 def tracking():
     pen1.color('red')
     pen1.up()
     pen1.goto(0, -y/2)
     pen1.down()
     pen1.setheadin-g(angle_2)
     pen1.fd(x+(y/2))

def distance():
     GPIO.output(trigger, True)
     time.sleep(0.0001)
     GPIO.output(trigger, False)
     StartTime = time.time()
     StopTime = time.time()

     while GPIO.input(echo) == 0:
         StartTime = time.time()
     while GPIO.input(echo) == 1:
         StopTime = time.time()
     TimeElapsed = StopTime - StartTime
     distance = (TimeElapsed * 34300)/2
     return distance

while True:
     pen3.up()
     pen3.goto(0, -y)
     pen3.down()
     pen3.write("Object detected : ")

     dist = distance()
     print("Measured distance =% 1f cm" %dist)
 
     radar_screen()

     angle_2 = 180
     p.start(0)
     angle_servo = 0
     for i in range(10):
         dist = distance()
         if dist > 100:
             count += 1
             pen2.up()
             pen2.goto(pen1.xcor(), pen1.ycor())
             pen2.down()
             pen2.color('megenta')
             pen2.begin_fill()
             pen2.circle(20)
             pen2.end_fill()
             pen2.color('red')
             pen2.write(count)

      tracking()
         p.ChangeDutyCycle(angle_servo)
         angle_2 -= 20
         angle_servo += 0.000005
         wn.update()
         time.sleep(0.05)
         pen1.clear()

     angle_2 = 0
     angle_servo = 5.5
     for i in range(10):
         dist = distance()
         if dist > 100:
             pen2.up()
             pen2.goto(pen1.xor(), pen1.ycor())
             pen2.down()
             pen2.color('cyan')
             pen2.begin_fill()
             pen2.circle(20)
             pen2.end_fill()
             pen2.color('red')
             pen2.write(count)

     tracking()
         p.ChangeDutyCycle(angle_servo)
         angle_2 += 20
         angle_servo -= 0.000005
         wn.update()
         time.sleep(0.05)
         pen1.clear()

     pen3.clear()
     pen3.color('green')
     pen3.up()
     pen3.goto(100, -y)
     pen3.down()
     pen3.write(count)
     pen3.ht()
  • Now to save this file press Ctrl+o+m+x and to run it type :
$ sudo python radar_system.py

You can enjoy the o/p