Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

1.

Introduction

Object detection system using ultrasonic sensor is a project that can detect any
object in the path with the help of an ultrasonic sensor. Ultrasonic sensor rotates over
the servo motor and almost cover all directions in rotatory motion. There is processing
software that makes it possible. The ultrasonic sensor is very useful in my electronics
projects. It uses in distance measuring and object detection. The radar system uses the
ultrasonic sensor to detect the object in front of the sensor and servo motor help to cover
the distance by rotating itself slowly. This detection system has one ultrasonic sensor,
one servo motor, two LEDs to work as a virtual indicator, one buzzer to alert if the
object is within the limited range, and an Arduino uno.

1
2. Objectives

The main objectives of the project are the followings:

1. To create an operation Ultrasonic radar system that is capable of monitoring a


particular area.

2. To detect exactly distances and angles of objects.

3. To study how to working radar at processing software.

2
3. Components List

Table 1: Hardware Components

No. Type Quantity


1 Arduino Uno Board(R3) 1
2 Ultrasonic Sensor 1
3 Servo Motor 1
4 Breadboard 1
5 LED 2
6 Buzzer 1
7 Jumper Wires 16
8 Resistors 2
9 USB Cable 1

3
4. Hardware Descriptions

4.1. Arduino Uno

Arduino is an open-source project that created microcontroller-based kits for


building digital devices and interactive objects that can sense and control physical
devices. In this project the systems provide sets of digital and analog input/output (I/O)
pins that can interface to various expansion boards (termed shields) and other circuits.
The Arduino project provides an integrated development environment (IDE) based on
a programming language named Processing, which also supports the languages, C and
C++. The Arduino UNO board is probably the most popular among the developers of
electronic products based on the Arduino. It is ideal for debugging the software and
hardware parts of devices during the development phase.

Figure 1: Arduino Uno

4.2. Ultrasonic Sensor

The ultrasonic sensor works on the principle of SONAR and RADAR system
which is used to determine the distance to an object. An ultrasonic sensor generates the
high frequency sound (ultrasound) waves. An ultrasonic sensor uses a transducer to
send and receive ultrasonic pulses that relay back information about an object's
proximity. When this ultrasound hits the object, it reflects as echo which is sensed by
the receiver as shown in below.

4
Figure 2: Ultrasonic Sensor

4.3. Servo Motor

A servo motor is a rotary or linear actuator that allows for precise control of
angular or linear position, velocity, and acceleration in a mechanical system. It
constitutes part of a servomechanism, and consists of a suitable motor coupled to a
sensor for position feedback. It usually comes with a gear arrangement that allows us
to get a very high torque servo motor in small and lightweight packages. Due to these
features, they are being used in many applications like toy car, RC helicopters and
planes, Robotics, etc.

Figure 3: Servo motor

5
4.4. Breadboard

A breadboard consists of plastic block holding a matrix of electrical sockets of


a size suitable for gripping thin connecting wire, component wires or the pins of
transistors and integrated circuits (ICs). The sockets are connected inside the board,
usually in rows of five sockets.

Figure 4: Breadboard

4.5. LED

A light-emitting diode is a semiconductor device that emits light when current


flows through it. Electrons in the semiconductor recombine with electron holes,
releasing energy in the form of photons. The color of the light is determined by the
energy required for electrons to cross the band gap of the semiconductor.

Figure 5: LED

4.6. Buzzer

A buzzer or beeper is an audio signaling device, which may be mechanical,


electromechanical, or piezoelectric (piezo for short). Typical uses of buzzers and
beepers include alarm devices, timers, train and confirmation of user input such as a
mouse click or keystroke. It has two inputs: signal and ground.

6
Figure 6: Buzzer

4.7. Jumper Wires


Jumper wires are simply wires that have connector pins at each end, allowing
them to be used to connect two points to each other without soldering. Jumper wires
are typically used with breadboards and other prototyping tools in order to make it easy
to change a circuit as needed. Fairly simple. In fact, it doesn’t get much more basic than
jumper wires. Jumper wires typically come in three versions: male-to-male, male-to-
female and female-to-female. The difference between each is in the end point of the
wire. Male ends have a pin protruding and can plug into things, while female ends do
not and are used to plug things into. Male-to-male jumper wires are the most common
and what you likely will use most often. When connecting two ports on a breadboard,
a male-to-male wire is what you’ll need.

Figure 7: Jumper Wires

