Skip to content

How to Make Raspberry Pi Radar?

14 Dec 2023
How to Make Raspberry Pi Radar?
How would you like to make Radar, which we often see in movies, at home using a Raspberry Pi kit? In this project we will learn how to make hommade radar , step by step DIY.

Beep... Beep... How interesting is the sonar sound we hear in movies? How sonar systems that detect ships kilometers away work has always been a matter of curiosity for us engineer candidates.

Today is the time to satisfy this curiosity. Let's make a homemade radar step by step.

How to Make Hommade Radar?

Don't worry. I'll explain step by step how to build a radar for beginners. Let's get started.

Step 1: Let's Examine the Wiring Diagram

In this diagram you can see which components we will use in our Rasberry Pi kit Picobricks:

Step 2: Stand for Sonar Sensor and Servo Motor

Let's build a stand for the sonar sensor that we will connect to Picobricks and the servo motor that rotates it. If you have a 3D printer, I leave the link to the STL file below. If you don't have a 3D printer, you can make a box like in the photo. You can hide the motor inside this box and put your sensor on top.


STL File

 

STEP 3: How to Connect Sonar Sensor to Raspberry Pi?

To connect a sonar sensor to the Raspberry Pi you need 4 jumper cable.

  1. Wire 1 to pinout TrigGPIO15
  2. Wire 2 to Echo GPIO14 pinout
  3. 3rd wire to GND-GND pinout
  4. You must connect the 4th wire to the VCC-VBUS pinout.

If you have PicoBricks, simply plug the 4 pin jumper cable from the kit into one of the free pins on the side of the Raspberry Pi Pico.

Step 3: Load the Code Into BricksIDE

I am writing the code below for beginners. If you want, you can upload these codes to your Picobricks with BricksIDE, ThonnyPhyton(MicroPhyton) you can write your own code with block based programming applications.


from time import sleep
from machine import Pin
from machine import PWM
from math import fabs
import machine
import math
from machine import I2C
from picobricks import SSD1306_I2C
import utime
import time

pwm_2 = PWM(Pin(22))
pwm_2.freq(50)

def CalculateAngle(angle):
   angle = fabs((angle * (6000 / 180)) + 2000)
   angle = round(angle)
   return angle

pin_button = machine.Pin(10, machine.Pin.IN)
import math
pot = machine.ADC(26)
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)
trigger = Pin(15, Pin.OUT)
echo = Pin(14, Pin.IN)

def getDistance():
   trigger.low()
   utime.sleep_us(2)
   trigger.high()
   utime.sleep_us(5)
   trigger.low()
   while echo.value() == 0:
      signaloff = utime.ticks_us()
   while echo.value() == 1:
      signalon = utime.ticks_us()
   timepassed = signalon - signaloff
   distance = (timepassed * 0.0343) / 2
   print("The distance from object is ", distance, "cm")
   return distance

buzzer = PWM(Pin(20))
pin_led = machine.Pin(7, machine.Pin.OUT)

angleservo = 0
servodirection = 1
pwm_2.duty_u16(CalculateAngle(45))

while True:
    while (pin_button.value()) == (0):
        range2 = round(round(pot.read_u16() - 0) * (40 - 5) / (65535 - 0) + 5)
        oled.fill(0)
        oled.text("{}".format("Press the button"), 0, 5)
        oled.text("{}".format("to start "), 30, 20)
        oled.text("{}".format("The Radar"), 30, 35)
        oled.text("{}".format("Range:"), 15, 50)
        oled.text("{}".format(range2), 60, 50)
        oled.show()

    oled.fill(0)
    oled.text("{}".format("Scanning..."), 15, 40)
    oled.show()

    while getDistance() > range2:
        angleservo += servodirection
        pwm_2.duty_u16(CalculateAngle(angleservo))
        time.sleep(0.008)

        if angleservo >= 180:
            servodirection = -1
        elif angleservo <= 0:
            servodirection = 1

    if getDistance() <= range2:
        distance = round(getDistance())
        buzzer.freq(300)
        buzzer.duty_u16(100)
        pin_led.on()
        time.sleep(0.5)
        sleep(0.25)
        buzzer.duty_u16(0)
        pin_led.off()

        while (pin_button.value()) == (0):
            oled.fill(0)
            oled.text("{}".format("Object detected"), 5, 0)
            oled.text("{}".format(distance), 5, 15)
            oled.text("{}".format("cm"), 35, 15)
            oled.text("{}".format(angleservo), 5, 30)
            oled.text("{}".format("degrees"), 35, 30)
            oled.show()

In BricksIDE, your code should look like this:

Step 3: Start Exploring

It's that easy to make homemade radar with our Raspberry Pi kit Picobricks.

Now we can start exploring like an explorer.

  1. If you have uploaded the codes I gave above to Picobricks, you can set the desired distance with the potentiometer from the first menu that appears on the OLED screen when you open Picobricks.
  2. After setting the distance, confirm your choice with the button.
  3. Servo Motors will start to rotate and start to capture objects passing through the distance you set.
  4. If the radar detects an object, the buzzer will emit a warning sound and the angle and distance at which the object was seen will be displayed on your OLED screen.
    Prev Post
    Next Post

    Thanks for subscribing!

    This email has been registered!

    Shop the look
    Choose Options

    Edit Option

    Back In Stock Notification

    Compare

    Product SKURatingDescription Collection Availability Product Type Other Details
    this is just a warning
    Login
    Shopping Cart
    0 items
    Same Day Shipping No Extra Costs
    Easy Returns Guarantee Return with Ease
    Secure Checkout Secure Payment