Sensors Application Using PIC16F877A Microcontroller

In the 21 century, sensors have become common and part of everyday life. Such as touch-sensitive cell phones, computer monitors, elevator buttons, lamps that automatically dim or brighten, and even cars that park themselves. In addition, there are many applications of sensors that are hidden but control many facets of modern life such as in cars, airplanes, medical imaging, satellite communications and navigation. This research effort examines three sensor types, their data, and how to integrate it with a single microcontroller to accomplish simple tasks – dimming a light, sounding an alarm and showing a temperature rise. Three sensor types were used in this effort. First, an ultrasonic sensor was used to measure the distance from an object. A temperature sensor was used for monitoring temperature change from a human touch. Third, a Light Depending Resistor (LDR) sensor was used to detect different levels of light in a room. The goal of this research was to make a smart device that can be used to solve simple problems. Further applications could be applied to perform tasks such as controlling the temperature of a room or controlling the level of water in a meter. Also, robotics could be improved by providing information about distance to an object. Many applications can be enhanced based on this research.


Introduction
In the modern world of the 21 st century, sensors are so abundant and widespread that they are commonly taken for granted. Sensors and microcontrollers have been integrated for specific applications such as touch-sensitive cell phones, computer monitors, elevator buttons and lamps which dim or brighten by touching the base. There are also innumerable applications for sensors of which most people are never aware. Applications include cars, machines, aerospace, medicine, manufacturing and robotics [1].
Simply put, a sensor is a device for detecting and signaling a changing condition [2]. A sensor (also called detector) is a converter that measures a physical quantity and converts it into a signal which can be read by an observer or by an (today mostly electronic) instrument [3][4][5][6]. For example, a mercury-in-glass thermometer responds to the ambient temperature by expansion and contraction of the mercury liquid. This can be read on a calibrated glass tube. A thermocouple converts temperature to an output voltage which can be read by a voltmeter. For accuracy, most sensors are calibrated against known standards [6][7][8].
The sensitivity of a sensor indicates how much the sensor's output changes when the measured quantity changes. For instance, if the mercury in a thermometer moves 1 cm when the temperature changes by 1°C, the sensitivity is 1 cm/°C (it is basically the slope assuming a linear characteristic). Sensors that measure very small changes must have very high sensitivities [2,4].
The sensors themselves may also have an impact on what they are measuring. For instance, a room temperature thermometer inserted into a hot cup of liquid will have a cooling effect on the liquid while the liquid heats the thermometer. For this reason, sensors should be designed to have as small an effect as possible on the environment which it is placed. One way to achieve this is to make the sensor small, the smaller the better. This miniaturization often improves the sensor response and may introduce other advantages as well. Technological progress allows more and more sensors to be manufactured on a microscopic scale as micro sensors using Micro Electro Mechanical Systems (MEMS) technology. In most cases, a micro sensor reaches a significantly higher speed and sensitivity compared with macroscopic approaches.

Sensor Types and Applications
Sensors vary from very plain to highly complex. A simple example of a sensor is a mercury-based glass thermometer. The input is the ambient air temperature. The contained mercury liquid expands and contracts in response to changes in the temperature, causing the level to be higher or lower on the marked gauge [1]. A more complex example is an oxygen sensor in a car's emission control system. A sensor detects the gasoline/oxygen ratio, usually through a chemical reaction that generates a voltage [2]. This voltage data is read by a computer in the engine, processes the data and if the mixture is not optimal, sends a signal to readjust the gas/oxygen ratio. Other examples are motion detector sensors used for home security lights, automatic doors and burglar alarms. These systems typically transmit some type of energy, such as microwaves, ultrasonic waves or light beams and detect when the flow of energy is interrupted by an object entering its path. A photo sensor detects the presence of visible light, Infrared transmission (IR), and/or Ultraviolet (UV) energy.

Hardware and Software Components
This section presents a description and theoretical background of the electronics hardware components, PIC, ultrasonic sensor, and temperature sensor. Also a synopsis of the integration of these components into the developed system is discussed.