4.8. Resistors

The resistor is a passive electrical component that creates resistance in the flow
of electric current. In almost all electrical networks and electronic circuits they can be
found. The resistance is measured in ohms (Ω). An ohm is the resistance that occurs
when a current of one ampere (A) passes through a resistor with a one volt (V) drop
across its terminals. The current is proportional to the voltage across the terminal ends.
This ratio is represented by Ohm’s law. Resistors are used for many purposes. A few
examples include limiting electric current, voltage division, heat generation, matching

7
and loading circuits, gain control, and setting time constants. They are commercially
available with resistance values over a range of more than nine orders of magnitude.
They can be used as electric brakes to dissipate kinetic energy from trains, or be smaller
than a square millimeter for electronics.

Figure 8: Resistor

4.9. USB Cable

The USB cable has one end as USB type A connector and another end has a
USB type B connector. The USB type-A end is connected to the power source or the
programming device (e.g., your computer/laptop) and the USB B end is connected to
Arduino UNO or MEGA 2560 board.

Figure 9: USB Cable

8
5. Software Requirements

5.1. Arduino Software

The Arduino Integrated Development Environment – or Arduino Software (IDE)


– contains a text editor for writing code, a message area, a text console, a toolbar with
buttons for common functions and a series of menus. It connects to the Arduino
hardware to upload programs and communicate with them.

Figure 9: Arduino Software

5.2. Processing Software

Processing is an open-source graphical library and integrated development


environment (IDE) built for the electronic arts, and visual design communities with the
purpose of teaching non-programmers the fundamentals of computer programming in
a visual context. Processing uses the Java language, with additional simplifications such
as additional classes and aliased mathematical functions and operations. It also provides
a graphical user interface for simplifying the compilation and execution stage.

9
Figure 9: Processing Software

6. System Design and Implementation

6.1. System Design

Ultrasonic sensor

Buzzer
Display
Microcontroller
Servo motor LED

Power supply

Figure 10: Block Diagram of Object Detection System

10
6.2 System Implementation

This system includes an Arduino Uno microcontroller, an ultrasonic sensor, a


servo motor, a buzzer and two LEDs. The ultrasonic sensor is used as input device for
the microcontroller. The buzzer and servo motor are used as output devices to alert and
to support ultrasonic sensor detecting around the area respectively. The LEDs are used
as an indicator. The Arduino Uno is used to control the processes of a object detection
system. The connection of the microcontroller, input, and output devices involves the
following steps:

Step 1: Connecting Ultrasonic sensor to the Arduino

1. Connect the VCC pin of the ultrasonic sensor to the positive terminal of the
Arduino (5V) pin.

2. Connect the GND pin of the ultrasonic sensor to any GND pin of the Arduino.

3. Connect the Trig pin and echo pin of ultrasonic sensor to digital pins 2 and 3 of
the Arduino.

Step 2: Connecting a servo motor to the Arduino

1. Connect the VCC pin of the Servo motor to the positive terminal of the Arduino
(5 V).

2. Connect the GND pin of the Servo motor to any GND pin on the Arduino.

3. Connect the Servo’s signal pin of the Servo motor to digital pin 9 of the Arduino.

Step 3: Connecting two LEDs to the Arduino

1. Connect anode terminal of Green LED to digital pin 8 of the Arduino.

2. Connect cathode terminal of Green LED to the terminal of resistor.

3. Connect anode terminal of Red LED to digital pin 7 of the Arduino.

4. Connect cathode terminal of Red LED to the terminal of resistor.

Step 4: Connecting Buzzer to the Arduino

1. Connect the Ground pin of the buzzer to any GND pin of the Arduino.
11
2. Connect the Signal pin of the buzzer to digital pin 4 of the Arduino.

Step 5: Programming the Arduino

1. Download Arduino IDE 2.3.2 from https://www.arduino.cc/en/software.

2. Connect the Arduino board to the computer using a USB cable.

3. Open the Arduino IDE and select the appropriate board from the Tools menu
under Boards.

4. Choose the correct port from Tools > Serial Port.

5. Copy the following sketch, which appears in your web browser, to your Arduino
sketch page.

6. Click on the Upload icon or go to File > Upload.

7. The final step is to connect the Arduino’s cable to the adapter and then plug it
into the socket.

Step 6: Programming the Processing

1. Download Processing IDE 2.3.2 from https://processing.org/download.

2. A Processing program is called a sketch. The idea is to make Java-style


