0% found this document useful (0 votes)
35 views24 pages

Minor Final

This document outlines a project involving a radar system controlled by an Arduino, utilizing an ultrasonic sensor and a servo motor to detect objects within a specified range. The system provides visual data representation through the Processing IDE, displaying the distance and angle of detected objects. The project aims to develop a cost-effective object detection system applicable in various fields such as navigation and mapping.

Uploaded by

Akshat Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views24 pages

Minor Final

This document outlines a project involving a radar system controlled by an Arduino, utilizing an ultrasonic sensor and a servo motor to detect objects within a specified range. The system provides visual data representation through the Processing IDE, displaying the distance and angle of detected objects. The project aims to develop a cost-effective object detection system applicable in various fields such as navigation and mapping.

Uploaded by

Akshat Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Abstract

This project is about Radar System controlled via Arduino. This Radar system consists of an Ultrasonic Sensor and Servo
Motor, these are the major components of the system. Basic working of the system is that it have to detect objects in its
defined range. Ultra-sonic sensor is attached to the servo motor it rotates about 180 degree and gives visual
representation on the software called processing IDE. Processing IDE gives graphical representation and it also gives
angle or position of the obzject and distance of the object. This system is controlled through Arduino. Arduino UNO
board is sufficed to control ultrasonic sensor and also to interface the sensor and display device. While researching, we
learned about existing navigation and obstacle detection innovations and different systems where ultrasonic sensors are
used efficiently. Main application of this RADAR system comes into different field of navigation, positioning, object
identification, mapping, spying or tracking and different applications. These less investment system are also suitable for
indoor applications.
Table of Contents
1.Abstract

2.Acknowledgement

3.Introduction

4.History

5.Project Aim

6.Hardware Requirements

7.Software Requirements

8.Description of the Hardware Requirements

9.Methodology

10. Connections
11.Working

12.Discussion and Result

13.Pros and Cons

14.Application

15.Conclusions

16.References

Appendix A

Appendix B
Chapter 1

1.1 Introduction
RADAR system is an object detection or tracking system which uses radio waves to decide or get the range, height,
heading, or speed of items or objects. Radar frameworks or system arrive in an assortment of sizes and have distinctive
performance particulars. Some radars are utilized for aviation authority at air terminals and others are utilized for long
range observation and early cautioning frameworks . There are some ways to show radar working data. There are also
some modified radar systems which have advance technology of handling the systems. These modified system are used
at higher levels to get or extract the helpful or important data . Our proposed system’s working principle is linked by the
following components which are is ultra-sonic sensor connected to the microcontroller (we have chosen Arduino) digital
input and output pins. Then we have servo motor which is also connected to digital output and input pins. Our both
main components ultra-sonic sensor and servo motor are connected simultaneously, so that when our servo motor
rotates from 0 degree to 180 degree from extreme right to extreme left the motor will rotate nearby its axis . We utilize
Computer screen to demonstrate the data (distance and angle) through software called “Processing development
Environment”.

1.2 History

It is a common assumption that radar is a by-product of World War II, brought about by military necessity. According to
Hiser (Radar Meteorology, Third Edition, 1970), this is true only to the extent that the war produced radar equipment in
great quantities suitable for practical use. Actually, the fundamental principle underlying all radars was first observed in
1886 by the physicist Heinrich Hertz when he found that electromagnetic waves could be reflected from various objects,
and even focused into beams by appropriate reflectors.

In 1904, a German engineer, Hulsmeyer, was granted a patent in several countries on a proposed method of using
electromagnetic waves in an obstacle detector and navigation aid for ships. In 1922, Marconi urged the use of "short
waves" for radio detection. From these beginnings, radar gradually evolved; it was not a science which was suddenly
discovered. Various experimenters in electromagnetic waves during the following years reflected these waves from the
upper atmosphere, and verified the existence of a series of ionized layers known as the ionosphere.

1.3 Project Aim


The aim of the project is to design and develop an object detection system which could determine the presence of
objects in its vicinity.
Chapter 2

2.1 Hardware Requirements


1. Microcontroller Board- Arduino UNO
2. Jumper Wires
3. Connecting Wires
4. Sensor- HC-SR04 Ultrasonic Sensor
5. Actuator – Micro-Servo Motor
6. Display Device (Laptop)

