# Sonar Test Plan

519

12

2

Published

## Introduction: Sonar Test Plan

The goal of this test plan is to determine whether a door is open or closed. This test plan will show you how to build a sonar sensor, create a program, calibrate the sensors, and eventually to find out if the door to the chicken coop in our school's garden is open or not.

## Step 1: Materials

“Jumper Wires.” Exploring Arduino, 23 June 2013, www.exploringarduino.com/parts/jumper-wires/.

Macfos. “Arduino Uno R3 with Cable.” Robu.in | Indian Online Store | RC Hobby | Robotics, robu.in/product/arduino-uno-r3/.

Nedelkovski, Dejan. “Ultrasonic Sensor HC-SR04 and Arduino Tutorial.”HowToMechatronics, 5 Dec. 2017, howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/.

You will need:

Computer with Arduino and Excel SpreadSheets

USB cable

Arduino Uno Microcontroller

Sonar Sensor (HC-SR04)

Arduino Wires

Ruler

## Step 2: Connecting the Circuit

“Fritzing.” Project – HC-SR04 Project, fritzing.org/projects/hc-sr04-project.

Make sure that:

the wire on the VCC pin connects to the 5V

the wire on the Trig pin connects to pin 8

the wire on Echo pin connects to pin 9

the wire on GND connects to Ground

NOTE: You can connect the wires directly to the arduino instead of having wires in the arrangement above.

## Step 3: Creating the Program

This code reads a value from the Sonar sensor, duration, which represents how long it took for the sound to bounce off of an object and return back to the Sonar sensor.

We will use this code to calculate the values presented from the echo, and then graph that information on an excel sheet in order to get the slope, and eventually the calibration curve, which we will use in the program later instead.

## Step 4: Collection of Data and Calibration

The values we got above were by measuring with a ruler the distance between an object and the sensor, and we wrote down the value that showed up on the serial monitor. We measured by every .5 inches.

Using the data from the excel spread sheet, create a scatter-plot graph in which the x-axis is duration in milliseconds and the y-axis is distance in inches.

After creating the graph, create a calibration curve by clicking on the graph, and selecting Linear Trendline under the Layout in the Chart Tools section.Under Trendline options, select Linear, and select the option that says "Display Equation on Chart".

The equation will show up and we will use that equation for future code to be able to determine how far an object is in inches.

## Step 5: Creating a New Code Using Our Equation

We used the above code with the equation that we got from the calibration curve in the past slide. This equation converts milliseconds to inches.

## Step 6: Final Code!

This code is the final code that will let us know whether the door is open or not, based on the distance the Sonar reads. For our test, we measured that if the Sonar read that the door was more than 14 inches away, that meant that the door was open, the Serial Monitor would then print "Door is open."

## Step 7: Results

Overall, the sensor was accurate. There were a few limitations.The few downsides we experienced were that the sensor read values in a cone shape infront of it, sensor was very sensitive,objects at short distances displayed strange values,and values beyond 14 inches were not accurate. We had to ensure that the sensor was at the same elevation as the object we wanted to measure the distance from, in this case, the door, but it served its function.

## Recommendations

• ### Arduino Class

70,925 Enrolled

## 2 Discussions

Nice instructable! Its good to see someone using regression analysis to verify accuracy of their data! Don't forget to show the coefficient of regression (R^2) on your trend line equation.

Good first instructable, thanks for sharing! :)