3.3 Arduino uno. 18. 3.3.1 Techinal Specification. 18. 3.4 Power Supply. 19. 3.5 16*2 LCD. 20. Chapter Four : Software Development. 4.1 Software design. 22.
Obstacle Detection Using the Concept of Ultrasound by : Amar Bakri Musa Gehad Abdullah Mohammed Sharf Eldeen Mahgoub Hussein
A graduation project is submitted to electrical & electronic engineering department in partial fulfillment of the requirements for the degree of bachelor in electrical & electronic engineering
Department of Electrical & Electronic Engineering College of Engineering & Technology Nile Valley University
July 2016
DEDICATION
Our thank to Allah who help us to conduct this research Then we would like to thank our teachers for their help. our lovely parents who are always with us in our hearts. Our sisters and brothers who are always around us with their prayers. Our friends who support us in our research.
i
Acknowledgement We would like to express deepest gratitude to our supervisor Teacher Abubakr Rahmtalla Abdalla for his full support, expert guidance, understanding and encouragement throughout our study and research. Without his incredible patience and timely wisdom and counsel, our thesis work would have been a frustrating and overwhelming pursuit. Special thanks to our families for care and support and teach us mean of love, magnificent with values and humanity.
ii
ABSTRACT
The purpose of this research is to develop a module to measure the level of the river system by using the concept of the ultrasonic waves. Everything in the modern human life has undergone rapid development. This development is supported by the advance of electronics and information technology, so we have built a system which can automatically sense the water level. The ultrasonic ranging module HC - SR04 is used as a distance sensor for detecting water level by measuring distance between sensor and water surfaces. The system consists of sensor and view data side . Sensor performs water level detection and LCD with LEDs and buzzer . View data side then displays the data on the LCD screen. Then depending on the measurements of the previous years for the same river we also have a set of LEDs to show that the current value of the water level located at which area (safe, medium or risky). If water level changes rapidly and considerably dangerous, the system will activate the buzzer at the receiver module to generate sound alarm. This system was developed by using Arduino uno.
iii
Table of contents Dedication
i
Acknowledgement
ii
Abstract
iii
Table of contents
iv
List of tables
vi
List of figures
vii
Chapter One : Introduction Overview Background Objectives Significance of the projects Proposed Approach and Methods to Be Employed
Chapter Two : Literature Review Background of ultrasonic distance measurement Selection of the ultrasonic sensor Arduino Arduino Advantages Arduino disadvantages Programming Language Background C Language arduino c Liquid Crystal Display (LCD) Light Emitting Diode (LED) Buzzer Power Supply Module
Chapter Three : Hardware Design The whole Hardware Design and Implementation The HC-SR04 Ultrasonic sensors iv
HC - SR04 features HC - SR04 Timing diagram Arduino uno Techinal Specification Power Supply 16*2 LCD
Chapter Four : Software Development Software design The system flowchart Arduino (IDE) The system code
Chapter Five : The System Integration, Testing & Results The System Integration The System testing and results
Chapter Six : Conclusion & Future Work Conclusion Future work References
v
List of Tables Table No.
Contents electrical parameters of HC-SR04 ultrasonic sensor 16*2 LCD pin connections
vi
Page No.
List of Figures Figure No.
Contents system block diagram Proposed Project Approach flowchart The time between the transmission sound waves and the detection of the echo LED The physical diagram of the Buzzer Arduino powering inputs Schematic of Power Supply in Circuit Diagram show the schematic circuit diagram of the project HC-SR04 ultrasonic sensor HC - SR04 Timing diagram Pin assignment of arduino uno 16*2 LCD Block diagram The software development flowchart the system flowchart Arduino IDE The system module case 1: the water at the safe level case 2: the water at the medium level case 3: the water at the risky level
vii
Page No.
CHAPTER 1. INTRODUCTION
1.1 Overview Almost all aspects of human life have undergone rapid development. This development is supported by the advance of electronics and information technology. The job can be performed on schedule precisely and efficiently by adopting this advance technology. An achievement in computer technology is used not only in business and industry but has also covers almost all fields, including control system where a computer system can be used to control the hardware in a flexible way. Therefore, computer based control system becomes more common in recent development of control system. Computer-based control system also can be implemented for optimizing a river flow management to minimize flood caused by water overflow. Management can be performed based on elevation of water level on the river as an input data and control the sluices along the river stream based on these data. The monitoring water level in a river or in a reservoir is important in the applications related to agriculture, flood prevention, and fishing industry, etc. The schemes developed for measuring water level can be categorized as four types based on the measuring features such as pressure, ultrasonic waves, heat, and image processing. In this project we will use the concepts of the ultrasonic waves. An ultrasonic level or sensing system requires no contact with the target. For many processes in the medical, pharmaceutical, military and general industries this is an advantage over inline sensors, which may contaminate the liquids inside a vessel or tube, or even may be clogged by the product. Both continuous wave and pulsed systems are used The principle behind a pulsedultrasonic technology is that the transmitted signal consists of short bursts of ultrasonic energy. After each burst, the electronics looks for a return signal within a small window of time corresponding to the time it takes for the energy to pass through the vessel. Only a signal received during this window will qualify for additional signal processing. Ultrasonic wave sensor is free from water pressure since it measures the time of travelling of ultrasonic wave pulse from transmitter to receiver reflected by the water surface.
1
1.2 Background The first use for the concept of the ultrasonic waves was done by U.S. researcher Dr. Floyd Firestone of the University of Michigan applies for a U.S. invention patent for the first practical ultrasonic testing method. The patent is granted on 1942 under the title "Flaw Detecting Device and Measuring Instrument". Extracts from the first two paragraphs of the patent for this entirely new non-destructive testing method succinctly describe the basics of such ultrasonic testing. "My invention pertains to a device for detecting the presence of in homogeneities of density or elasticity in materials. For instance if a casting has a hole or a crack within it, my device allows the presence of the flaw to be detected and its position located, even though the flaw lies entirely within the casting and no portion of it extends out to the surface. ... The general principle of my device consists of sending high frequency vibrations into the part to be inspected, and the determination of the time intervals of arrival of the direct and reflected vibrations at one or more stations on the surface of the part." Another use for the concept of the ultrasonic waves was done by James F. McNulty of Automation Industries, then, in El Segundo, California, an early improver of the many foibles and limits of this and other non-destructive testing methods, teaches in further detail on ultrasonic testing in his U.S. Patent (application filed in 1962, granted in 1966, titled “Ultrasonic Testing Apparatus and Method”)that “Basically ultrasonic testing is performed by applying to a piezoelectric crystal transducer periodic electrical pulses of ultrasonic frequency. The crystal vibrates at the ultrasonic frequency and is mechanically coupled to the surface of the specimen to be tested. This coupling may be affected by immersion of both the transducer and the specimen in a body of liquid or by actual contact through a thin film of liquid such as oil. The ultrasonic vibrations pass through the specimen and are reflected by any discontinuities which may be encountered. The echo pulses that are reflected are received by the same or by a different transducer and are converted into electrical signals which indicate the presence of the defect. In ultrasonic testing, an ultrasound transducer connected to a diagnostic machine is passed over the object being inspected. The transducer is typically separated from the test object by a couplant (such as oil) or by water, as in immersion testing. However, when ultrasonic testing is conducted with an Electromagnetic Acoustic Transducer (EMAT) the use of couplant is not required.
2
There are two methods of receiving the ultrasound waveform: reflection and attenuation. In reflection (or pulse-echo) mode, the transducer performs both the sending and the receiving of the pulsed waves as the "sound" is reflected back to the device. Reflected ultrasound comes from an interface, such as the back wall of the object or from an imperfection within the object. The diagnostic machine displays these results in the form of a signal with an amplitude representing the intensity of the reflection and the distance, representing the arrival time of the reflection. In attenuation (or through-transmission) mode, a transmitter sends ultrasound through one surface, and a separate receiver detects the amount that has reached it on another surface after travelling through the medium. Imperfections or other conditions in the space between the transmitter and receiver reduce the amount of sound transmitted, thus revealing their presence. Using the couplant increases the efficiency of the process by reducing the losses in the ultrasonic wave energy due to separation between the surfaces.
1.3 Objectives There are some objectives need to be achieved in order to accomplish this project. These objectives will act as a guide and will restrict the system to be implemented for certain situations: To develop a model of FLOOD MONITERING SYSTEM by using the ultrasonic sensor to measure the water depth in the rive To display the water level using LCD. Then Depending on the measurements of the previous years for the same river we also have a set of LEDs to show that the current value of the water level located in which level (safe, medium or risky). To use Arduino (IDE) software to generate a computer program for the arduino in order to get signal for the real time
Significance of the projects The aim of this project is to develop prototype of water level detection that can be viewed as a part of control system of river flow management system. The system consist of ultrasonic sensor and the Liquid Crystal Display with the Light Emitting Diodes (LEDs) and the buzzer. 3
Ultrasonic sensor is used to detect the distance between sensor and the water surface. Water level detection is performed without physical contact between the sensor and water surface. Ultrasonic sensors utilize the principle of sound reflection to measure the level of the water. The calculation is performed by high level language program that reside in an arduino. arduino to display the water level using LCD. Then depending on the measurements of the previous years for the same river we also have a set of LEDs to show that the current value of the water level located in which area:
LED with a green color means that the water level is still at the safe level.
LED with a yellow color means that the water level at the area between the safe level and the level of risk (medium level).
LED with a red color means that the water level has reached the level of risk (flood level). Then if water level is changed rapidly and considerably dangerous, the buzzer will be
activated.
Ultrasonic sensor
Arduino
LCD Display
Buzzer
Figure 1.1 system block diagram
4
LED set to show the level of the measured value of water
Proposed Approach and Methods to Be Employed In order to complete this project smoothly, a lot of research work on flood monitoring systems was required such as going through reference books, journals, internet resources and components datasheets so that will assist in the success of the project. The system consists of hardware and software parts. Hardware part consists of some components such as: 1) The Ultrasonic ranging module HC - SR04. 2) Arduino(Microcontroller) 3)The Liquid Crystal Display (LCD). 4) The Light Emitting Diodes (LEDs) and the buzzer. Arduino is the “brain” of the whole system It receives the input signals from the sensor and displays the water level on the Liquid Crystal Display (LCD), controls Light Emitting Diodes (LEDs) and the buzzer. All these processes will be done according to the program. Software part consists of the programming needed for the arduino to perform its task. Algorithms are written to set how the arduino works and reacts according to the different scenarios such as reading the input signal from the sensor and flashing of LEDs and activating of the buzzer when alarm happens. For the software application, either C-programming or Assembly Language can be selected to be the main software used for the micro-controller. In order to achieve these goals, a lot of hard work is required to program the software. In the process of completing the project, tasks like circuit designing, finding components, constructing prototype, checking the simulation and testing the functionality of the prototype will be performed, followed by circuit fault diagnoses and troubleshooting.
5
Software development and system implementation
Study about the existing Ultrasonic
sensor flood monitoring systems
Analyze the improvement on the existing systems
Literature review and selecting suitable components
Study Arduino C language and write the system code
Perform simulation and functionality test
No
Design the circuit and construct the system prototype
Figure 1
Fault diagnosis and troubleshooting
Proposed Project Approach flowchart
6
Yes
System implementation on real time and improvement
CHAPTER 2. LITERATURE REVIEW
Background of ultrasonic distance measurement The Ultrasonic distance sensor uses high frequency sound to determine the distance to a reflected object. Similar to how bats detect obstacles by transmitting high-pitched Sound and listening to the echoes. These Ultrasonic distance sensors emit a series of Supersonic pulses and wait for echo pulses to be detected. Since the speed of the sound is constant in the air (340.29 m/s), the time elapse between the transmitted signal and the received signal can be measured and so the distance of the object can be determined. Ultrasonic distance measurement is based on the speed property of sound. The system transmits multiple sound waves that travel out into the air. These sound waves reflect off from any objects they impact and return back as an echo to the location from which they originated. The system detects these reflected sound waves (that is, echoes). The time between the transmission of the sound waves and the detection of the echo is measured, as shown in Figure 2.1. At time t0, the transducer creates the sound waves. At time t1, the sound waves impact an object. At time t2, the waves have reflected off from the object and are travelling back toward the transducer. At time t3, the echo has impacted the transducer, which detects these waves. The system subtracts t0 from t3 to calculate the total travel time of the sound.
Figure 2.1 The time between the transmission sound waves and the detection of the echo
7
The sound’s travel time is multiplied by the speed of the sound to calculate the total distance that the sound waves travelled. This distance is divided by two to calculate the distance of the object that caused the echo. These calculations are shown in Equation 2.1, where S is the distance between the transducer and the detected object, V is the speed of sound, and t is the measured time between sound wave transmission and detection of the echo. The total distance (s) =
)
Some advantages of the ultrasonic distance sensor are that it is less affected by target materials, or by colour. Even though it does not have a narrow field of view as the laser range finder, it is still capable of detecting objects within a meter. These Ultrasonic sensors are designed to resist external disturbances such as vibration, infrared radiation, ambient noise, and EMI radiation. The cost of ultrasonic range finder depends on the frequency transducer uses. Higher frequency (~255 KHz) ultrasonic range finder costs between 100 to 200 dollars, but with moderate high frequency (40 KHz) it is cheaper.
2.2 Selection of the ultrasonic sensor There are numerous types of ultrasonic range sensors available with key differences in frequency and power consumptions. Ultrasonic sensor with high frequency will have a sharper beam width and can detect obstacles in longer range. Also some of the new sensors have similar range detection as previous models but with less power consumption. In this project, the ultrasonic sensor must be able to detect obstacles or objects from 2cm to 400cm. Since the whole system power supply will be taken from battery supply, the less current consumption is crucial and must be able to operate at low voltage. HC-SR04 meets the criteria of this project to detect the obstacles in a short period after the long research was done between the HC-SR04 and others Ultrasonic sensors.
2.3 Arduino Arduino is a software company, project, and user community that designs and manufactures computer open -source hardware, open source, and microcontroller-based kits for building digital devices and interactive objects that can sense and control physical devices. The project is based on microcontroller board designs , produced by several vendors, using various microcontrollers. These systems provide sets of digital and analog I/ O pins that can interface to various expansion boards (termed shields ) and other circuits . the boards feature serial communication interface, including universal serial bus (USB )on some models, for loading programming from personal computers. 8
Arduino are used in automatically controlled devices such as control systems, office machines, automobile engines, power tools and so on. By reducing the size, cost and power consumption, arduino makes it economical to electronically control more and more processes.
Arduino Advantages Ready to use : The biggest advantage of Arduino is its ready to use structure. As Arduino comes in a complete package form which includes the 5Vregulator, a burner, an oscillator, a micro controller, , serial communication interface, LED and headers for the connections. You don't have to think about programmer connections for programming or any other interface. Just plug it into USB port of your computer and that's it. Your revolutionary idea is going to change the world after just few words of coding. Examples of codes : Another big advantage of Arduino is its library of examples present inside the software of Arduino. Effortless function :During coding of Arduino, you will notice some functions which make the life so easy. Large community: There are many forums present on the internet in which people are talking about the Arduino. Engineers, hobbyists and professionals are making their projects through Arduino.
Arduino disadvantages - Structure: Yes, the structure of Arduino is its disadvantage as well. During building a project you have to make its size as small as possible. But with the big structures of Arduino we have to stick with big sized PCB’s. - Cost: The most important factor which you cannot deny is cost. This is the problem which every hobbyist, Engineer or Professional has to face. - Easy to use: In my opinion, if you started your journey of micro-controllers with Arduino then it will be very difficult for you to make the complex intelligent circuitries in future. The easy to use hardware/software of Arduino unable a person to learn the basics of many things likes Serial communication.
9
2.4 Programming Language There is no scientific or universal way to define what is the absolute best style of programming. However, I can quote six items that can help to understand what we'll try to do together in order to make good programs. We'll aim for the following: Reliability: This enables a code to handle its own generated errors while running. Solidity: This provides a frame to anticipate problems on the user side(wrong inputs). Ergonomics: This helps to intuitively be able to use it with ease. Portability: This is the designing of a program for a wide range of platforms. Maintainability: This is the ease of modifying it even if you didn't code it yourself. Efficiency: This indicates that a program runs very smoothly without consuming a lot of resources.
2.4.1 Background of C Language C and C++ Dennis Ritchie at Bell Labs developed the C programming language from 1969 to 1973. It is often defined as a general-purpose programming language and is indeed one of the most used languages of all times. It had been used initially to design the Unix operating system that had numerous requirements, especially high performance. It has influenced a lot of very well-known and used languages such as C++,Objective -C, Java, JavaScript, Perl, PHP, and many others.
Arduino c Indeed, the C language provides a lot of advantages. They are as follows: • It is small and easy to learn • It is processor-independent because compilers exist for almost all processors in the world. This independence provides something very useful to programmers: they can focus on algorithms and the application levels of their job instead of thinking about the hardware level at each row of code. • It is a very "low-level" high-level language. This is its main strength. Dennis M. Ritchie, in his book The C Programming Language written with Brian W. Kernighan commented on C as: C is a relatively "low level" language. This characterization is not pejorative; it simply means that C deals with the same sort of objects that most computers do. These may be combined and moved about with the arithmetic and logical operators implemented by real machines. Today, this is the only language that allows interacting with the underlying hardware engine so easily and this is the reason why the Arduino tool chain is based on C. 11
2.5 Liquid Crystal Display (LCD) A liquid-crystal display (LCD) is a flat panel display, electronic visual display, or video display that uses the light modulating properties of liquid crystals. Liquid crystals do not emit light directly. LCDs are available to display arbitrary images (as in a general-purpose computer display) or fixed images which can be displayed or hidden, such as preset words, digits, and seven-segment displays as in a digital clock. They are often used in batterypowered devices, such as digital watches, because LCDs consume very little electricity. They are also used for flat screen TV's. They work well by themselves when there is other light around (like in a lit room, or outside in daylight). For TV's and some other cases where light is needed, a back-light is built into the product. LCDs use the same basic technology, except that arbitrary images are made up of a large number of small pixels, while other displays have larger elements.
2.6 Light Emitting Diode (LED) A LED is a semiconductor diode that emits light when an electrical voltage is applied in the forward direction of the device. When LED anode lead has a voltage that is more positive than its cathode lead by at least the LED forward voltage drop thus current flows. Electrons are able to recombine with holes within the device, releasing energy in the form of photons. This effect is called electroluminescence, and the colour of the light (corresponding to the energy of the photon) is determined by the energy band gap of the semiconductor. In this project, the LEDs will be used as indicators at the prototype; thus, we have used one green LED, one yellow LED and one red LED which indicate the water level.
Figure 2. LED
11
2.7 Buzzer A buzzer is an audio signaling device which may be mechanical or electronic. It can be used as an alarm, timer or confirmation of user input. The sound output from the buzzer may be continuous or intermittent. As the output is typically at least 75dB, it will provide sufficient sound aid for the user. Thus, I have used a buzzer in my system to give an alarm if the water level changed rapidly and considerably dangerous.
Figure 2. The physical diagram of the Buzzer
2.8 Power Supply Module That we have quite a clear idea of the possible external power sources, we may see how to apply them to Arduino. Everything we will describe in this paragraph can be applied to all the kind of sources previously described, thus both power supplies and batteries. We point out again the need to pay maximum attention to the polarities: it is very important to connect properly the positive and the negative poles to the Arduino board, otherwise there is the risk to see nothing work or even to make irreparable damages. In fact, while in some cases there are some intrinsic protections on the board, in other cases the polarity inversion might cause-immediate-damages.
12
Arduino has four possible powering inputs:
Figure
Arduino powering inputs
.USB Port: 5 V have to reach this socket (different voltages are not allowed, absolutely!), coming from a computer’s USB port, or from any power supply that is provided with a USB port (in general, they are small size power supplies, suitable to power devices that are provided with a USB cable). If the powering comes from a computer, there is a current limitation of 250 mA or 500 mA, depending on the USB port of the said computer; if on the other hand you are using an external power supply, the maximum output current (regardless of the one guaranteed by the same power supply, that in general is a maximum of 1 A or 2 A) is anyway limited to 500 mA by the PTC self-resettable protection fuse JAPAN JACK socket: an external source (a power supply, usually) must be connected to this socket, with the positive pole going to the central part of the jack, and the value must be ranging between 6 V and 20 V, even though the range recommended by the manufacturer is 7÷12 V, thus it is not advisable to use voltages that are lower than 7 V or greater than 12 V, if not in the case of a real need; 6 V may not guarantee a proper stabilization on the part of the regulator, it is in fact needed to consider the voltage fall of the protection diode, placed in series at the regulator’s input whose purpose is to preserve 13
the board from destruction in the case of polarity inversion on the jack); while values above 12 V would create an excessively high drop-out (an electric potential difference between the regulator’s input and output) that would cause a pointless overheating of the regulator, even with low levels of current draw. Vin socket: V socket: it is directly connected to the regulator’s output, thus the
V to power
external loads to Arduino can be drawn from it. In the case voltages are not applied to the USB Port or to the JACK socket, the 5 V socket can be even used to power Arduino directly, if having an external stabilized 5 V source.
Figure 2. Schematic of Power Supply in Circuit Diagram
14
CHAPTER
HARDWARE DESIGN
This chapter discusses the hardware implementation of the project. It will be divided into various parts which are essential to complete the project. The following is the list of the hardware components used in this project. The hardware design and its implementation for these hardware components will be discussed in details in the subsequent sections.
3.1 The whole Hardware Design and Implementation The whole design mainly includes the following parts: The HC-SR04 Ultrasonic sensors. Arduino uno: to program and control devices. Power Supply: to supply voltage power to the whole system. 16*2 LCD: to display the water level. Buzzer and LEDs: alert panel (to give a signal to the operator or driver).
Figure 3.1 show the schematic circuit diagram of the project
3.2 The HC-SR04 Ultrasonic sensors In this project, the ultrasonic sensor must be able to detect obstacles and objects from 2cm to 400cm. Since the whole system power supply will be taken from battery pack, the less power consumption is crucial and must be able to operate at low voltage. SR04 meets the criteria of 15
this standard to detect the obstacles in a short period after the long research work was done to select between the SR04 and others Ultrasonic sensors.
HC - SR04 features Ultrasonic ranging module HC - SR04 provides 2cm - 400cm non-contact measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit. The basic principles of work are: (1) Using IO trigger for at least 10µs high level signal, (2) The Module automatically sends eight 40 kHz signals and detect whether there is a pulse signal back. (3) IF the signal comes back, through high level, time of high output IO duration is the time from sending ultrasonic to returning. Test distance = (high level time ×velocity of sound (340m/s) / 2.
Figure 2.3 HC-SR04 ultrasonic sensor
Wire connecting direct as following:
5V power supply
Trigger Pulse Input
Echo Pulse Output
0V Ground 16
Table 3.1 electrical parameters of HC-SR04 ultrasonic sensor Working voltage
DC 5V
Working current
15 Ma
Working frequency
40Hz
Max range
4m
Min range
2 cm
Measuring angle
15 degree
Trigger input signal
10 µs TTL pulse
Echo output signal
Input TTL lever signal and the range in proportion
Dimension
450*20*15 mm
3.2.2 HC - SR04 Timing diagram The timing diagram of HC-SR04 is shown in figure 3.4. To start the measurement, Trig of SR04 must receive a pulse of high (5V) for at least 10µs, this will initiate the sensor to transmit out 8 cycles of ultrasonic burst at 40 kHz and wait for the reflected ultrasonic burst. When the sensor detected ultrasonic from the receiver, it will set the Echo pin to high (5V) and delay for a period (width) which is proportional to distance. To obtain the distance, measure the width (Ton) of Echo pin. We can calculate the range through the time interval between sending trigger signal and receiving echo signal. Formula: µS / 58 = centimeters or µS / 148 =inch; or you can calculate the range = high level time * velocity (340m/s) / 2; it is suggested to use over 60ms measurement cycle, in order to prevent trigger signal from the echo signal.
Figure
HC - SR04 Timing diagram
17
3.3 Arduino uno The Arduino Uno is a microcontroller board based on the ATmega328 . It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started. The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega8U2 programmed as a USB-to-serial converter.
3.3.1 Techinal Specification
Microcontroller ATmega328
Operating Voltage 5V
Supply Voltage (recommended) 7-12V
Maximum supply voltage (not recommended) 20V
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega328) of which 0.5 KB used by boot loader
SRAM 2 KB (ATmega328)
EEPROM 1 KB (ATmega328)
Clock Speed 16 MHz
If you want to give a closer look to this board we advise you to visit the official Arduino UNO in the Hardware Section.
18
Figure
Pin assignment of arduino uno
3.4 Power Supply One of the main objectives for this project is to enable the user to carry the device around easily. Therefore, direct connection to AC power will not be possible for this case. Therefore, A voltage regulator will be needed. A voltage regulator is an electrical regulator designed and use for maintaining of a constant voltage output in a circuit. The LM7812 voltage regulator will be used for maintaining of 12V output voltage in this project as we showed in figure 2.5
19
16*2 LCD LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments) , animations and so on. A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.
Figure
LCD Block diagram
21
Table 3.2 16*2 LCD pin connections
PIN NUMBER
SYMBOL
FUNCTION
VSS
GND
VDD
+ 3V or + 5V
Vo
Contrast Adjustment
RS
H/L Register Select Signal
R/W
H/L Read/Write Signal
E
H L Enable Signal
DB0
H/L Data Bus Line
DB1
H/L Data Bus Line
DB2
H/L Data Bus Line
DB3
H/L Data Bus Line
DB4
H/L Data Bus Line
DB5
H/L Data Bus Line
DB6
H/L Data Bus Line
DB7
H/L Data Bus Line
A/Vee
+ 4.2V for LED/Negative Voltage Output
K
21
Power Supply for B/L (OV)
CHAPTER 4.SOFTWARE DEVELOPMENT This chapter will discuss the software development of the system including all the programs which were tested out using the prototype hardware that We developed.
4.1 Software design The software development begins when the hardware implementation is close to completion. In order to determine if the hardware design works as expected, programming codes are required to test the hardware design modules individually. For instance, programming code to test solely on the LCD if it is functioning or not. Upon the completion of the hardware design, full program instructions will be planned out, written and programmed into the arduino . Figure 4.1 below is the software development flowchart as a guideline.
Configure and familiarize software
Basic program on ultrasonic sensor
Program on LCD
Program on LEDs and buzzer
Integration of the programming codes by parts
Testing on all programming codes after compiling together Figure 4.1 The software development flowchart
22
4.2 The system flowchart START
Port initialization
Detect the water level using the ultrasonic sensor
Yes
Is the water level at the safe level?
Display the value on the LCD and turn the green LED on
No
Yes
Is the water level at the medium level?
Display the value on the LCD and turn the yellow LED on
No
Is the water level at the risky level?
Yes
Display the value on the LCD, turn the red LED on and activate the buzzer
No END
Figure 4.2 the system flowchart
23
4.3 Arduino IDE The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the Arduino and Genuino hardware to upload programs and communicate with them. Programs written using Arduino Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the file extension .ino. The editor has features for cutting/pasting and for searching / replacing text. The message area gives feedback while saving and exporting and also displays errors. The console displays text output by the Arduino Software (IDE), including complete error messages and other information. The bottom right hand corner of the window displays the configured board and serial port. The toolbar buttons allow you to verify and upload programs, create, open, and save sketches, and open the serial monitor.
Figure 4. Arduino IDE
24
Verify :Checks your code for errors compiling it Upload : Compiles your code and uploads it to the configured board. New: Creates a new sketch Open: Presents a menu of all the sketches in your sketchbook Save :Saves your sketch Serial Monitor: Opens the serial monitor
Additional commands are found within the five menus: File, Edit, Sketch, Tools, Help. The menus are context sensitive, which means only those items relevant to the work currently being carried out are available.
4.4 The system code #define trigPin 7
//trigPin
#define echoPin 6
//echoPin
#define buzzerPin 5 #define ledredPin 4 #define ledgreenPin 3 #define ledyellowPin 2 #include LiquidCrystallcd(8, 9, 10, 11, 12, 13); byte rang1=150; byte rang2=50 ; void setup () { pinMode (trigPin, OUTPUT); //trig pin as output pinMode (echoPin, INPUT); //echo pin as input lcd.begin(16, 2); 25
pinMode(buzzerPin, OUTPUT); pinMode(ledredPin,OUTPUT); pinMode(ledgreenPin,OUTPUT); pinMode(ledyellowPin,OUTPUT); } void loop () { int duration, level; digitalWrite (trigPin, HIGH); delayMicroseconds (500); digitalWrite (trigPin, LOW); duration = pulseIn (echoPin, HIGH); level = (duration / 2) / 29.1; { lcd.print("Lquid level="); lcd.print(level); lcd.println("cm" ); delay(1000); lcd. setCursor(0 , 0); } delay(100); if ( level