2.2 Software Requirements


1.Arduino IDE

2.Processing IDE
2.3Description of HardwareRequired
2.3.1 The Arduino UNO

Arduino is an open source electronics platform for fast prototyping of projects for users with minimal knowledge or
experience in electronics and programming. We have used the Arduino UNO, the most widely used variant of the
Arduino.

Technically, Arduino Uno is a microcontroller board based on the 8-bit

ATMega328P microcontroller. With 14 digital input/output pins (including 6 PWM outputs), 6 Analog inputs, a 16 MHz
ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button, it has everything needed to
support the microcontroller, we simply have to connect it to a computer with a USB cable or power it with a AC-to-DC
adapter or battery to get started. Arduino also comes with the Arduino IDE, in which we can write code and upload to
the

Arduino. The programming language used for an Arduino, called the Arduino Programming language, is very similar to
C/C++ except that we can use inbuilt functions of the Arduino libraries which keep the code very simple and short

Why Arduino?
We had the following reasons strongly backing our decision to choose the Arduino UNO Support - Thanks to its simple
and accessible user experience,

Arduino has been used in thousands of different projects and applications. The Arduino software is easy-to-use for
beginners, yet flexible enough for advanced users. It runs on Mac, Windows, and Linux. This has enabled a very large
support base for Arduino, more than any other microcontroller board ever released in the market. Every problem/bug/
question that we ever had throughout the course of this project was promptly answered by questions in online forums,
as there was a very high probability that scores of people had already posted the same question and the issue was
resolved by other experienced users.
Microcontroller ATmega328P(8-bit)

Operating Voltage (DC)5V

Input Voltage (recommended) 7-12V; (limits) 6-20V

Digital I/O Pins 14(of which 6 provide PWM output)

Analog Input Pins 6

DC Current per I/O Pin 40mA

DC Current for 3.3V pin 50mA

Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader

SRAM 2 KB (ATmega328)

EEPROM 1 KB (ATmega328)

Clock Speed 16MHz

Need of External Programmer NO

Built-in-LED pin 13

Length 68.6 mm

Width 53.4mm

Weight 25 g

Table 1.1: Features of Arduino UNO

Cost Effective - The Arduino UNO, its basic variant that every beginner to embedded systems usually starts with, is
available for less than $25. Being an open source hardware and due to its simplicity, it is easily and widely replicable,
which is also responsible for the growth of such a large community as mentioned in the earlier reason.

Features - It is generally observed that the computing power and inbuilt memory of the Arduino easily supports a wide
variety of circuits with multiple components along with continuous serial communication with another device/computer.
Compared to the system configuration of the board, our project would require fairly low amount of resources.

The no. of GPIO pins on the UNO is more than sufficient considering the need for the circuitry in our project, as we shall
see when we look at the pinouts of the servo motor and the sensor - the only two other devices being used in the
project.

One important advantage of using the UNO is that unlike most previous programmable circuit boards, the Arduino UNO
does not need a separate piece of hardware (called a programmer) in order to load new code onto the board - we can
simply use a USB cable. The ATmega328 on the Arduino Uno comes pre- programmed with a bootloader that allows us to
upload new code to it without the use of an external hardware programmer.

Moreover, the components we have used work under the same operating voltage and current conditions as an Arduino,
especially considering the fact that such components are nowadays sold with their compatibility with Arduino in mind.

Considering the above factors, we found Arduino UNO to be the most appropriate microcontroller board to work with for
this project.

Operation of Arduino
Once a program written for an Arduino, called a "Sketch is uploaded to the board via the Arduino IDE, the Arduino
environment performs some small transformations to make sure that the code is correct C/C++. It then gets passed to a
compiler, which turns the human readable code into machine readable instructions (object files). Then, the code gets
combined with (linked against) the standard Arduino libraries that provide basic functions like digitalWrite() or
Serial.print(). The result is a single Intel lex file, which contains the specific bytes that need to be written to the program
(flash) memory of the chip on the Arduino board. This file is then uploaded to the board: transmitted over the USB or
serial connection via the bootloader already on the chip or with external programming hardware.

2.3.2 The HC-SR04 Ultrasonic Sensor

Figure 1.2: HC-SR04 Ultrasonic sensor

