Arduino Uno, Ultrasonic Sensor HC-SR04 Motion Detector with Display of Distance in the LCD

-Motion detection has become one of the great areas of research in the world. Many activities are carried out in the presence of motion. One of the research focus has been the use of Arduino Uno microcontroller, Ultrasonic sensor, passive infrared sensor and many others to sense and measure distances. The goal is to measure and monitor human activity remotely, and using less manpower as much as possible. This study aimed at designing a sensor that can easily measure how far the object is, monitor change of distances as the object approach and display the results in the Liquid Crystal Display (LCD), give a light coded signal and a sound alarm. The hardware utilized included the Arduino Uno on a bread board interfaced with LCD, LEDs, Buzzer and Ultrasonic sensor. The program to run the circuit was developed using Arduino IDE and stored at the memory of the Arduino microcontroller. The study demonstrated that the designed sensor could be used to accurately determine the position of an approaching object and display the distance readings on the LCD. Simultaneously the sensor display visual LED signals set and color coded as for instance, distances less than 150 cm, 70 cm and 40cm corresponding to Green, Blue and Red LED lights respectively, while at the same time producing sound signals n a sound buzzer. Thus, this method of distance sensing and measurement is efficient and assures measurements of small distances precisely. This distance sensing and measurement system can get wide applications where proximity detection is required e.g. in industries and traffic departments.


INTRODUCTION
Population increase, lifestyle changes and economic development has led to increase in human activity and hence high demand of manpower and especially in cities all over the world [1,2]. For example there is increasing need to employ security officers at the gates to monitor the movement of people which might be intruders [3,4], traffic police in highways to monitor traffic, care givers in homes for the old or sick [5], automatic doors [6], washing [7], wireless Sensor-Based Driving Assistant for Automobiles [8,9,10,11,12] and many others. Use of human to sense motions and other human activities is prone to human error and limitations. Some security officers have been found in a serious case of corruption [13], theft from the company and institutions since some guards end up taking some of the company's material home and of which it has led to the fall of various companies like Kenya textile and Mumias sugar company [14].
This among other reasons have necessitated automated sensing that could be recorded for future reference and also remote. Samuel Bango [15] was the first person to invent a motion detector whereby he came up with a burglar alarm in the early 1950s. Doppler Effect is the main principle upon which Bango [15] motion detector is based on. Majority of motion detectors today still employ the same principle for example, use of the Doppler Effect to sense gestures [16]. Other sensors include IR sensors [17,18], ultrasonic sensors [19,20,21] and microwave sensors [22] which by the change in the frequencies they emit they are able to sense motion.
Several researchers have come up with motion detectors techniques to cub insecurity amongst other applications [23,24]. Some researchers have used Passive Infrared (PIR) Sensors [25]. The study by Ervin et al. (2010) [25], used Arduino Uno microcontroller to detect the motion of the object or the intruder. The study was able to alert an observer the presence of an intruder by producing a sound signal using LEDs and Piezo Buzzer. However, they could not display the distance between the intruder/ object and the sensor to the LCD.
A study by Soni et al. (2017) [26], made a motion detector using the ultrasonic sensor and Arduino Uno microcontroller to detect motion and finally their study was finally able to display the distance on the LCD. Their study had some limitation since the sensor in that study had only a visual signal, no sound or recorded signal. This implied that their study could only apply when there is eye focus to the LCD screen.
Another example of the research study used in motion sensor was carried out by Edwards et. al. (2014) [27]. The study was aimed to study a simple harmonic motion detector using ultrasonic distance sensor and the Arduino microcontroller. The study aimed at sensing the motion of objects such as pendulum bob. This was to provide an alternative or automatic study of the simple harmonic motions. The study was successful since the parameters such as determination of force of gravity, g, could be easily measured automatically. However, the study had no other interfaces such as Piezo Buzzer, LCD and LEDs The findings of the mentioned studies in ref. 25,26 and 27 motivated this current study. The aim was to make an attempt on motion detection using Arduino Uno, LEDs, Piezo Buzzer, Ultrasonic sensor and finally give out sound and recorded signals. The study was also to display the records of distances on the LCD. This study aims at designing a Motion detector with distance display at the liquid crystal display and produce sound alarm. The use of Arduino Uno, LCD, LEDs and Piezo Buzzer is cheap since the designing of the circuit is not sophisticated. Arduino is a low-cost and effective [28] microcontroller. It uses readily available and cheap appliances which can easily be found in the electronics dealers. The language needed to program the microcontroller is friendly since it uses a combination of C and C++. Its storage is almost space less since together with its components requires minimal space and can reduce the congestion of workers like those of security men [29]. The Ultrasonic sensor works by producing ultrasound waves that are reflected back after hitting an obstacle. The time taken by the waves to and from the obstacle shall be recorded in the microcontroller [30]. The Piezo Buzzer produces a sound signal while the LCD produces the visual results of the parameter expected (distance).

