Building a distance measurement device

Let's build an exciting project by combining an Ultrasonic Sensor with a 16x2 LCD character display to build an electronic distance measurement device. We will use one of the most easily available 9-volt batteries for powering this standalone device prototype.

For building the distance measurement device, the following parts will be required.

  • Arduino Uno R3
  • USB connector
  • 1 pc. 9 volt battery
  • 1 full sized bread board
  • 1 HC-SR04 ultrasonic sensor
  • 1 pc. 16x2 LCD character display
  • 1 pc. 10K potentiometer
  • 2 pcs. 220 ohms resistor
  • 1 pc. 150 ohms resistor
  • Some jumper wires

Before we start building the device, let's understand what the device will do and the various parts involved in the device. The purpose of the device will be to be able to measure the distance of an object from the device. The following diagram depicts the overview of the device:

Figure 3 - A standalone distance measurement device overview

First, let's quickly understand each of the components involved in the preceding setup. Then, we will jump into hands-on prototyping and coding. The ultrasonic sensor model used in this example is known as HC-SR04. HC-SR04 is a standard commercially available ultrasonic transceiver.

A transceiver is a device that is capable of transmitting as well as receiving signals. The HC-SR04 transceiver transmits ultrasonic signals. Once the signals hit an object/obstacle, the signals echo back to the HC-SR04 transceiver. The HC-SR04 ultrasonic module is shown below for reference.

Figure 4: The HC-SR04 Ultrasonic module

The HC-SR-04 has four pins. The usage of the pins is explained below for easy understanding:

  • Vcc: This pin is connected to a 5 volt power supply
  • Trig: This pin receives digital signals from the attached microcontroller unit in order to send out an ultrasonic burst
  • Echo: This pin sends the measured time duration proportional to the distance travelled by the ultrasonic burst
  • Gnd: This pin is connected to the ground terminal

The total time taken for the ultrasonic signals to echo back from an obstacle can be divided by 2 and then based on the speed of sound in air, the distance between the object and the HC-SR04 can be calculated.

We will see how to calculate the distance in the sketch for this device prototype. As per the HC-SR04 data sheet, it is a 5-volt tolerant device, operating at 15 mA, and has a measurement range starting from 2 centimeters to a maximum of 4 meters. The HC-SR04 can be directly connected to the Arduino board pins.

The 16x2 LCD character display is also a standard commercially available device, with 16 columns and 2 rows. The LCD is controlled by its 4 data pins/lines. We will also see how to send string outputs to the LCD from the Arduino sketch.

The power supply being used in today's example is a standard 9-volt battery plugged in to Arduino's DC IN Jack. Alternatively, another option is to use 6 pieces of either AA-sized or AAA-sized batteries in series and plug them into the VIN pin of the Arduino board.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.182.66