The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats or dolphins do. It offers non-
contact range detection from 2cm to 400 cm or 1" to 13 feet. It's operation is not affected by sunlight or black material
like sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete
with ultrasonic transmitter and receiver module. The human ear can only detect sounds between 2012-20kHz. The sound
waves beyond 20kHz are called ultrasonic waves or ultrasound. The principle of ultrasonic distance measurement uses
the velocity of ultrasonic waves spreading in air, measuring the time from launch to reflection when it encounters an
obstacle. We then calculate the distance between the transmitter and the obstacle according to the time and the
velocity. Thus, the principle of ultrasonic distance measurement is the same as with a radar.
Features

Electrical Parameters HC-SR04 Ultrasonic module

Operating Voltages (DC)5V (4.5-5.5V)

Quiescent Current(inactivity) 2mA (1.5-2.5 mA)

Working Current 15mA (10-20 mA)

Operating Frequency 40KHz (Ultrasonic)

Farthest range 4m

Nearest range 2cm

Resolution 0.3cm

Measuring angle 15 degrees

Input trigger signal 10us TTL pulse

Output echo signal Output TTL level signal, proportional with range

Dimensions 45*20*15 mm

Since the sensor considers the distance to an obstacle that reflects the ultrasonic wave, we cannot use it to make
trustworthy measurements of the position of moving objects. This is majorly due to the fact that this sensor works on
the principle of transmitting a set of pulses and receiving their reflection, before transmitting again, as we shall see later.

Hence, there is no way that we can continuously track the position of an object with such a sensor. As far as we know,
that can only be done by some type of a camera, which would've introduced the concepts of computer vision and taken
us beyond the scope and costs of the current project

2.3.3 HC-SR04 : Pin Definitions


. Vo - 5V Power Supply
Trig - Trigger Pin (Input)
Echo - Receive Pin (Output)
GND - Power Ground

The Trig and Echo pins are used for transmission and reception of ultrasonic waves, respectively.

Operation of the HC-SR04

The timing diagram of HC-SR04 is shown in Figure 13. To start measurement, Trig of SR04 must receive a HIGH pulse (5V)
for at least 10us, which will initiate the sensor to transmit 8 cycles of ultrasonic burst at 40kHz. It then waits for the
reflected ultrasonic wave. When the sensor detects the ultrasonic wave through the receiver, it will set the Echo pin to
HIGH (5V), for as long as it detects an incoming ultrasonic pulse at the receiver. Calculation of distance
The delay between transmission and reception of the final pulse (i.e., between when the Trig pin is set back to LOW and
when the Echo pin turns HIGH) is a time period proportional to the distance travelled by it. To obtain the distance, we
start a counter the moment the Trig pin is set to LOW which keeps counting till the microcontroller detects a HIGH pulse
at the Echo pin. Time = Width of pulse, in us (micro second).

• Distance in centimetres = Time / 58 • Distance in inches = Time / 148 as mentioned in its datasheet. We can also utilize
the speed of sound, which is 340m/s in a generic case.

2.3.4 Micro-Servo Motor


We had to use a servo motor in order to rotate the HC-SR04 and give it a wider field of view over the area around it. This
Micro-Servo can rotate approximately

180 degrees (90 in each side) with an operating speed of 0.1s/60degrees. Moreover, it has an operating voltage of
4.8V(5V) which is in the same range as of the Arduino UNO.

Other details:

Weight: 9 g
Dimension: 22.2 x 118 x 31 mm approx.
Stall torque: 18 kgf.cm
Operating speed: 0.1 s/60 degrees
Operating voltage: 4.8 V (5V)
Deadband width: 10 us (The servo will not move so long as subsequent commands to it are within the deadband
timing pulse width)
Temperature range: 0-55C

The Micro-Servo has a signal pin to which the Arduino sends the value of angle that it should turn to.

Pins of micro-servo motor


The Ultrasonic Sensor was mounted on top of it and the apparatus connected to the Arduino was kept in a modified
transparent plastic case.

2.3.5 Jumper wires


A jump wire (also known as jumper wire, or jumper) is an electrical wire, or group of them in a cable, with a connector or
pin at each end (or sometimes without them – simply "tinned"), which is normally used to interconnect the components
of a breadboard or other prototype or test circuit, internally or with other equipment or components, without soldering.
Individual jump wires are fitted by inserting their "end connectors" into the slots provided in a breadboard, the header
connector of a circuit board, or a piece of test equipment.