Ultrasonic Sensor
Ultrasonic sensors (generally called transducers but also known as transceivers doing both sending and receiving) work on a principle similar to radar or sonar. They process the returning echoes to evaluate attributes of a target such as size, shape, and position [1,9]. Ultrasonic sensors generate high frequency sound waves and evaluate the echo which is reflected back to the sensor. A timing chip measures the time interval between transmitting the signal and receiving the echo to calculate the distance to the object. This technology can also be used for measuring wind speed and direction (anemometer), tank or channel level, and speed through air or water. For measuring speed or direction a device uses multiple detectors and calculates the speed from the relative distances to particulates in the air or water. To measure tank or channel level, the sensor measures the distance to the surface of the fluid. Further applications include: humidifiers, sonar, medical ultrasonography, burglar alarms and nondestructive testing.
Within the manufacturing industry, ultrasonic sensors are used to detect movement and to measure distance of objects [1,10,11,20]. Currently ultrasonic sensors are widely used in automotive applications such as park assist technology [1]. Another application of ultrasonic transducers is formedical imaging technology. Ultrasonic probes come in a variety of shapes and sizes. The transducer may be passed over the surface of the body or inserted into a body cavity to produce an image.
This study employsan ultrasonic ranging module-HC -SR04 to provide a 2cm -220cm non-contact measurement function with a ranging accuracy up to 3mm. This module includes an ultrasonic transmitter, receiver and control circuit [9,10,12,13]. Figure 1 shows the HC-SR04 ultrasonic sensor. This sensor has 4 pins: Vcc (Voltage in), Trig (Trigger), Echo, and GND (Ground). The Vcc pin requires 5 VDC and the GND pin needs to be properly grounded [14,20,21]. The Trig pin receives a pulse to start ranging and sends out a burst of ultrasound. The Echo pin receives the signal and calculates the time between sending a signal and receiving it. The formulas in Equations 1 and 2 show how the distance to an object is calculated, where Equations 1 and 2 show the distance calculation, and Equation 3 show the range of sensor [15,16,21]. The basic mode of operation of this module is to: Use IO trigger for at least 10us high level signal, then The module automatically sends eight 40 kHz and detect whether there is a pulse signal back.
IF the signal 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. (4)

Microcontrollers
Microcontrollers are essentially a computer on a chip. They consist of an integrated circuit with processor core, memory, and with programmable input/output peripherals. Many also have a Light Emitting Diode (LED) or Liquid Crystal Display (LCD) display for output. Microcontrollers typically do a limited number of tasks, but they do them well. They are best suited for embedded applications designed for a specific purpose.
Microcontrollers have essentially three components: a Central Processing Unit (CPU), memory, and digital input/output connections. Electronic Erasable Programmable Read-Only Memory (EEPROM) memory makes it easier to apply microcontrollers to devices where permanent storage of various parameters is needed (codes for transmitters, motor speed, receiver frequencies, etc,.).
For this research a PIC16F877A microcontroller, manufactured by Microchip, was selected. PIC and PIC micro are registered trademarks of Microchip technology [17]. It is generally thought that PIC stands for Peripheral Interface Controller, although General Instruments' original acronym for the initial PIC1640 and PIC1650 devices was "Programmable Interface Controller". The acronym was quickly replaced with "Programmable Intelligent Computer" [17][18].
The PIC16F877A is one of the PIC Micro families of microcontrollers which is currently popular among professionals and hobbyists alike. This is because the PIC16F877A is easily programmed and with the FLASH memory technology allows up to a thousand re-writes [17]. The superiority of this microcontroller compared with other's within its peer group show that the PIC has the speed and flexibility for many uses, from automotive industries and controlling home appliances to industrial instruments, remote sensors, electrical door locks and safety devices. It is also ideal for smart cards as well as for battery supplied devices because of its low consumption.
Low cost, low consumption, easy handling and flexibility make the PIC16F877A applicable even in areas where microcontrollers had not previously been considered (example: timer functions, interface replacement in larger systems, coprocessor applications, etc.) [6]. In system programmability of this chip (along with using only two pins in data transfer) makes possible the flexibility of a product, after assembling and testing have been completed. This capability can be used to create assembly-line production, to store calibration data available only after final testing, or it can be used to improve programs on finished products.
Features of the PIC Microchip microprocessors are that they are easily programmed, have built in EEPROM, and an abundance of development tools. The PIC16F877A microprocessor has 8K of flash program memory, 256K of EEPROM, and 3 timers, making it an excellent choice for this research [17].

Light Dependent Resistor
Photo resistors, also known as Light Dependent Resistors (LDR), are light sensitive devices most often used to indicate the presence or absence of light, or to measure the light intensity. In the dark, their resistance is very high, sometimes up to 1MΩ, but when the LDR sensor is exposed to light, the resistance drops dramatically, even down to a few ohms, depending on the light intensity. The LDR's sensitivity varies with the wavelength of the light applied and are nonlinear devices. They are used in many applications but are sometimes made obsolete by other devices such as photodiodes and phototransistors [7].

