top of page
20210504_223952 (1).jpg

Ultrasonic Distance Meter

Group members: Joel Osuna, Steven Magayanes

This was a free project, meaning we were allowed to create anything mechatronic. We decided to use a sensor to measure distance and display that measurement on an LCD. Although simple, our project is a very marketable idea that serves many purposes.

Requirements

As all engineering work, this project had a lot of constraints and requirements. In this section we will summarize the basic set of requirements that were given to complete this project.

 

  1. Must have the following three components

    1. At least one sensor

    2. At least one microcontroller

    3. At least one actuator

  2. Must contain at least one subsystem

  3. All components must be utilized and modeled as either an open loop or a closed loop control system. In other words, the sensor input data must be read by the microcontroller to control the actuator.

 

  1. It must be able to do something useful, entertaining, or interesting

  2. Must be a group effort. Teams may separate into smaller groups if it can be shown that this can benefit the project. You must be able to discuss any changes with the lab group and communicate then changes with the professor via email with all original team members cc’d. Include the reason why a smaller/different team would benefit the project outcome.

Proposal

Living during a pandemic and all, public health agencies such as the CDC have a set of recommended guidelines to help prevent the spread of Covid-19. These include, wearing a facemask in public, washing your hands often, avoid large gatherings, etc., however, for this project we wanted to focus on the social distancing guideline, where the CDC recommends that we maintain a safe distance of at least 6 ft, however, this can sometimes be difficult to measure. For our project we thought of making a sensor that measures the distance between any physical objects and displays that distance on an LCD screen. An ultrasonic sensor would be used to measure the distance between it and a physical object, while the LCD screen could display the distance measured. The measured distance would have to be displayed in both feet and meters in order to accommodate different measurement systems. Something like this could also be useful to people with physical disabilities such as the blind and the deaf. 

 

The basis of our proposed project is to create something that could be useful in times like the ones were living in now. Something that could create some sort of accurate measurement to meet the required CDC social distancing guidelines. In addition, a sensor that measures distance can be quite useful for other things. The figure below is a simple schematic of what we tried to create in this project.

usdm.JPG
usdm.JPG

Circuit Design and Component Selection

Knowing the idea we had for our project, we had to come up with something that could not only meet the requirements but also perform in the way we wanted it to. The requirements clearly stated the need for three different components, which are a sensor, a microcontroller, and an actuator so we tried our best to fit all those components into our project. 

 

According to lecture 21, a sensor is a part of a mechatronic or measurement system that can detect some kind of magnitude of a physical state and then transforms it into a signal that can be processed by the electronic system. The Arduino kit came with several different sensors, including a thermistor, a photoresistor, a temperature and humidity module, etc., however, the only sensor we could use for our project was the ultrasonic proximity sensor. An ultrasonic proximity sensor is a sensor that uses ultrasonic waves to detect objects and it works by sending out a pulse that is then sent back. The time it takes between sending and receiving the sound signal is what is used to find the distance between the sensor and the object in front of it. In our case, this type of sensor suited us perfectly since the whole purpose of our project was to measure the distance between objects. The transmitter(trig) that sends the signal is connected to pin 9, the transmitter(echo) that receives the signal is connected to pin 10, the sensor ground(gnd) is connected to the ground on the breadboard, and the sensor source(Vcc) is connected to the breadboard 5 V.

 

In our project, the microcontroller portion would be the Arduino. It is the basic processor in our circuit, where the code that would set the function is read. We essentially don't require having a power supply module since the Arduino microcontroller serves as both our source(5V) and our ground. We decided to use digital pins 10, 9, 7, 6, 5, 4, 2, and 1.

 

Another key component in our project was the LCD1602 module, which is essentially a screen that would display the sensor measurements in both standard and metric units. This component was key in achieving our goal of having a circuit that could accurately display distance measurements. In order for the LCD to work we had to do some research in using the LiquidCrystal library in our Arduino code. By using this library, we wanted to be able to set up a code where the Arduino could display the desired measurements on the LCD screen.

 

Lastly, the circuit also includes a 100 kΩ rotary potentiometer that essentially adjusts the resistance of the circuit. We did not specifically intend for it to serve as a kind of on/off button, however, with a high resistance provided by the potentiometer the screen would display nothing, basically turning it off. This component is especially useful to provide a changing resistance which we could adjust to brighten or darken the LCD screen.

The following is a complete list of components used in our circuit

  • 1x UNO R3 Microcontroller

  • 1x Ultrasonic Proximity Sensor

  • 1x LCD1602 Module(with pin header)

  • 1x 100 kΩ Rotary Potentiometer

  • 12x Female to Male Dupont wire

  • 8x Male to Male Wire

  • 1x 830 Tie- Points Breadboard

 

Figure 2 below is a digital schematic of the circuit created using Tinkercad. All the components previously mentioned are present in the schematic. We tried to create this in order to find a basic idea of how the components would be placed on our physical circuit. Once we decided on the final arrangement of our components, we could simulate the circuit along with the code. Although the wiring is quite messy, using this type of simulation really helped us set up the physical circuit.

Control System Design

usdm 2.JPG
usdm 3.JPG