Types

Female- female jumper wire

There are different types of jumper wires. Some have the same type of electrical connector at both ends, while others
have different connectors. Some common connectors are:

Solid tips – are used to connect on/with a breadboard or female header connector. The arrangement of the elements and
ease of insertion on a breadboard allows increasing the mounting density of both components and jump wires without
fear of short-circuits. The jump wires vary in size and colour to distinguish the different working signals.

Crocodile clips– are used, among other applications, to temporarily bridge sensors, buttons and other elements of
prototypes with components or equipment that have arbitrary connectors, wires, screw terminals, etc.

Banana connectors – are commonly used on test equipment for DC and low- frequency AC signals.

Registered jack (RJnn) – are commonly used in telephone (RJ11) and computer networking (RJ45).

RCA connectors– are often used for audio, low-resolution composite video signals, or other low-frequency applications
requiring a shielded cable.

RF connectors – are used to carry radio frequency signals between circuits, test equipment, and antennas.
RF jumper cables - Jumper cables is a smaller and more bendable corrugated cable which is used to connect antennas
and other components to network cabling. Jumpers are also used in base stations to connect antennas to radio units.

Usually the most bendable jumper cable diameter is 1/2".


Chapter 3
3.1 Methodology
In order to testify the working of this system, after its designing, construction and programming we placed few objects in
front of the ultrasonic sensor. As the motor started to rotate, our monitor started to display the output through
processing IDE. Hence, when the sensor crossed over the object it showed a red segment with the distance and angle
where the object is paced. The first object was placed at the distance of 30.5cm measured through a ruler and the
system measured the distance at 32cm.While the second object was placed at a distance of 20 cm and the system
measured it as 21cm. Hence the calculated efficiency turned out to be 95%.

System Overview:

System hardware description

The above figure represents a brief overview of this radar system. Here, as it is shown the controller we are using is
Arduino, with the input Ultrasonic sensor and the output is the servo motor which rotates 180 degrees. The
microcontroller controls all the operations of this system, from rotation of the motors to the obstacle detection of the
ultrasonic and representation of the result on the screen.
System block diagram:

Figure represents the system’s block diagram. Here, it can be seen how the work flow in this radar system. The sensor is
going to sense the obstacle and determine the angle of incident and its distance from the radar. The servo motor is
constantly rotating to and fro, hence making the sensor move. The data obtained is encoded and fed to the processing
IDE which represents it on the screen. The results are displayed further in this paper. All these operation are done by
Arduino microcontroller from the rotation of the servo, data collection from the sensor, feeding the data to encoder to
transferring it to the display.
3.2 Connections
For Ultrasonic Sensor:

1. VCC =>> Vin 2. TRIG =>> 8th pin 3. ECHO =>> 9th pin 4. GND =>> GND
For Micro-Servo Motor:
1.VCC =>> 5V 2. SIGNAL =>>10th pin 3. GND =>> GND

3.3 Working
The basic objective of our design is to ascertain the distance position and speed of the obstacle set at some distance
from the sensor. Ultrasonic sensor sends the ultrasonic wave in various ways by rotating with help of servo motors. This
wave goes in air and gets reflected back subsequent to striking some object. This wave is again detected by the sensor
and its qualities is analyzed and output is shown in screen indicating parameters, for example, distance and position of
object. Arduino IDE is utilized to compose code and transfer coding in Arduino and causes us to detect position or angle
of servo motor and it is communicated through the serial port alongside the covered distance of the nearest object in its
way. Output of all of this working is shown in the software called processing, it will display the input/output and the
range of the object [4]. Implementations of the sensors are done in such a way that ultra-sonic sensor is attached on top
of the servo motor because it have to detect the object and its distance. Arduino (micro- controller) will control the ultra-
sonic sensor and servo motor and also powered will be given to both of them through micro-controller.
Flow chart of Radar System