1) Arduino Uno
The Arduino Uno is an open-source microcontroller board based on the Microchip ATmega328P microcontroller and developed by Arduino [31,32,33]. The board is equipped with sets of digital and analog input/output (I/O) pins that may be interfaced to various expansion boards (shields) and other circuits. The board has 14 digital I/O pins (six capable of PW output), 6 analog I/O pins, and is programmable with the Arduino IDE (Integrated Development Environment), via a type B USB cable. It can be powered by the USB cable or by an external 9-volt battery, though it accepts voltages between 7 and 20 volts. It is also similar to the Arduino Nano and Leonardo. A good example of the Arduino Uno microcontroller is shown in the figure 1.
The word " Uno " means "one" in Italian and was chosen to mark the initial release of Arduino Software [34,35]. The Uno board is the first in a series of USB-based Arduino boards; it and version 1.0 of the Arduino IDE were the reference versions of Arduino, which have now evolved to newer releases. The ATmega328 on the board comes preprogrammed with a bootloader that allows uploading new code to it without the use of an external hardware programmer. While the Uno communicates using the original STK500 protocol, it differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it uses the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USB-to-serial converter.
Arduino Uno microcontroller is full set containing the memory and the I/O serial ports which are used in interfacing it with other devices like LCD, LEDs, Buzzer and many others [36]. Once the program is made in the computer, it is transferred to the Arduino chip using the USB cable. The circuit to be interfaced with the microcontroller is connected to it [37]. Arduino Uno in the circuit controls all the functioning of the attached device and make them operate as per the program Arduino microcontroller has been used by several researchers [25,26] to interface the devices in motion detector with LEDs, Buzzers and LCD.

2) Ultrasonic Sensors
The HC-SR04 ultrasonic sensor (like the one shown in figure 2) uses SONAR to determine the distance of an object just like the bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package from 2 cm to 400 cm or 1" to 13 feet. The operation is not affected by sunlight or black material, although acoustically, soft materials like cloth can be difficult to detect. It comes complete with ultrasonic transmitter and receiver module. The ultrasonic sensor uses the reflection of sound in obtaining the time between the wave sent and the wave received. It usually sent a wave at the transmission terminal and receive the reflected waves. The time taken is used together with the normal speed of sound in air (340ms -1) to determine the distance between the sensor and the obstacle. The Ultrasonic sensor has been used by several researchers [25,26] to sense the movements of the objects as they approach it.

3) Liquid-Crystal Display (LCD)
Liquid-Crystal Display (LCD), shown in figure 3, is a flat-panel display or other electronically modulated optical device that uses the light-modulating properties of liquid crystals combined with polarizers. Liquid crystals do not emit light directly, instead using a backlight or reflector to produce images in color or monochrome. LCDs are available to display arbitrary images (as in a generalpurpose computer display) or fixed images with low information content, which can be displayed or hidden, such as preset words, digits, and seven-segment displays, as in a digital clock. They use the same basic technology, except that arbitrary images are made from a matrix of small pixels, while other displays have larger elements. LCDs can either be normally on (positive) or off (negative), depending on the polarizer arrangement. For example, a character positive LCD with a backlight will have black lettering on a background that is the color of the backlight, and a character negative LCD will have a black background with the letters being of the same color as the backlight. Optical filters are added to white on blue LCDs to give them their characteristic appearance. The Liquid Crystal Display is used to display the distances according to the program in the Arduino microcontroller. It displays the distances in meters or in centimeters as per the set of the study. The LCD has been used in displaying the distances from their research study [26].