Temperature Sensor
The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature [19]. The LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1/4°C at room temperature and ±3/4°C over a full -55°C to 150°C temperature range [19]. Low cost is assured by trimming and calibration at the water level. The LM35's low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 µA from its supply, it has very low self-heating, less than 0.1°C in still air. The LM35 is rated to operate over a -55°C to 150°C temperature range, while the LM35C is rated for a -40°C to 110°C range (-10°C with improved accuracy) [19]. The LM35 series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and LM35D are also available in the plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface mount small outline package and a plastic TO-202 package [19].

Voltage Regulator
A voltage regulator maintains a constant voltage level. A voltage regulator may be a simple "feed-forward" design or may include negative feedback control loops. It may use an electromechanical mechanism, or electronic components. Depending on the design, it may be used to regulate one or more AC or DC voltages [8]. For this effort, the Lm7805 (voltage regulator) was selected. This regulator will maintain the circuit with 5 volts and output current up to 1.5 A. The Lm7895 has 3 terminals, an internal thermal-overload protection, high power-dissipation capability, internal shortcircuit current limiting and an output transistor safe-area compensation.

Buzzer
A buzzer is an audio signaling device, that may be either mechanical, electromechanical, or piezoelectric. Typical uses of buzzers and beepers include alarm devices, timers and confirmation of user input.

LCD Screen
For displaying the sensed data, a 2 row by 16 column LCD screen was used as shown in figure 2. This LCD screen was attached to the PIC16F877A microprocessor.

Software
The following software modules were used in this research: "MIKROC PRO for PIC" in order to programming the PIC16F877A microcontroller, C++, and a K150 programmer KIT.

Methodology
The main objective of this research was to build a device containing three types of sensors that respond to the environment, display the sensed data, and to perform a simple task depending on the sensed data. All sensor data is processed by PIC16F877A microcontroller. The microcontroller was programmed to do command specific tasks depending on the sensor data. These tasks are to turn on an LED light if the room is dim, and to sound an alarm if an object is within a minimum distance from the device. These features will give the user assistance and awareness of the surrounding environment.

Research block diagram
The block diagram in Figure 3 shows the construction of the research plane and how the hardware was connected.

Sensing Light Intensity
With experimentation, it was determined that the range of the analog data from the LDR is from 100 mv to 5000 mv depending on the light intensity sensed by the LDR. Range bins were then selected for three conditions: a bright room, a mid-level bright room, and a dark room. The sensed level will then be used to determine the number of LED lights to turn on. These bins are shown in the following table 1: Results for all three room lighting conditions were successful. The device correctly sensed the lighting condition and correctly turned on the desired number of LED bulbs.
Case One -Bright Room Case Two -Mid-Level Brightness For this task, the temperature sensor will initially sense the ambient air temperature and display the measured temperature on the LCD screen. The temperature sensor is then held by a human hand with a temperature of approximately 98.6 degrees F. After a few seconds, the sensor will respond and show the sensed temperature. This sensor correctly responded to the touch and displayed the correct temperature of the hand. Figure 8 shows the results of temperature sensor. Human hand used as temperature source to raise sensed temperature.

Measuring Distance Using Ultrasonic Wave
In this test, the device measures the distance to an object using the ultrasonic sensor. When the object is less than <x> centimeters, a buzzer is sounded. The results of this test were successful. Each time the object was closer than the threshold, the buzzer was sounded. Figure 9 shows the Ultrasonic measurement of the distance from the device to the object.

Conclusion
In electronics science the electrical sensors is very important part because the electronics device go to be intelligent and more active when the sensors used inside, it's giving it feeling about the area. The conducted research studies sensors types and data that's comes out from sensors and how can be used with microcontroller to build devices that's solve problem related to the need monitoring some physical variation such as temperature, distance and lighting control. Research aims to make smart device that can be used to solve some problem like temperature control or water range meter. Also, a blind stick can be informed about distance of objective that's in front. Thus many applications can be enhanced based on this research.
Combining sensors with microcontrollers can successfully monitor the surrounding environment and accomplish simple tasks. This study effort demonstrated the feasibility of sensing the surrounding temperature, the distance to an object, and the light intensity of a room. Applications of these types of sensors can be used for many devices such as appliances, robotics, automobiles to enhance human lives and increase productivity.