kaparthi rithik
Published

Radar System Using Ultrasonic Sensor

Radar is an object detection system. Easy to design and cost effective

IntermediateFull instructions provided5 hours6,720
Radar System Using Ultrasonic Sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

SMS Messaging API
Twilio SMS Messaging API
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic View

It is a schematic view of the project

Breadboard

This image gives you a clear connection of components using Breadboard

Circuit Diagram

Code

Arduino code

Arduino
// Includes the Servo library
#include <Servo.h>
// Defines Tirg and Echo pins of the UltrasonicSensor
const int trigPin = 8;
const int echoPin = 7;
// Variables for the duration and the distance
long duration;
int distance;
Servo myServo; // Creates a servo object for controlling the servo motor
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600);
myServo.attach(6); // Defines on which pin is the servo motor attached
}
void loop() {
// rotates the servo motor from 15 to 165 degrees
for(int i=15;i<=165;i++){
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(i); // Sends the current degree into the Serial Port
Serial.print(",");
Serial.print(distance); // Sends the distance value into the Serial Port
Serial.print(".");
}
// Repeats the previous lines from 165 to 15 degrees
for(int i=165; i>15 ;i--){
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
}
}
// Function for calculating the distance measured by the Ultrasonic sensor
int calculateDistance(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance= duration*0.034/2;
return distance;
}

Python code for BOLT

Python
from statistics import mode
from boltiot import Bolt, Sms
import json, time

'''Using the boltiot library for configuring the bolt device , Sms is used to send custom message to any phone number
json is library present by default in python it is used to turn json type data into a python dictionary
time is used for delaying the code so that you wont receive infinite messages.'''

SID = "XXXX"
AUTH_TOKEN = "XXXX"
FROM_NUMBER ="+XXXX"
TO_NUMBER = "+91XXXXXXXXXX"
API_KEY = 'XXXXXX'
DEVICE_ID = 'BOLTXXX'

mybolt = Bolt(API_KEY, DEVICE_ID)#Create a bolt object
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)

while True:
   response = mybolt.serialRead('10')# Fetching the serial data from Arduino
   data = json.loads(response) #Using json to load the response as a python dictionary
   dist = data['value'].rstrip()#rstrip is used to remove any special characters in the data
   x =dist.split(',')
   x = list(map(float,dist.split(",")))
   y = [round(i) for i in x]
   d=mode(y)
   print(f"Object found at {d} cm")
   respond = sms.send_sms(f"An object has been found at {d} cm")#SMS is send if object is detected
   time.sleep(50) #The while loop executes only once every 50 seconds

Credits

kaparthi rithik

kaparthi rithik

2 projects • 2 followers

Comments