4) Piezo buzzers
Piezo buzzers, an example in figure 4, is a simple device that can generate basic beeps and tones. They work by using a piezo crystal, a special material that changes shape when voltage is applied to it. If the crystal pushes against a diaphragm, like a tiny speaker cone, it can generate a pressure wave which the human ear picks up as sound. Simple change the frequency of the voltage sent to the piezo and it will start generating sounds by changing shape very quickly [38]. Piezo Buzzer is also readily available in the market in the most of the electronics dealers. It is a low and costeffective device which has capability of converting mechanical energy into sound energy [39]. When the ultrasonic sensor detects motion of the object, it activates the piezo buzzer which produces the alarmed sound depend on the frequency of the approaching object. It has been used in various motions detectors in producing the sound signals [25].

B. Methods
The materials were connected as follows. The Arduino Uno was fixed to the breadboard and the jumper wires were connected as illustrated in the following sections. One jumper wire from the 5-volt pin on the Arduino was connected to the to the bottom channel of the breadboard. Another jumper wire from a ground pin on the Arduino was connected to the upper channel of the breadboard. Piezo Buzzer has two terminals. Positive and negative. The positive terminal was connected to the pin 13 at the Arduino while the negative part was interfaced with 330 Ohms resister and connected to the lower channel of the breadboard. The ultrasonic sensor has four pins that's Vcc, Trig, Echo and ground. Echo was connected to pin number 11 while Trig being connected to pin number12 in the Arduino Uno. Vcc was connected to the upper channel while the Ground (Gnd) to the lower channel of the breadboard. The study utilized three LEDs one red, 1blue and greens. LED1 was connected to the pin number 8 and LED2 to pin number 7, LED3 to pin number 6. The negative terminal was interface with the 330 Ohms resisters to the lower channel of the breadboard as shown in figure 5. The jumper wires connected to the LEDs was connected to the lead on the right, while the left lead of the LED connected to the ground channel via a 330-ohm resistor. LCD has 14 terminals which were connected to the Arduino as: Pin 12 to Pin 2, Pin 11 to pin3, Pin 5 to pin 4, Pin 4 to pin 5, Pin 3 to pin 9, Pin 2 to pin 10 as shown in figure 5. The 5V pin from the Arduino was connected to the positive line on the breadboard. Also, the ground pin from the Arduino was connected to the negative part of the breadboard. For the reset of the intensity of the LCD screen, a 10kΩ potentiometer was interfaced to the breadboard. Potentiometer was connected to the breadboard, the positive terminal to the positive pin and the negative terminal to the ground pin to the ground pin as shown in the figure 5. The code was generated using the computer with the appropriate Arduino IDE program and sent to the Arduino microcontroller for running the circuit. The data for the study were collected and compared to the actual distance. The object from whose motion was to be detected was moved towards the sensor and the display of the distances to the LCD screen was observed. The displayed distances were compared from the actual distances from the meter rule.