The block diagram shows the open-loop controller where the moving object is detected by the sensor, the microcontroller or Arduino sets the function of the data perceived on the LCD which in our case was meters and feet, and finally our output is the printing of the data in the LCD showing users the distance. 

​

An ultrasonic proximity sensor relies on the sound waves bouncing back on an object in order to process and measure the distance. Meaning that the sensor serves as both an input and output. It is what sends and receives the signal that ultimately determines or measures the distance. In more basic terms, the sensor transmits a signal that bounces back to the receiver, that signal then travels back to the microcontroller and sequentially to the LCD screen.

20210505_220449 (1).jpg

Physical Circuit

Our physical circuit was very similar to what we envisioned. We used all of the components that were specifically listed on section 2.1. In the initial physical circuit, we tried using a 10 kΩ potentiometer, however we could not get it to properly work. Instead we decided to use the metal 100 kΩ potentiometer, which seemed to fit in our circuit perfectly. Similarly to the circuit design on Tinkercad, our physical circuit ended up being quite messy with the wiring, but in hindsight it's a minor inconvenience that can always be fixed. 

 

The physical circuit did exactly what we intended it to do. It measured the distance between the sensor and anything in front of it, however we did encounter some issues, especially with the LCD screen. Some of the times we tested the sensor, it would not properly display the units of the measurements. Sometimes it would display ‘’mm” instead of “m” or “ftt” instead of just “ft”. Another problem we encountered was that sometimes the measurement displayed would flicker and change many times, making it difficult to read. We also found that the potentiometer could essentially dim or clear anything on the LCD screen, however, it wouldn't completely turn off the screen.

 

Overall the physical circuit was constructed in such a way that it remained sufficiently organized to perform its function. We intend the circuit to be placed in some sort of case that could be easy to carry and use. The LCD could be somewhere on the outside, while only the speaker part of the sensor is exposed. Everything else, including the battery could be inside this case. Figure X is a brief Solidworks assembly where we showcase the idea we had for the casing.

Arduino Code

usdm 4.JPG
usdm 5.JPG
20210504_223952 (1).jpg

Equally important to the components that made up our circuit, is the code that made it perform its intended function. As previously mentioned we had to use a liquidCrystal library in order to make our LCD work. This is in the first line of the code with “#include <LiquidCrystal.h>”, which is set by going to the “sketch” menu then “Include Library” and selecting the “LiquidCrystal” library. We essentially set pins 1, 2, 4, 5, 6, and 7, which is why the function is set as “LiquidCrystal lcd(1, 2, 4, 5, 6, 7)”. These parameters are set to represent  rs, enable, d4, d5, d6, and d7 respectively. We also had to use seval LCD functions that only work along with the LiquidCrystal library. These include “lcd.begin”, “lcd.setCursor” and “lcd.print”. The “lcd.begin” function starts the LCD screen and sets the width and length of the display. The “setCursor” syntax is used to move the LCD cursor, while the “print” syntax is used to print sequential character strings or number sequences. One of the cons of our code is that it is unable to display distances in non-whole numbers, so when trying to find the distance between the sensor and something that is under a meter, the LCD will display a zero as the distance. The smaller the units, the more accurate so we could change the code to measure in centimeters and inches, however, for what we intend the apparatus to be used for, meters and feet are a much more viable form of measurement.

 

In order to be able to use a sensor that is based on sending and receiving sound waves in order to measure a certain distance, we had to create an equation that would transform the sensor measurement into a distance measurement that could be displayed on the LCD. When creating this equation we had to consider the speed of sound in both meters and feet, as well as the fact that the sensor sends and receives a sound wave. In addition to this we had to take into account that the time delay set in the code is in microseconds The following is the basics of the equations used in the code of our project.

 

  • Variables to consider

    • Speed of sound

      • In meters → 343 m/s

      • In feet → ~1125 ft/s

    • Distance

      • Must be divided by 2 because the sensor signal travels forward onto the object and sequentially travels back.

      • Without dividing by two, the sensor would measure the distance that the signal traveled to and back.

    • Time

      • The delay is in microseconds → 11,000,000 sec 

  • The equations

    • To measure the distance in meters

      • dMeter=(dSensor)(11,000,000sec)(343 m/sec)(1/2)

    • To measure the distance in feet

      • dFeet=(dSensor)(11,000,000sec)(1125 ft/sec)(1/2)


Below is a detailed explanation of each of our lines of code. It is important to understand our code in order to understand our circuit so here we display our code and present a guide to better understand it. Everything in purple is the basic explanation of what that line of code is supposed to do.

usdm code.JPG

Conclusion

This was a neat project that had reintroduced some lessons built off of previous labs. We see that different complex components can be easily utilized with imported libraries. With the  ultrasonic sensor HC SR04, we used the SR04 library while in the project, we used the LiquidCrystal library for the LCD 1602 component. This was a key contributor to what our project was about in printing the distance to give people general knowledge of their spacing. A simple lesson taught in this project was using the Arduino as its own power source with the 5V and ground. Overall, we are content with the outcome of the project as we got the system to function properly. 

Ultrasonic Distance Meter Report

© 2022 by Joel E Osuna.

bottom of page