The above flow chart explains the working and the decision flow of this framework. As it can be seen the system starts
with an input i.e. when the ultrasonic sensor detects an object, or does not detects any object, at any condition the
encoder feeds the information in the controller while the servo keeps constantly rotating. As soon as any obstacle is
detected by the ultrasonic sensor the data is immediately processed by the controller and is fed to the IDE which shows
it on the display screen. Here the process ends with an estimated distance of the object from the system with the angle
at which it is placed.
Chapter 4
4.1 Discussion and Result
In this project we have mentioned that our system is designed consisting following components such as, a servo- motor,
an ultra-sonic sensor and a micro- controller (Arduino). System’s objective is to track the distance and angle of the object
and to represent this information graphically, means its output should be in graphical form which will be represented
through processing software. We can have an idea of an efficiency of this radar by testing objects at different levels and
observe how faster or smoothly it detects an object that it finds in a way and gives us an expected range of the obstacle.
Following figure show the results of the monitor screen of our design when the sensor rotates through the area and
detects obstacle in the way. The red area indicates the presence of obstacle and below the angle of incident and distance
is being displayed.

Testing of the system:

a. Object 1 is placed 30.5cm far from the radar, radar gives the distance 32 cm, so: error = (32-30.5)/30.5) * 100=
4.918% efficiency 1 = 100-error =95.08%

a. object 2 placed at a distance of 20.3 cm, radar gives the distance 21 cm so:

error = ((21-20.3)/20.3) * 100 = 3.44% efficiency 2 =100-error= 96.55%

After the observations and calculations we can conclude that this system is 95.815% efficient.

4.2 Pros of Radar System


1. It is not affected by colour or transparency. Basically, the Ultrasonic Sensors transmit the sound off of the object,
hence the colour and transparency have no effect on the radar reading.

1. Any dark environments have no effect on this Arduino radar sensor’s detection procedure. So, it can also use at
night.

1. Easy to design and low price. The ultrasonic sensors are available at the market with very cheap price.

1. It has high frequency, high sensitivity, therefore, it can easily detect the external or deep objects.
2. This radar sensor is not affected by dust, rain, snow, and many more.

6.It has a self-cleaning system to continue running and less downtime.

1. The Arduino Radar Sensor is easy to use. Also, it is completely safe during the operation to nearby objects, human
or equipment.
1. The Ultrasonic sensor can easily interface with any types of the microcontroller.

4.3 Cons of Radar System

1. The Arduino Radar Sensor conduct sound to continue the work. So, it is not working in a vacuum as there is no air
for the sound to travel through.

1. A very soft fabric can absorb more sound waves. Therefore, it is hard to detect objects which are covered with soft
fabric.

1. If temperature changes of 5 to 10 degree or more then it is the effect on the sensing accuracy. Although this is true
that there have many more temperature compensated sensors available.

1. Another limitation is the detection range. This depends on which Ultrasonic sensor have used to make the Arduino
Radar Sensor.

1. While the radar using for inspection purpose, make sure it should be water resistive. Otherwise highly chances of
damage.
2.
Chapter 5
5.1 Applications

This Radar System have various applications for security purposes and it is mainly used for mapping.

APPLCATION IN AIR FORCE: It is used in airplanes or aircraft machines which have implemented radar system in it to
detect the objects that comes in a way. It is also used to calculate height readings.
APPLICATION IN MARINE: This radar system also used in ships or marine. It is implemented on big ships to calculate
the distance of other boats or ships, with the help of this sea accidents can also be reduced by not colliding. It can
also be implemented on ports to see the distance of other ships and to monitor or control the ship movements.
APPLICATON IN METEROLOGY: Meteorologists also uses radar systems to track or monitor the wind. It has been
become an important equipment for climate testing. For example, to detect tornados, storms.
5.2 Conclusions
Numerous advanced control methods gave designers to have more command over different advanced applications. In
our paper, the recommended mapping method of whole system is assessed on small principles or scale. The field that we
have chosen for our design “Radar System” is a very vast field and future scope of this technology is very high. We have
tremendous applications in which radar system have been implemented or used. There is a lot of future scope of this
design because of its security capacity. It can be used in many applications. This framework can also be developed or
modified according to the rising needs and demand.