IV. RESULTS AND DISCUSSION
This study sought to first design of a motion detector to detect approaching objects and raise a light (from an LED) and a sound alarm (from a sound buzzer). To achieve this, the components that include the Arduino Uno, resistors, LEDs, buzzer, LCD and ultrasonic sensor were fixed to the breadboard and connected as described in chapter three. Figure 5, shows the connections in progress. A jumper wire was connected from the 5 volts port from the Vcc port in the microcontroller chip to the positive channel of the breadboard. Another cable was grounded to the negative terminal of the breadboard from the GND port of the chip.  Figure 2; Circuit for arrangement of resistors, LEDs, buzzer, LCD and ultrasonic sensor.
A piezo buzzer having two terminals, positive terminal was connected to the pin 13 at the Arduino while the negative part was interfaced with 330 Ohms resister and connected to the lower channel of the breadboard. When the power source was connected as in figure 6 piezo buzzer produced a single tone signal to indicate that power was flowing through it. The limit set for the Piezo Buzzer was to produce the sound alarm at the distance greater than 0cm and less than 150cm.
The ultrasonic sensor having four pins, Echo was connected to pin number 11 while Trig being connected to pin number12 in the Arduino Uno. Vcc was connected to the upper channel while the Ground (Gnd) to the lower channel of the breadboard. Before enclosing the assembly in a casing, the complete connection as shown in Figure 6 was connected to a power supply, to confirm if it's working as expected. When power was applied as in figure 6, the piezo buzzer produced continuous sound alarm. LED1-RED was connected to the pin number 8 and LED2-BLUE to pin number7, LED3-GREEN to pin number 6. The negative terminal for all the LEDs each was interface with the 330 Ohms resisters to the lower channel of the breadboard. When the power was applied, the three LEDs produced the light as in Figure 6 and as per the program. Green LED produced light when the object was at 150.5cm, Blue LED when the object was 70.2 cm and Red LED when the object was at 40cm. LCD has 14 terminals which were connected to the Arduino as: Pin 12 to Pin 2, Pin 11 to pin3, Pin 5 to pin 4, Pin 4 to pin 5, Pin 3 to pin 9, Pin 2 to pin 10 as shown in figure 5. The 5V pin from the Arduino was connected to the positive line on the breadboard. Also, the ground pin from the Arduino was connected to the negative part of the breadboard. For the re-set of the intensity of the LCD screen, a 10kΩ potentiometer was interfaced to the breadboard. Potentiometer was connected to the breadboard, the positive terminal to the positive pin and the negative terminal to the ground pin to the ground pin as in figure 7. When the power was connected to the circuit, LCD produced a green light and it displayed distances as in figure 7 and 8. The program to run the circuit shown in figure 5 above was compiled in Arduino IDE and upload to the Arduino microcontroller chip.
The study also tested the display of the LCD, its brightness that could be adjusted, and the accuracy of the displaced distance versus the actual object distance. The Figure 7 shows an object distance of 187 cm on display. Once confirmed that everything was working as expected, the connections were assembled into a single unit as shown in Figure 8. An object was moved along the tape measure as shown on figure 9. The set up in figure 9was set and the carton drawn using the rope. The values from the tape were compared to the corresponding data from the LCD and the readings in the LCD were tabulated in the table 1.  Table 1 comprise of the Actual values recorded from the tape measure, values displayed on the LCD, Absolute errors, relative errors and the percentage errors tabulated in excel [40]. Absolute errors were obtained from the difference between the values from the tape measure-actual values and the values recorded from the LCD-approximated values. Relative errors were obtained from dividing the absolute errors by the actual values. Percentage errors were obtained from the product of relative errors by 100%. The distances recorded from the LCD had a small deviation from the actual distances from the meter rule as shown in table 1. The values recorded from the LCD deviated from the actual values from the tape measure by small margins as shown in the column of Absolute errors. The system is better than manual readings of distances. The possible sources of errors might be as a result of; (1) Instrumental errors, (2) Observation errors and (3) Variation of natural phenomena is also a possible source of error.

International
LEDs interfaced to the Arduino microcontroller were able to blink giving out the light signals. The order of the light signal was set from the Green LED being the first one to light followed by Blue LED and finally Red LED produced according to the program. The Green LED was set to produce continuous light signal at the distance <=150.5cm, Blue LED at <=70.2cm and Red LED at a distance <=40cm. The results obtained from the project slightly below the set parameters from the program.

V. SUMMARY, CONCLUSION AND RECOMMENDATION
In this study, a tool to detect motion of objects, display the recorded distances on the LCD screen, produce a recorded sound alarm by Piezo Buzzer and also light by LEDs was assembled. The circuit was successfully connected and the program was sent to the Arduino microcontroller chip to run the circuit. The ultrasonic sensor was able to send the ultrasonic sound waves to the approaching object and the alarm sound from the piezo buzzer was produced. Piezo Buzzer was set to produce sound at different levels. The limit set for the Piezo Buzzer was to produce the sound alarm at the distance greater than 0cm and less than 150cm. The results were correct since for the distance equal or greater than 150cm and the distance equal to 0cm produced no tone from the piezo buzzer. LEDs were also set to produce light signal in a particular set of distances starting with Green LED followed by Blue LED and lastly Red LED. On the outcome, LEDs produced light as they were expected. The LCD was also expected to display the variation of distances as the object approaches the ultrasonic sensor. When the power was connected to the set-up, there were values recorded in the LCD screen indicating that the connection was right. The intensity of the screen was expected to be controlled by the potentiometer of which the same was approved.
This tool can be custom made to fit various applications such as being fitted in cars to aid when reversing, could tell the level of water in a well or storage tanks etc. The technique can also be implemented with the GSM for proper remote monitoring. The technique can also be recommended to be used in the tunnels such as train or vehicle tunnels to give signal in case there are complications.