programming feel more like scripting, and adopt the process of scripting to
quickly write code.

3. Sketches are stored in the sketchbook, a folder that's used as the default location
for saving all of your projects.

4. Sketches that are stored in the sketchbook can be accessed from


File → Sketchbook. Alternatively, File → Open... can be used to open a sketch
from elsewhere on the system.

5. Connect the Arduino board to the computer using a USB cable.

6. The port number in the Arduino must match the port number in the processing
code.

12
7. Click on the Sketch icon or go to Run or Click Run icon above the code.

6.3 Implementation Results

Object detection system has been successfully implemented and shows good
performance. The ultrasonic sensor detects an object and send the right signal to the
Arduino board and the Arduino communicate the processing software so that the angle
of the object is calculated successfully. Buzzer and LEDs were also used to give an
alarm if a ship is detected at a specific distance. The result implementation is shown in
Fig-12. The ultrasonic radar can actually detect an object of about 40cm away but a
specific distance was chosen in this project for the alarm system to triggered.

An LED remain high indicating that no ship is close to colliding with another
ship if the position of the other ship or object is greater than 40cm, but if it is less than
40cm then the Arduino will trigger the alarm system to come up with a buzzer and red
LED indicating that the ship is close to colliding with another ship.

Figure 12: Screen displaying output of the system

13
8. Conclusion
Within the first week of starting our project, we decided to make a project based
on our mini-project. So, we chose to make something useful related to ultrasonic sensor.
And then, an ultrasonic radar system was designed and implemented experimentally for
distance measurements purposes to be used in various applications. An Arduino Uno
device was used as a controller in the design beside other requirements such as
servomotor, ultrasonic sensor and computer for distance calculation of objects or
obstacles placed at different angles (from 0 to 180 degrees) within the range up to 40
centimeters.

9. References

[1] https://picobricks.com/blogs/info/what-is-buzzer?currency=USD

[2] https://projecthub.arduino.cc/nimishac/ultrasonic-radar-with-arduino-19baa3

[3] https://techatronic.com/radar-using-arduino-ultrasonic-sensor/

[4] https://circuitdigest.com/article/servo-motor-working-and-basics

10. Appendix

Arduino Code

#include<Servo.h>

#define trigPin 2

#define echoPin 3

#define LED_PIN 7

#define LED_PING 8

const int DISTANCE_THRESHOLD = 40;

const int BUZZER_PIN = 4;

long duration;

int distance;
14
Servo myservo;