As we have designed a short range radar therefore our research was specified and limited. This system can only detect
objects from 0 to 180 degrees only because the servo motor that we have used can rotate only to this range. So, due to
this limitation our design cannot be applied to places or areas for obstacle detection on a larger scale. Usage of a 360
degrees rotating servo motor can make the system more efficient. We look forward to modify this system and enhance
our research work by using a fully 360 degrees rotating servo and a higher ranged ultrasonic sensor. We can further add
features to this system i.e. making it mobile, mounting an alarm system to it which turns on when obstacle is detected.
Further modifications could be an obstacle avoiding robot with surveillance system.

References
1. http://www.arduino.cc/
2. http://www.arduinoproducts .cc/

[3]http://www.atmel.com/atmega328/

[4]http://en.wikipedia.org/wiki/File:16MHZ_Crystal.jpg

1. http//:www.sproboticworks.com/ic%20pin%20configurat ion/7805/Pinout.jpg/
2. http://www.sproboticworks.com/ic%ultrasonicsensor%2 0pinout.jpg
3. http://www.instructables.com/id/ ATMega328-usingArduino-/
4. http://www.google.co.in/imgres/Radar_antenna.jpg&w=

546&h=697&ei=wuuK
Appendix A: Arduino Code
#include <Servo.h>. const int trigPin = 8; const int echoPin = 9; // defining time and distance long duration; int distance;

Servo myServo; // Object servo

void setup() {

pinMode(trigPin, OUTPUT); // trigPin as an Output pinMode(echoPin, INPUT); // echoPin as an Input Serial.begin(9600);


myServo.attach(10); // Pin Connected To Servo

} void loop() {

// rotating servo i++ depicts increment of one degree for(int i=15;i<=165;i++){ myServo.write(i); delay(30);

distance = calculateDistance();

Serial.print(i);

Serial.print(",");

Serial.print(distance);

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(".");

int calculateDistance(){

digitalWrite(trigPin, LOW); delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delayMicroseconds(10);
digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance= duration*0.034/2;

return distance;

}
Appendix B: Processing Code

float pixsDistance; int iAngle, iDistance; int index1=0; int index2=0; PFont orcFont; void setup() {

size (1366, 768); smooth();

myPort = new Serial(this,”COM5″, 9600); // change this accordingly

myPort.bufferUntil(‘.’); // reads the data from the serial port up to the character ‘.’. So actually it reads this:
angle,distance.

} void draw() {

fill(98,245,31);

// simulating motion blur and slow fade of the moving line noStroke(); fill(0,4);

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

fill(98,245,31); // green color

// calls the functions for drawing the radar

drawRadar(); drawLine(); drawObject(); drawText();

void serialEvent (Serial myPort) { // starts reading data from the Serial Port

// reads the data from the Serial Port up to the character ‘.’ and puts it into the String variable “data”. data =
myPort.readStringUntil(‘.’); data = data.substring(0,data.length()-1);

index1 = data.indexOf(“,”); // find the character ‘,’ and puts it into the variable “index1” angle= data.substring(0,
index1); // read the data from position “0” to position of the variable index1 or thats the value of the angle the
Arduino Board sent into the Serial Port

distance= data.substring(index1+1, data.length()); // read the data from position “index1” to the end of the data pr
thats the value of the distance

// converts the String variables into Integer iAngle = int(angle); iDistance = int(distance);

void drawRadar() { pushMatrix();

translate(width/2,height-height*0.074); // moves the starting coordinats to new location

noFill(); strokeWeight(2);

stroke(98,245,31); // draws the arc lines

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);
// draws the angle lines 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); // moves the starting coordinats to new location strokeWeight(9);

stroke(255,10,10); // red color pixsDistance = iDistance*((height-height*0.1666)*0.025); // covers the


distance from the

sensor from cm to

pixels

// limiting the range to 40

cms if(iDistance<40){

// draws the object according to the angle and the

distance line(pixsDistance*cos(radians(iAngle)),-

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

popMatrix();

void drawLine() { pushMatrix(); strokeWeight(9); stroke(30,250,60

);

translate(width/2,height-height*0.074); // moves the starting coordinats to new location line(0,0,(height-


height*0.12)*cos(radians(iAngle)),-(height-height*0.12)*sin(radians(iAngle))); // draws the line according to the
angle popMatrix();

void drawText() { // draws the texts on the screen

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(“Harsh Sharma”, width-width*0.875, height-height*0.0277); text(“Angle: ” + iAngle +” °”, width-
width*0.48, height-height*0.0277); 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();

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();

You might also like