void setup(){

pinMode(LED_PIN, OUTPUT);

pinMode(LED_PING, OUTPUT);

pinMode(trigPin , OUTPUT);

pinMode(echoPin, INPUT);

pinMode(BUZZER_PIN, OUTPUT);

myservo.attach(9);

Serial.begin(9600);

void loop(){

int i;

for (i = 0; i <= 180; i++){

myservo.write(i);

delay(15);

distance = calculateDistance();

Serial.print(i);

Serial.print(",");

Serial.print(distance);

Serial.print(".");

for (i = 180; i >= 0; i--){

myservo.write(i);

delay(15);

distance = calculateDistance();

15
Serial.print(i);

Serial.print(",");

Serial.print(distance);

Serial.print(".");

int calculateDistance()

if(distance < DISTANCE_THRESHOLD)

{digitalWrite(LED_PIN, HIGH);

digitalWrite(LED_PING, LOW);

digitalWrite(BUZZER_PIN, HIGH); }

else{

digitalWrite(LED_PIN, LOW);

digitalWrite(LED_PING, HIGH);

digitalWrite(BUZZER_PIN, LOW);}

digitalWrite(trigPin,LOW);

delayMicroseconds(2);

digitalWrite(trigPin,HIGH);

delayMicroseconds(10);

digitalWrite(trigPin,LOW);

duration = pulseIn(echoPin, HIGH);

distance = duration*0.034/2;

return distance;

}}

16
Processing Code

import processing.serial.*;

import java.awt.event.KeyEvent;

import java.io.IOException;

Serial myPort;

String angle="";

String distance="";

String data="";

String noObject;

float pixsDistance;

int iAngle, iDistance;

int index1=0;

int index2=0;

PFont orcFont;

void setup() {

size (1200, 700);

smooth();

myPort = new Serial(this, "COM3", 9600);

myPort.bufferUntil('.');

void draw() {

fill(98, 245, 31);

noStroke();

fill(0, 4);

rect(0, 0, width, height-height*0.065);

17
fill(98, 245, 31);

drawRadar();

drawLine();

drawObject();

drawText();

void serialEvent (Serial myPort) {

data = myPort.readStringUntil('.');

data = data.substring(0, data.length()-1);

index1 = data.indexOf(",");

angle= data.substring(0, index1);

distance= data.substring(index1+1, data.length());

iAngle = int(angle);

iDistance = int(distance);

void drawRadar() {

pushMatrix();

translate(width/2, height-height*0.074);

noFill();

strokeWeight(2);

stroke(98, 245, 31);

arc(0, 0, (width-width*0.0625), (width-width*0.0625), PI, TWO_PI);

arc(0, 0, (width-width*0.27), (width-width*0.27), PI, TWO_PI);

arc(0, 0, (width-width*0.479), (width-width*0.479), PI, TWO_PI);

arc(0, 0, (width-width*0.687), (width-width*0.687), PI, TWO_PI);

18
line(-width/2, 0, width/2, 0);

line(0, 0, (-width/2)*cos(radians(30)), (-width/2)*sin(radians(30)));

line(0, 0, (-width/2)*cos(radians(60)), (-width/2)*sin(radians(60)));

line(0, 0, (-width/2)*cos(radians(90)), (-width/2)*sin(radians(90)));

line(0, 0, (-width/2)*cos(radians(120)), (-width/2)*sin(radians(120)));

line(0, 0, (-width/2)*cos(radians(150)), (-width/2)*sin(radians(150)));

line((-width/2)*cos(radians(30)), 0, width/2, 0);

popMatrix();

void drawObject() {

pushMatrix();

translate(width/2, height-height*0.074);

strokeWeight(9);

stroke(255, 10, 10);

pixsDistance = iDistance*((height-height*0.1666)*0.025);

// limiting the range to 40 cms

if (iDistance<40) {

line(pixsDistance*cos(radians(iAngle)), -pixsDistance*sin(radians(iAngle)),(width-
width*0.505)*cos(radians(iAngle)), -(width-width*0.505)*sin(radians(iAngle)));

popMatrix();

void drawLine() {

pushMatrix();

strokeWeight(9);

19
stroke(30, 250, 60);

translate(width/2, height-height*0.074);

line(0, 0, (height-height*0.12)*cos(radians(iAngle)), -(height-


height*0.12)*sin(radians(iAngle)));

popMatrix();

void drawText() {

pushMatrix();

if (iDistance>40) {

noObject = "Out of Range";

} else {

noObject = "In Range";

fill(0, 0, 0);

noStroke();

rect(0, height-height*0.0648, width, height);

fill(98, 245, 31);

textSize(25);

text("10cm", width-width*0.3854, height-height*0.0833);

text("20cm", width-width*0.281, height-height*0.0833);

text("30cm", width-width*0.177, height-height*0.0833);

text("40cm", width-width*0.0729, height-height*0.0833);

textSize(40);

text("N_Tech ", width-width*0.875, height-height*0.0277);

text("Angle: " + iAngle +" ", width-width*0.48, height-height*0.0277);

20
text("Distance: ", width-width*0.26, height-height*0.0277);

if (iDistance<40) {

text(" " + iDistance +" cm", width-width*0.225, height-height*0.0277);

textSize(25);

fill(98, 245, 60);

translate((width-width*0.4994)+width/2*cos(radians(30)), (height-height*0.0907)-
width/2*sin(radians(30)));

rotate(-radians(-60));

text("30", 0, 0);

resetMatrix();

translate((width-width*0.503)+width/2*cos(radians(60)), (height-height*0.0888)-
width/2*sin(radians(60)));

rotate(-radians(-30));

text("60", 0, 0);

resetMatrix();

translate((width-width*0.507)+width/2*cos(radians(90)), (height-height*0.0833)-
width/2*sin(radians(90)));

rotate(radians(0));

text("90", 0, 0);

resetMatrix();

translate(width-width*0.513+width/2*cos(radians(120)), (height-height*0.07129)-
width/2*sin(radians(120)));

rotate(radians(-30));

text("120", 0, 0);

resetMatrix();

21
translate((width-width*0.5104)+width/2*cos(radians(150)), (height-height*0.0574)-
width/2*sin(radians(150)));

rotate(radians(-60));

text("150", 0, 0);

popMatrix();

22

You might also like