Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore CU-BCA-Sem VI-IOT Based Applications

CU-BCA-Sem VI-IOT Based Applications

Published by Teamlease Edtech Ltd (Amita Chitroda), 2022-11-12 07:10:45

Description: CU-BCA-Sem VI-IOT Based Applications

Search

Read the Text Version

["A. Rotary potentiometer (the most common type) varies their resistive value due to an angular movement. For example, rotating a knob or dial attached to the shaft causes the internal wiper to sweep around a curved resistive element. The most common use of a rotary potentiometer is the volume control pot. Fig 9.6 Rotary potentiometer The rotary potentiometer can further be classified based on the number of rotations of the wiper into: 1. Single-turn pot: The wiper can make a single rotation of approximately 270270 degrees or 3\/43\/4 of a complete turn. 2. Multi-turn pot: These can make multiple rotations (mostly 5,10,5,10, or 2020) for increased precision. They are constructed either with a wiper that follows a spiral or helix form or a worm gear. 3. Dual-gang pot: It consists of two potentiometers combined on the same shaft, enabling the parallel setting of two channels. 4. Concentric pot: It consists of two potentiometers, where each pot is individually adjusted using concentric shafts. 5. Servo pot: It is a motorized potentiometer that can be automatically adjusted by a servo motor. B. Linear Potentiometer: A linear potentiometer is a type of position sensor. They are used to measure displacement along a single axis, either up and down or left and right. These are the potentiometers in which the wiper moves along a linear path. These are often called: slider, slide pot, or fader. 201 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 9.7 Linear Potentiometer There are several types of linear potentiometers. Some of them are: 1. Slide pot: Single linear slider is used for audio applications. High-quality faders are often constructed from conductive plastic. 2. Dual-Slide Pot: It consists of a single slider controlling two potentiometers in parallel. 3. Multi-turn Slide: It is constructed from a spindle that actuates a linear potentiometer wiper. 4. Motorized fader: Fader, which can be automatically adjusted by a servo motor. Potentiometer Uses The instrument designed to measure the unknown voltage by comparing it with the known voltage is the potentiometer. There are various potentiometer applications. The following are the most common potentiometer uses: 1. Audio control: Low-power potentiometers, both slide, and rotary, are used to control audio equipment, changing loudness, frequency attenuation, and other characteristics of audio signals. 2. Television: Potentiometers were formerly used to control picture brightness, contrast, and colour response. 3. Motion Control: Potentiometers can be used as position feedback devices to create closed-loop control, such as in a servomechanism. This motion control method control is the simplest method of measuring the angle of displacement. 4. Transducers: Potentiometers are also very widely used as a part of displacement transducers because of the simplicity of construction and because they can give a significant output signal. 5. Potentiometers as tuners and calibrators: Pots can be used in a circuit to tune them to get the desired output. Also, during the calibrations of a device, a preset pot is often mounted on the circuit board. 6. Potentiometers as measuring devices: The most typical application of a potentiometer is as a voltage measuring device. The name itself has that implication. It was first manufactured to measure and control the voltage. 9.3 LM35 (TEMPERATURE SENSOR) If you are looking for an inexpensive, accurate, easy-to-use temperature sensor, then LM35 is an excellent choice. It has an accuracy of \u00b1\u00bc\u00b0C at room temperature and \u00b1\u00be\u00b0C over a full 202 CU IDOL SELF LEARNING MATERIAL (SLM)","\u221255\u00b0C to 150\u00b0C temperature range. It does not require any external trimming, although the main drawback of this sensor is that it outputs data in analog format, making it very prone to external noise and interference. So, in this tutorial, we will learn how to wire up a LM35 Temperature Sensor with Arduino and also we will output the temperature data in the serial monitor window. LM35 Temperature Sensor Pinout Fig 9.8 LM35 Temperature Sensor Pinout VCC is the power supply pin of the LM35 temperature sensor IC that can be connected to 4V or 32V of the supply. GND is the ground pin of the LM35 temperature sensor IC and it should be connected to the supply ground. OUT This is the temperature sensor analog output pin. This is the analog output pin of the temperature sensor, the output voltage on this pin is directly proportional to the temperature. LM35 Temperature Sensor The LM35 is a low-power, low-cost, high-precision temperature sensor designed and manufactured by Texas instruments. This IC provides a voltage output that is linearly proportional to the change in temperature. 203 CU IDOL SELF LEARNING MATERIAL (SLM)","LM35 Temperature Sensor 10.9 The LM35 sensor is moderately precise and its robust construction makes it suitable for various environmental conditions. Additionally, you don't need any external component to calibrate this circuit and it has a typical accuracy of \u00b10.5\u00b0C at room temperature and \u00b11\u00b0C over a full \u221255\u00b0C to +155\u00b0C temperature range. It has an operating voltage of 4V to 30V and consumes 60-uA current while it's in working state, this also makes it perfect for battery- powered applications. There are two disadvantages of this sensor. The first big disadvantage of this sensor is that it cannot measure negative temperature, for that you have to bias it with a dual polarity supply. If your project requires negative temperature measurements, you can opt for a LM36 sensor. The second disadvantage of this sensor is that it's very sensitive to noise because it outputs data in analog format. If you want to learn more about this sensor you can check out the Datasheet of LM35 Temperature Sensor IC. How the LM35 Temperature Sensor Measures Temperature: The LM35 temperature sensor uses the basic principle of a diode to measure known temperature value. As we all know from semiconductor physics, as the temperature increases the voltage across a diode increases at a known rate. By accurately amplifying the 204 CU IDOL SELF LEARNING MATERIAL (SLM)","voltage change, we can easily generate a voltage signal that is directly proportional to the surrounding temperature. The screenshot below shows the internal schematic of LM35 temperature sensor IC according to the datasheet. Fig 9.10LM35 Temperature Sensor Measures Temperature (a) In practice, this diode that they are using to measure the temperature is not actually a PN Junction diode but its a diode-connected transistor. That is why the relationship between the forward voltage and the transistor is so linear. The temperature coefficient vs collector current graph below gives you a better understanding of the process. Fig 9.10 LM35 Temperature Sensor Measures Temperature (b) If you want to learn more about the topic, you can check out the documentation on Diode- Based Temperature Measurement Techniques by Texas Instruments. How does the LM35 Temperature Sensor Works in our Circuit 205 CU IDOL SELF LEARNING MATERIAL (SLM)","The working of the LM35 Temperature Sensor is very simple and easy to understand. We just have to connect 5V and Ground to the sensor and we need to measure the output voltage from the output pin. Fig 9.11working of the LM35 Temperature Sensor According to the datasheet of the device, the sensor should give us 10mv\/\u00b0C. So, if the temperature of the room is 18\u00b0C then the sensor should give us 180mV at the output pin and the animation above shows exactly that. If you connect a multimeter to the output pin of the sensor and measure the output voltage you will get something similar. If you are getting wired voltage output from the sensor then we would recommend you to go through our previous article on LM35 Temperature Sensor Not Working? where we have encountered some weird issues that we couldn't find any solution to. Commonly Asked Questions about the LM35 Temperature Sensor IC What is the LM35 temperature sensor used for? Like any other temperature sensor, it can be used for many different applications, mainly you can use it to measure body temperature of an object, and also it can measure ambient temperature. Is LM35 a thermistor? Thermistors have some benefits over other kinds of temperature sensors such as analog output chips (LM35\/TMP36 ) or digital temperature sensor chips (DS18B20) or thermocouples. What are the advantages and disadvantages of thermistors over LM35? 206 CU IDOL SELF LEARNING MATERIAL (SLM)","The main advantages of the thermistor are large temperature coefficient of resistance, high sensitivity, small heat capacity, fast response; but the main disadvantages are poor interchangeability and non-linearity of thermoelectric characteristics which is to expand the measurement. What is the minimum typical temperature that the LM35 can pick up? As the LM35 device draws only 60 \u00b5A from the supply, it has very low self-heating of less than 0.1\u00b0C in still air. The LM35 device is rated to operate over a \u221255\u00b0C to 150\u00b0C temperature range, while the LM35C device is rated for a \u221240\u00b0C to 110\u00b0C range (\u221210\u00b0 with improved accuracy). Arduino LM35 Temperature Sensor Circuit Diagram Now that we have understood how the LM35 Temperature Sensor works we can connect all the required wires to Arduino UNO. The arduino lm35 connection diagram is shown below- Fig 9.12 Arduino LM35 Temperature Sensor Circuit Diagram Connecting the LM35 sensor to the Arduino is really simple. You just need to connect 5V power to the sensor and you need to connect the output of the sensor to the A0 pin of the Arduino. Once the connection is done you need to write the code to convert the output voltage of the sensor to temperature data. For that, first, you need to convert the ADC values to voltage and multiply that voltage to 10 and you will get the output in temperature. With that, you\u2019re now ready to upload the code to Arduino. An image showing the actual Arduino LM35 hardware setup is shown below. 207 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 9.13 Arduino LM35 Temperature Sensor Code Arduino LM35 Temperature Sensor Code The Arduino Code for Interfacing the LM35 Temperature Sensor is very simple and easy to understand. We just need to read the analog data out of the sensor and convert it to temperature data. We Initialize our code by defining the pin in which the LM35 Temperature sensor is connected. #define sensor_pin A0 \/\/ LM35 is connected to this PIN Next, we have our setup() function, in the setup, we just need to initialize the serial monitor for debugging. void setup() { \/\/ Init serial at 9600 baud Serial.begin(9600); } Next we have our loop function, in the loop function we read the pin and store the ADC data in adcData variable. Next, we convert the ADC data to the voltage value and store it in a local variable named voltage, and finally, we convert the voltage value to temperature and store it in a variable named temperature and print that in the serial monitor window. At last, we added 800ms and finished the code. void loop() { 208 CU IDOL SELF LEARNING MATERIAL (SLM)","\/\/Read Raw ADC Data int adcData = analogRead(sensorPin); \/\/ Convert that ADC Data into voltage float voltage = adcData * (5.0 \/ 1024.0); \/\/ Convert the voltage into temperature float temperature = voltage * 100; \/\/ Print the temperature data Serial.print(\\\"Temperature: \\\"); Serial.print(temperature); Serial.println(\\\"*C\\\"); delay(800); \/\/ wait a second between readings } 9.4 LDR LDR (Light Dependent Resistor) as the name states is a special type of resistor that works on the photoconductivity principle means that resistance changes according to the intensity of light. Its resistance decreases with an increase in the intensity of light. It is often used as a light sensor, light meter, Automatic street lights, and in areas where we need to have light sensitivity. It is also called a Light Sensor. LDR are usually available in 5mm, 8mm, 12mm and 25mm dimensions. How are LDRs Made? The LDRs made with photosensitive semiconductor materials like Cadmium Sulphides (CdS), lead sulfide, lead selenide, indium antimonide or cadmium selenide and they are placed in Zig-Zag shape as you can see in the pic below, and two metal contacts are placed on both ends of the Zig-Zag shape these metal contacts helps in creating a connection with the LDRs. - Advertisement - Now, a transparent coating is applied on the top so that the zig-zag-shaped photosensitive material gets protected and as the coating is transparent the LDR will be able to capture light from the outer environment for its working. 209 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 9.14 LDR Symbol Working and Principle It works on the principle of photoconductivity whenever the light falls on its photoconductive material, it absorbs its energy and the electrons of that photoconductive material that is in the valence band get excited and go to the conduction band and thus increasing the conductivity as per the increased in light intensity. Also, the energy in incident light should be greater than the bandgap gap energy so that the electrons from the valence band got excited and go to the conduction band. The LDR has the highest resistance in dark around 1012 Ohm and this resistance decreases with the increase in Light. Light intensity V\/S Resistance As per the property of LDRs, the amount of light entering the LDR the inversely proportional to the resistance of the sensor, and the graph is hyperbolic in nature. Fig 9.15 A Simple LDR Component 210 CU IDOL SELF LEARNING MATERIAL (SLM)","Difference Between Photocell and LDR Photodiodes give quick response and are used where needed to detect quick response on and off like in optical communication, and optoisolators. The photodiodes are semiconductor devices and work on PN junctions. The photodiode works on the principle of converting the light energy into electric energy while the LDR is resistance and its resistance decreases with the increase in light intensity. They are generally used in automatic security lights. Whereas the Photocell, a photoelectric, photovoltaic effect or photoconductivity is used to generate a current or a voltage when exposed to light or other electromagnetic radiation. They are generally used in burglar alarms. Types of LDR or Photoresistors Intrinsic photoresistor This type of photoresistor is made with pure semiconductors without any doping. This kind of photoresistor uses pure semiconductors like silicon and germanium. when the incident light having an adequate amount of energy falls on this then electrons gain that energy and got excited and a few of them go to the conduction band. Extrinsic Photoresistor This type of photoresistor uses the doped semiconductor; this means some impurities are mixed with the semiconductor such as phosphorus to make this photoresistor. Extrinsic light-dependent resistors are generally designed for longer wavelengths of light, with a tendency towards infrared (IR). How LDRs are Tested 1. Take a multimeter and set it up in Ohms mode. 2. Now connect the positive terminal and negative terminal wires to the two sections of the LDR 3. Place an glowing torch light or any medium of light onto the surface of the LDR and check the reading. 4. Now place a hand over the LDR or place the LDR in the dark and check the multimeter reading. 5. You can see that in 1st case the value of \u03a9 would be lower than the 2nd case. In the dark, LDRs resistance are high as several megaohms, while in the light, it can get reduced to 100\u03a9 also. Applications \uf0b7 The photoresistor is generally used in detecting the presence and intensity of light \uf0b7 Used in automatic lights that switch on and off according to light 211 CU IDOL SELF LEARNING MATERIAL (SLM)","\uf0b7 Simple Smoke Detector Alarm, Clock with automatic light \uf0b7 Optical circuit design \uf0b7 Photo proximity switch \uf0b7 Laser-based security systems \uf0b7 Solar Street Lamps \uf0b7 Camera light meters \uf0b7 Clock radios \uf0b7 Can be used in Dynamic Compressors, some compressors use LDR and LED connected to the signal source to create changes in signal gain. Limitation: \uf0b7 LDRs require a few milliseconds or more to respond fully to the changes in light intensity, i.e. they require few seconds to return to their normal resistance once the light source is removed. \uf0b7 The sensitivity of an LDR varies with the light wavelength. If the wavelength is outside a certain range, it will not affect the resistance at all. \uf0b7 Light-dependent resistors have lower sensitivity than photodiodes and phototransistors. 9.5 SPEAKER WITH PROGRAMMING The main thing which makes this project super simple is that this project requires only one extra component. If you are new to Arduino, this tutorial will help you get familiar with Arduino and learn the basics of Arduino programming. This musical project has a speaker which plays out a song. If you ever want to add some sound to your existing project, you can do it easily with this Arduino speaker tutorial. You can even make a musical car reverse horn and make it play songs. You can change it easily by uploading a new program. If you still remember how you made ringtones on those old Nokia cell phones, you pretty much have all the knowledge required to make any song with this project. Let\u2019s get started. How Does the Arduino Speaker Work? The Arduino in this circuit creates tones of different frequencies and plays it through the speaker connected to it. The variation of the frequency of the tone (a.k.a. pitch) with correct timings (a.k.a. rhythm) creates music. The Arduino generates a signal and outputs it through the Digital pin 3. This drives the speaker connected to the pin to create sound. This can be 212 CU IDOL SELF LEARNING MATERIAL (SLM)","used to play different songs by modifying this program. In this tutorial, I have programmed the Arduino speaker to play a song from the Malayalam movie \u2018Ennu Ninte Moideen\u2019. Fig 9.16 tone() The program creates tones with a function, \u2018tone( )\u2019. It generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified for this. Otherwise, the wave continues until a call to noTone(). The Arduino pin can be connected to a piezo buzzer or other speakers to play the tones. Syntax: tone(pin, frequency) tone (pin, frequency, duration) Parameters pin: the pin on which to generate the tone frequency: the frequency of the tone in hertz - unsigned int duration: the duration of the tone in milliseconds (optional) - unsigned long The code below uses an extra file, pitches.h. This file contains all the pitch values for typical notes. For example, NOTE_C4 is middle C. NOTE_FS4 is F sharp, and so forth. So instead of writing the frequency in the tone( ) function, we\u2019ll just have to write the name of the note. This note table was originally written by Brett Hagman, on whose work the tone() 213 CU IDOL SELF LEARNING MATERIAL (SLM)","command was based. You may find it useful whenever you want to make musical notes for your Arduino speaker. How I made melody[ ] and noteDurations[ ] of this song: If you take a look at the program, you can find two int arrays: melody[ ] and noteDurations[ ]. It is similar to how ringtones were written in old Nokia cell phones. The first array contains the notes and the second array contains its corresponding durations. I found out the notes of this song with my guitar. I wrote down the musical notes of this song first and then wrote the melody[ ] array with that. Then I wrote noteDurations[ ] according to the length of each music note. Here 8 = quarter note, 4 = 8th note, etc. Higher value gives longer duration notes. The note and its corresponding duration is what is there in melody[ ] and noteDurations[ ] respectively. You can modify those and create any song according to your wish! Connecting the Arduino, Speaker, and Power Connect a speaker or a piezo buzzer to the Arduino with one wire to the Digital pin 3 and the other one to the ground of the Arduino. Here\u2019s what this project looks like: Fig 9.17 The Arduino speaker assembly 214 Uploading the Program The main sketch for Arduino speaker is as follows: \/*Arduino speaker song tutorial * This program will play the theme song of the Malayalam movie CU IDOL SELF LEARNING MATERIAL (SLM)","* 'Ennu Ninte Moideen'. The song is 'Mukkathe Penne'. * The song is played on the speaker connected to pin 3 and GND. * * Created 26 Oct 2015 * by Akshay James * Video at https:\/\/www.youtube.com\/watch?v=LgtcUxe8fmA *\/ #include\\\"pitches.h\\\" \/\/ notes in the song 'Mukkathe Penne' int melody[] = { NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_A4, NOTE_G4, NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_FS4, NOTE_DS4, NOTE_D4, NOTE_C4, NOTE_D4,0, NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_A4, NOTE_G4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_A4, \/\/29 \/\/8 NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_FS4, NOTE_DS4, NOTE_D4, NOTE_C4, NOTE_D4,0, NOTE_D4, NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_DS5, NOTE_D5, NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_C5, NOTE_C4, NOTE_D4, NOTE_DS4, NOTE_FS4, NOTE_D5, NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_C5, NOTE_AS4, \/\/58 NOTE_D4, NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_DS5, NOTE_D5, 215 CU IDOL SELF LEARNING MATERIAL (SLM)","NOTE_C5, NOTE_D5, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_C5, NOTE_G4, NOTE_A4, 0, NOTE_AS4, NOTE_A4, 0, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_FS4, 0, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_DS4, NOTE_C4, NOTE_D4, 0, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_DS4, NOTE_C4, NOTE_D4, END }; \/\/ note durations: 8 = quarter note, 4 = 8th note, etc. int noteDurations[] = { \/\/duration of the notes 8,4,8,4, 4,4,4,12, 4,4,4,4,4,4, 4,16,4, 8,4,8,4, 4,2,1,1,2,1,1,12, 4,4,4,4,4,4, 4,16,4, 4,4,4,4,4,4, 4,4,4,12, 4,4,4,4,4,4, 4,4,4,12, 4,4,4,4,4,4, 216 CU IDOL SELF LEARNING MATERIAL (SLM)","2,1,1,2,1,1,4,8,4, 217 2,6,4,2,6,4, 2,1,1,16,4, 4,8,4,4,4, 4,16,4, 4,8,4,4,4, 4,20, }; int speed=90; \/\/higher value, slower notes void setup() { Serial.begin(9600); for (int thisNote = 0; melody[thisNote]!=-1; thisNote++) { int noteDuration = speed*noteDurations[thisNote]; tone(3, melody[thisNote],noteDuration*.95); Serial.println(melody[thisNote]); delay(noteDuration); noTone(3); } } void loop() { \/\/ no need to repeat the melody. } CU IDOL SELF LEARNING MATERIAL (SLM)","Next, you have to create a new pitches.h file. To make that, either click on the button just below the serial monitor icon and choose \\\"New Tab\\\", or use Ctrl+Shift+N. Then paste in the following code. Fig 9.18 Uploading the Program 218 And save it as pitches.h file. #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 CU IDOL SELF LEARNING MATERIAL (SLM)","#define NOTE_CS2 69 219 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 CU IDOL SELF LEARNING MATERIAL (SLM)","#define NOTE_G4 392 220 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 CU IDOL SELF LEARNING MATERIAL (SLM)","#define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978 #define END -1 Using Your Arduino Speaker Now upload the main sketch to finish the Arduino speaker project by clicking the upload button. The song will then start playing. And if you open the serial monitor, you can see the frequencies of the output tone. 221 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 9.19Using Your Arduino Speaker 9.6 SUMMARY The potentiometer is an electrical instrument generally used to measure the potential difference in a circuit. It can also be used to find the EMF of a given cell or compare the two cells\u2019 EMF. Further, we can use it to find the internal resistance. It does not draw any current from the circuit, giving a more accurate reading than a voltmeter. It consists of a long wire (manganin or constantan) with a uniform area of cross-section. It works on the principle that the potential drop across a segment of a wire of uniform cross-section carrying a constant current is directly proportional to its length. 1. To calculate unknown potential: Let K=V\/LK=V\/L be the potential gradient of the given potentiometer, where VV is the potential difference between two points and is the distance between two points. Then, K=I\u03c1\/A.K=I\u03c1\/A. 2. To compare the EMF of two cells: Let the first cell of EMF E1E1 given a null point at a length L1L1 and the second cell of EMF E2E2 show a null point at length L2.L2. Then, E1E2=L1L2.E1E2=L1L2. 222 CU IDOL SELF LEARNING MATERIAL (SLM)","3. To find internal resistance of a cell: r=R(L\u2013l)lr=R(L\u2013l)l where rr is the unknown resistance. 9.7 KEYWORDS \uf0b7 Sensor: A device or component that perceives and responds to physical input from the environment. \uf0b7 Sensor Network: A group of sensors with a communications infrastructure intended to monitor and collect data from multiple locations. \uf0b7 Single-Board Computer: A complete computer built on a single circuit board with all the components required of a functional computer. \uf0b7 Site-Level Management: Allows site-level arrangement across devices from different vendors using dissimilar protocols. \uf0b7 Store and Forward: A messaging mechanism in which a broker is involved between sender and receiver so that the broker gets ownership of the message from the sender, stores it for reliability, and then delivers the message itself to the receiver. \uf0b7 System on a Chip: An integrated chip that is comprised of electronic circuits of multiple computer components to create a complete device. 9.8LEARNING ACTIVITY 1. Draw IoT-Based Smart Street Light System 2. What is Potentiometer Definition? 9.9 UNIT END QUESTIONS A. Descriptive questions Short Questions 1. Explain LM35 2. Explain LDR 3. What does a potentiometer measure? 4. What is a potentiometer, and how does it work? 5. Is the potentiometer analogue or digital? 223 CU IDOL SELF LEARNING MATERIAL (SLM)","Long Questions 224 1. What are the types of potentiometer? 2. What are the potentiometer applications? 3. Which type of potentiometer is used for volume control? 4. Why is a potentiometer preferred over a voltmeter? 5. How can we increase the sensitivity of a potentiometer? 6. Where can I find the study material on the topic of a potentiometer? A. Multiple Choice Questions 1. ENOB stands for_________ a) Effective no of bits b) Effective no of bytes c) Efficient no of bits d) Efficient no of bytes Answer: a 2. Perfect resolution is possible when? a) sampling rate greater than thrice the bandwidth of the signal b) sampling rate greater than twice the bandwidth of the signal c) sampling rate less than twice the bandwidth of the signal d) sampling rate less than thrice the bandwidth of the signal Answer: b 3. Resolution is expressed in __________ a) Bytes b) Bits c) Word d) Nibble Answer: b 4. The discrete levels available are_________ a) Sides CU IDOL SELF LEARNING MATERIAL (SLM)","b) Edges c) Levels d) Bytes Answer: c 5. Resolution is expressed in terms of_________ a) Milli volts b) Ampere c) Milli ampere d) Volts Answer: d 9.10 REFERENCES Text Books: - 1. Internet of Things (A Hands on Approach), By ArshdeepBahga (Author),VijayMadisetti(Author). Edition: Second Edition, Illustrated, Reprint (2014) Publisher: VPT, 2017 2. \u201cBeginning Arduino\u201d by Michael McRobetrs(Author). Publisher:Technology in Action Reference Books: - 1. Tim Cox, Dr. Steven Lawrence Fernandes, Sai Yamanoor, Srihari Yamanoor, Prof. DiwakarVaish,\u201d Getting Started with Python for the Internet of Things: Leverage the full potential of Python to prototype and build IoT projects using the RaspberryPi Edition: First Edition Publisher:Packt Publisher-2019 225 CU IDOL SELF LEARNING MATERIAL (SLM)","UNIT - 10EMBEDDED SYSTEM APPLICATIONS USING ARDUINO 1 STRUCTURE 10.0 Learning Objectives 10.1 Introduction 10.2 Timers\/counters with programming 10.3 Emphasis on various real world applications via Interfacing Bluetooth and controlling by android phone 10.4 Summary 10.5 Keywords 10.6 Learning Activity 10.7 Unit End Questions 10.8 References 10.0 LEARNING OBJECTIVES After studying this unit, you will be able to: \uf0b7 Understand Timers with programming \uf0b7 Understand counters with programming \uf0b7 Emphasis on various real world applications via Interfacing Bluetooth and controlling by android phone 10.1 INTRODUCTION In the traditional world, Computers were used to Process Payroll, Accounts, and inventory records related to mainly Business applications. This mainframe, mini, super mini-computers with separate CPU, Memory, physical storage, and controlling unit were assembled as boxes and these units were operated from Datacenters that had central cooling and power facility. Then came personal computers on the desk with office Arduino Application for day-to-day activity and also acted as a client to the servers for data and other services. 226 CU IDOL SELF LEARNING MATERIAL (SLM)","In the Digital world, there is a need to connect computers to any objects or devices, take inputs from its operating units, control the operation using the inputs and pass on the data collected to the central system for further operations. The object may be stationary or moving. Data from moving objects is collected over mobile networks. The embedded computers connected to the objects should be small enough to be managed within the object and it should be self-sufficient to perform the intended function. The Embedded system is designed to perform specific tasks in the device it is connected to and it has both hardware and software in it. It may or may not have a user interface depending on the application. 10.2 TIMERS\/COUNTERS WITH PROGRAMMING The Arduino Development Platform was originally developed in 2005 as an easy-to-use programmable device for art design projects. Its intention was to help non-engineers to work with basic electronics and microcontrollers without much programming knowledge. But then, because of its easy to use nature it was soon adapted by electronics beginners and hobbyists around the world and today it is even preferred for prototype development and POC developments. While it is okay to begin with Arduino, it is important to slowly move into the core microcontrollers like AVR, ARM, PIC, STM, etc. and program it using their native applications. This is because the Arduino Programming language is very easy to understand as most of the work is done by pre-built functions like digitalWrite(), AnalogWrite(), Delay(), etc. while the low level machine language is hidden behind them. The Arduino programs are not similar to other Embedded C coding where we deal with register bits and make them high or low based on the logic of our program. Arduino Timers without delay: Hence, to understand what is happening inside the pre-built functions we need to dig behind these terms. For example when a delay() function is used it actual sets the Timer and Counter Register bits of the ATmega microcontroller. In this arduino timer tutorial we are going to avoid the usage of this delay() function and instead actually deal with the Registers themselves. The good thing is you can use the same Arduino IDE for this. We will set our Timer register bits and use the Timer Overflow Interrupt to toggle an LED every time the interrupt occurs. The preloader value of the Timer bit can also be adjusted using pushbuttons to control the duration in which the interrupt occurs. What is TIMER in Embedded Electronics? 227 CU IDOL SELF LEARNING MATERIAL (SLM)","Timer is kind of interrupt. It is like a simple clock which can measure time interval of an event. Every microcontroller has a clock (oscillator), say in Arduino Uno it is 16Mhz. This is responsible for speed. Higher the clock frequency higher will be the processing speed. A timer uses counter which counts at certain speed depending upon the clock frequency. In Arduino Uno it takes 1\/16000000 seconds or 62nano seconds to make a single count. Meaning Arduino moves from one instruction to another instruction for every 62 nano second. Timers in Arduino UNO: In Arduino UNO there are three timers used for different functions. Timer0: It is an 8-Bit timer and used in timer function such as delay(), millis(). Timer1: It is a 16-Bit timer and used in servo library. Timer2: It is an 8-Bit Timer and used in tone() function. Arduino Timer Registers To change the configuration of the timers, timer registers are used. 1. Timer\/Counter Control Registers (TCCRnA\/B): This register holds the main control bits of the timer and used to control the prescalers of timer. It also allows to control the mode of timer using the WGM bits. Frame Format: TCCR1 7 6 5 4 3 2 10 A COM1A COM1A COM1B COM1B COM1C COM1C WGM1 WGM1 1 0 1 0 1 0 10 TCCR1B 7 6 5 4 3 2 1 0 ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10 Prescaler: The CS12, CS11, CS10 bits in TCCR1B sets the prescaler value. A prescaler is used to setup the clock speed of the timer. Arduino Uno has prescalers of 1, 8, 64, 256, 1024. 228 CU IDOL SELF LEARNING MATERIAL (SLM)","CS12 CS11 CS10 USE 0 0 0 No Clock Timer STOP 0 0 1 CLCK i\/o \/1 No Prescaling 0 1 0 CLK i\/o \/8 (From Prescaler) 0 1 1 CLK i\/o \/64 (From Prescaler) 1 0 0 CLK i\/o \/256 (From Prescaler) 1 0 1 CLK i\/o \/1024 (From Prescaler) External clock source on T1 Pin. Clock on 11 0 falling edge External Clock source on T1 pin. Clock on 11 1 rising edge. 2. Timer\/Counter Register (TCNTn) This Register is used to control the counter value and to set a preloader value. Formula for preloader value for required time in second: TCNTn = 65535 \u2013 (16x1010xTime in sec \/ Prescaler Value) To calculate preloader value for timer1 for time of 2 Sec: TCNT1 = 65535 \u2013 (16x1010x2 \/ 1024) = 34285 Arduino Timer Interrupts We previously learned about Arduino Interrupts and have seen that Timer interrupts are kind of software interrupts. There are various timer interrupts in Arduino which are explained below. Timer Overflow Interrupt: Whenever the timer reaches to its maximum value say for example (16 Bit-65535) the Timer Overflow Interrupt occurs. So, an ISR interrupt service routine is called when the Timer Overflow Interrupt bit enabled in the TOIEx present in timer interrupt mask register TIMSKx. ISR Format: ISR(TIMERx_OVF_vect) 229 CU IDOL SELF LEARNING MATERIAL (SLM)","{ } Output Compare Register (OCRnA\/B): Here when the Output Compare Match Interrupt occurs then the interrupt service ISR (TIMERx_COMPy_vect) is called and also OCFxy flag bit will be set in TIFRx register. This ISR is enabled by setting enable bit in OCIExy present in TIMSKx register. Where TIMSKx is Timer Interrupt Mask Register. Timer Input Capture: Next when the timer Input Capture Interrupt occurs then the interrupt service ISR (TIMERx_CAPT_vect) is called and also the ICFx flag bit will be set in TIFRx (Timer Interrupt Flag Register). This ISR is enabled by setting the enable bit in ICIEx present in TIMSKx register. Components Required \uf0b7 Arduino UNO \uf0b7 Push Buttons (2) \uf0b7 LED (Any Color) \uf0b7 10k Resistor (2), 2.2k (1) \uf0b7 16x2 LCD Display Circuit Diagram 230 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 10 1 Circuit Diagram Circuit Connections between Arduino UNO and 16x2 LCD display: 16x2 LCD Arduino UNO VSS GND VDD +5V To potentiometer centre pin for contrast V0 control of LCD RS 8 RW GND E9 D4 10 D5 11 D6 12 D7 13 A +5V K GND Table 10.1 Circuit Connections between Arduino UNO and 16x2 LCD display Two Push buttons with pull down resistors of 10K are connected with the Arduino pins 2 & 4 and a LED is connected to PIN 7 of Arduino through a 2.2K resistor. The setup will look like below image. 231 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig. 10.2 Push buttons Programming Arduino UNO Timers In this tutorial we will use the TIMER OVERFLOW INTERRUPT and use it to blink the LED ON and OFF for certain duration by adjusting the preloader value (TCNT1) using pushbuttons. Complete code for Arduino Timer is given at the end. Here we are explaining the code line by line: As 16x2 LCD is used in the project to display the preloader value, so liquid crystal library is used. #include<LiquidCrystal.h> The LED anode pin that is connected with Arduino pin 7 is defined as ledPin. #define ledPin 7 Next the object for accessing Liquid Crystal class is declared with the LCD pins (RS, E, D4, D5, D6, D7) that are connected with Arduino UNO. LiquidCrystal lcd(8,9,10,11,12,13); Then set the preloader value 3035 for 4 seconds. Check the formula above to calculate the preloader value. float value = 3035; Next in void setup(), first set the LCD in 16x2 mode and display a welcome message for few seconds. lcd.begin(16,2); lcd.setCursor(0,0); lcd.print(\\\"ARDUINO TIMERS\\\"); delay(2000); 232 CU IDOL SELF LEARNING MATERIAL (SLM)","lcd.clear(); Next set the LED pin as OUTPUT pin and the Push buttons are set as INPUT pins pinMode(ledPin, OUTPUT); pinMode(2,INPUT); pinMode(4,INPUT); Next disable all the interrupts: noInterrupts(); Next the Timer1 is initialized. TCCR1A = 0; TCCR1B = 0; The preloader timer value is set (Initially as 3035). TCNT1 = value; Then the Pre scaler value 1024 is set in the TCCR1B register. TCCR1B |= (1 << CS10)|(1 << CS12); The Timer overflow interrupt is enabled in the Timer Interrupt Mask register so that the ISR can be used. TIMSK1 |= (1 << TOIE1); At last all interrupts are enabled. interrupts(); Now write the ISR for Timer Overflow Interrupt which is responsible for turning LED ON and OFF using digitalWrite. The state changes whenever the timer overflow interrupt occurs. ISR(TIMER1_OVF_vect) { TCNT1 = value; digitalWrite(ledPin, digitalRead(ledPin) ^ 1); } In the void loop() the value of preloader is incremented or decremented by using the push button inputs and also the value is displayed on 16x2 LCD. if(digitalRead(2) == HIGH) { value = value+10; \/\/Incement preload value 233 CU IDOL SELF LEARNING MATERIAL (SLM)","} if(digitalRead(4)== HIGH) { value = value-10; \/\/Decrement preload value } lcd.setCursor(0,0); lcd.print(value); } So this is how a timer can be used to produce delay in Arduino program. Check the video below where we have demonstrated the change in delay by increasing and decreasing the preloader value using Push buttons. Code #include<LiquidCrystal.h> \/\/LCD display library #define ledPin 7 LiquidCrystal lcd(8,9,10,11,12,13); float value = 3035; \/\/Preload timer value (3035 for 4 seconds) void setup() { lcd.begin(16,2); lcd.setCursor(0,0); lcd.print(\\\"ARDUINO TIMERS\\\"); delay(2000); 234 CU IDOL SELF LEARNING MATERIAL (SLM)","lcd.clear(); pinMode(ledPin, OUTPUT); pinMode(2,INPUT); pinMode(4,INPUT); noInterrupts(); \/\/ disable all interrupts TCCR1A = 0; TCCR1B = 0; TCNT1 = value; \/\/ preload timer TCCR1B |= (1 << CS10)|(1 << CS12); \/\/ 1024 prescaler TIMSK1 |= (1 << TOIE1); \/\/ enable timer overflow interrupt ISR interrupts(); \/\/ enable all interrupts } ISR(TIMER1_OVF_vect) \/\/ interrupt service routine for overflow { 235 CU IDOL SELF LEARNING MATERIAL (SLM)","TCNT1 = value; \/\/ preload timer digitalWrite(ledPin, digitalRead(ledPin) ^ 1); \/\/Turns LED ON and OFF } void loop() { if(digitalRead(2) == HIGH) { value = value+10; \/\/Incement preload value } if(digitalRead(4)== HIGH) { value = value-10; \/\/Decrement preload value } lcd.setCursor(0,0); lcd.print(value); } 236 CU IDOL SELF LEARNING MATERIAL (SLM)","10.3 EMPHASIS ON VARIOUS REAL WORLD APPLICATIONS VIA INTERFACING BLUETOOTH AND CONTROLLING BY ANDROID PHONE While buttons, LEDs, and character LCDs were sufficient for interfacing with the embedded systems of the past, future embedded systems will be more intelligent, configurable, and connected, requiring a new approach to the user interface. Modern users are accustomed to more advanced user interfaces, ones with touchscreens, and on-screen keyboards. But LCDs and touchscreens add unwanted cost adders to embedded system products in the form of board cost, and software support. Luckily there are better and more cost effective ways to provide your embedded system with an easily programmable user interface. Instead of building an embedded system with a LCD and touchscreen, why not take advantage of the LCD and touchscreen that most people carry in their pocket every day? I am, of course, referring to Android\u2013enabled smart phones and tablets. The Android OS provides a variety of features for interfacing with future embedded systems. But can Android communicate with embedded systems? The short answer is: yes! Here are four ways embedded system engineers can use Android\u2013 enabled devices in design. 1. Universal Serial Bus The Universal Serial Bus (USB) is the connector used to charge Android phones and tablets and sync them with a PC. That same connector can also be used to communicate with an embedded system. This method ONLY works with Android phones, however (iPhones use proprietary communications on their ports). This interface method is being promoted by Google in the form of The Accessory Development Kit (ADK). ADK was designed by Google to aid in the interfacing of Android products with embedded systems. Connecting an Android device over USB to an embedded system makes the Android device the User Interface for the embedded system. By using the Android device the user has full access to a touchscreen, and can use touchscreen gestures like zoom, scroll, and pan, as 237 CU IDOL SELF LEARNING MATERIAL (SLM)","well as various other features of the device interface, to configure or control the embedded system. When the user is done, they simply unplug their device. Using this method could even charge the Android device while it\u2019s being used to interface with the embedded system. Adding USB technology greatly enhances the user interface experience and adds about $5.00 to the cost of the board. 2. Near Field Communications Near Field Communications (NFC) is the simplest way to take advantage of the Android interface with your embedded system. NFC is a license free, bidirectional communication system, with a range of approximately one foot. It can be added to an embedded system for less than one dollar, making it not only the simplest but by far the least expensive option. This method is ideal for configuring an embedded system. The fancy graphics, complex calculation, GPS positioning, and internet communications available on the Android OS are all implemented as part of an application on the smart device. The user needs only to run the application on their smart device, fill out the any required parameters using the Android user interface, and then hold their personal smart device close to the embedded appliance. The smart device uses NFC to transfer all the configuration information from the device onto the embedded system. Once the transfer is complete, the embedded system is configured, and will start to work immediately, the user can then leave the vicinity of the embedded system with their smart device. Later, if the user wants to retrieve information stored in the embedded system for any reason, they can move their smart device back into the vicinity of the embedded system and use NFC to read the desired data. 3. WiFi Another option for enabling a smart device to interface with embedded systems is to add WiFi to the embedded system. In the past, adding WiFi to an embedded system was prohibitively expensive. However, with the current state of WiFi technology, WiFi can be added to an embedded system for as little as $10.00. 238 CU IDOL SELF LEARNING MATERIAL (SLM)","While this is the most expensive of the options presented here, it is still significantly less than the cost of a touch panel LCD. An embedded system with WiFi can serve web pages to, and allow interface with, ANY smart device or tablet (not just one running the Android OS). Using a web interface to configure or control an embedded device is a simple method of adding an advanced user interface to an embedded product. Unlike NFC with its radio range of only one foot, the embedded device and the smart device can communicate over long distances. In fact, by connecting to the cloud, the embedded device can be configured and controlled by ANY WiFi enabled device from anywhere in the world where there is WiFi. So, while this is the most expensive of the options listed, it is also the most versatile. 4. Bluetooth Bluetooth is also supported by almost all smart devices and it has the advantage of being cheaper on the embedded system side. At about $5.00, adding Bluetooth is about equal in cost to adding USB, making it, along with USB, a mid-range option between NFC and WiFi. It has better radio range than NFC, but not as good range as WiFi. Like NFC, Bluetooth is a point-to-point communication system, but it has a data transfer rate that is an order of magnitude faster. The biggest problem with Bluetooth is in its lack of compatibility. Not all smart devices support the Bluetooth profiles required to communicate with embedded systems. There are a variety of options, at price points ranging from less than $1 to around $10, to take advantage of Android and enhance the user interface experience when designing embedded products. There is no longer a need to invest in expensive LCD and touchscreen technology, instead use the many options available to Android OS users and, in the case of WiFi ANY device, to provide embedded systems with an easily programmable user interface. 10.3 SUMMARY \uf0b7 Arduino is an inexpensive solution as compared with other microcontroller and Development environment runs in windows, Mac, Linux OS. \uf0b7 This platform is open-sourced and provides a good platform for students to develop pilot projects and develop new technology. 239 CU IDOL SELF LEARNING MATERIAL (SLM)","\uf0b7 An embedded system is a combination of computer hardware and software designed for a specific function. Embedded systems may also function within a larger system. The systems can be programmable or have a fixed functionality. Industrial machines, consumer electronics, agricultural and processing industry devices, automobiles, medical equipment, cameras, digital watches, household appliances, airplanes, vending machines and toys, as well as mobile devices, are possible locations for an embedded system. \uf0b7 While embedded systems are computing systems, they can range from having no user interface (UI) -- for example, on devices designed to perform a single task -- to complex graphical user interfaces (GUIs), such as in mobile devices. User interfaces can include buttons, LEDs (light-emitting diodes) and touchscreen sensing. Some systems use remote user interfaces as well. 10.4 KEYWORDS \uf0b7 Radio Frequency Identification (RFID): A technology that incorporates electromagnetic coupling and radio frequency to identify objects and persons. It consists of three components: an antenna, transceiver, and transponder. \uf0b7 Real-Time Operating System (RTOS): Designed to guarantee the completion of a task within a certain time constraint. Often used in safety-critical systems and when building IoT devices. \uf0b7 Releasability: The ability to quickly deploy changes to a software system, but also to quickly recover from disaster and adapt to changing technical and business challenges. 10.5 LEARNING ACTIVITY 240 1. Give real world applications of embedded systems. 2. How DMA plays an important role in embedded systems. 10.6 UNIT END QUESTIONS A.Descriptive questions Short Questions 1. Explain timers with example 2. Explain counters with example 3. What are real-time embedded systems? CU IDOL SELF LEARNING MATERIAL (SLM)","4. Why do embedded systems matter? Long Questions 1. What is a microcontroller? 2. What is the DMA address used for? 3. What is interrupt latency? Can it be reduced? 4. What is a Watchdog Timer? 5. What is an embedded system? What are the components of embedded system? A. Multiple Choice Questions 1. Which of the following is a coprocessor of 80386? a) 80387 b) 8087 c) 8089 d) 8088 Answer: a 2. Name the processor which helps in floating point calculations. a) microprocessor b) microcontroller c) coprocessor d) controller Answer: c 3. Which is the coprocessor of 8086? a) 8087 b) 8088 c) 8086 d) 8080 Answer: a 4. Which of the following is a coprocessor of Motorola 68000 family? a) 68001 b) 68011 c) 68881 241 CU IDOL SELF LEARNING MATERIAL (SLM)","d) 68010 Answer: c 5. Which of the following processors can perform exponential, logarithmic and trigonometricfunctions? a) 8086 b) 8087 c) 8080 d) 8088 Answer: b 10.7 REFERENCES Text Books: - 1. Internet of Things (A Hands on Approach), By ArshdeepBahga (Author),VijayMadisetti(Author). Edition: Second Edition, Illustrated, Reprint (2014) Publisher: VPT, 2017 2. \u201cBeginning Arduino\u201d by Michael McRobetrs(Author). Publisher:Technology in Action Reference Books: - 1. Tim Cox, Dr. Steven Lawrence Fernandes, Sai Yamanoor, Srihari Yamanoor, Prof. DiwakarVaish,\u201d Getting Started with Python for the Internet of Things: Leverage the full potential of Python to prototype and build IoT projects using the RaspberryPi Edition: First Edition Publisher:Packt Publisher-2019 242 CU IDOL SELF LEARNING MATERIAL (SLM)","UNIT - 11EMBEDDED SYSTEM APPLICATIONS USING ARDUINO 2 STRUCTURE 11.0 Learning Objectives 11.1 Introduction 11.2 Interfacing Ultrasonic Sensor to calculate distance. 11.3 Interfacing DC Motors 11.4 Summary 11.5 Keywords 11.6 Learning Activity 11.7 Unit End Questions 11.8 References 11.0 LEARNING OBJECTIVES After studying this unit, you will be able to: \uf0b7 Understand Interfacing Ultrasonic Sensor to calculate distance. \uf0b7 Know how to Interface DC Motors 11.1 INTRODUCTION An embedded system can be thought of as a computer hardware system having software embedded in it. An embedded system can be an independent system or it can be a part of a large system. An embedded system is a microcontroller or microprocessor based system which is designed to perform a specific task. 11.2 INTERFACING ULTRASONIC SENSOR TO CALCULATE DISTANCE Hardware Requirements 243 CU IDOL SELF LEARNING MATERIAL (SLM)","1. Arduino UNO board 2. USB cable connecter for Arduino UNO 3. Ultra Sonic HC-SR04 4. Jumper wires male to female Software requirements 1. Arduino software 2. Processing software The working principle of Arduino-Bluetooth Module The Ultra Sonic HC-SR04 emits ultrasound at 40,000Hz that travels in the air. If there is an object or obstacle in its path, then it collides and bounces back to the Ultra Sonic module. The formula distance = speed*time is used to calculate the distance. Suppose, an object is placed at a distance of 10 cm away from the sensor, the speed of sound in air is 340 m\/s or 0.034 cm\/\u00b5s. It means the sound wave needs to travel in 294 \u00b5s. But the Echo pin double the distance (forward and bounce backward distance). So, to get the distance in cm multiply the received travel time value with echo pin by 0.034 and divide it by 2. Fig 11.1 Interfacing Ultrasonic Sensor to calculate distance 244 CU IDOL SELF LEARNING MATERIAL (SLM)","The distance between Ultra Sonic HC-SR04 and an object is: For doing programming of Arduino device, it requires Arduino software IDE. The complete process of downloading and installation of Arduino software IDE is given at link controlling home light using WiFi Node MCU, and Relay module. Open Arduino IDE and paste the following code. 1. #include <Mouse.h> 2. 3. const int trigpin= 8; 4. const int echopin= 7; 5. long duration; 6. int distance; 7. void setup(){ 8. pinMode(trigpin,OUTPUT); 9. pinMode(echopin,INPUT); 10. Serial.begin(9600); 11. } 12. 13. void loop(){ 14. digitalWrite(trigpin,HIGH); 15. delayMicroseconds(10); 245 CU IDOL SELF LEARNING MATERIAL (SLM)","16. digitalWrite(trigpin,LOW); 17. duration=pulseIn(echopin,HIGH); 18. distance = duration*0.034\/2; 19. Serial.println(distance); 20. } Save your program and compile it. Fig 11.2 Speed of Sound Connect your Arduino device to your Laptop (or Monitor) via Arduino UNO USB cable. Remove all the other connections with Arduino UNO device such as Ultrasonic module while uploading the program in Arduino UNO. Upload the code in Arduino UNO device. Before uploading the code in Arduino UNO device make sure your Arduino serial port is selected otherwise, it generates an error message Serial port not selected. To select your serial port open Device Manager > Ports >Arduino Uno, and then upload your code. 246 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 11.3 port not selected (a) Upload your program in Arduino device Fig 11.3 port not selected (b) Digital circuit diagram 247 CU IDOL SELF LEARNING MATERIAL (SLM)","Ultrasonic Sensor HC-SR04 Arduino UNO VCC --------------------------------> 5v Trig --------------------------------> Pin 8 Echo --------------------------------> Pin 7 GND --------------------------------> GND Now download the Processing from https:\/\/processing.org\/download\/. Fig 11.4 Ultrasonic Sensor HC-SR04 Arduino UNO (a) Follow the instruction to install the Processing app. 248 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 11.4 Ultrasonic Sensor HC-SR04 Arduino UNO (b) Paste the following code in the Processing IDE and run it. The Processing IDE displays the distance between Ultra Sonic module and an object. 1. import processing.serial.*; 249 CU IDOL SELF LEARNING MATERIAL (SLM)","2. Serial myPort; 3. String data=\\\"\\\" ; 4. PFont myFont; 5. 6. void setup(){ 7. size(1366,900); \/\/ size of processing window 8. background(0);\/\/ setting background color to black 9. myPort = new Serial(this, \\\"COM3\\\", 9600); 10. myPort.bufferUntil('\\\\n'); 11. } 12. 13. void draw(){ 14. background(0); 15. textAlign(CENTER); 16. fill(255); 17. text(data,820,400); 18. textSize(100); 19. fill(#4B5DCE); 20. text(\\\" Distance : cm\\\",450,400); 21. noFill(); 22. stroke(#4B5DCE); 23. } 24. 25. void serialEvent(Serial myPort){ 26. data=myPort.readStringUntil('\\\\n'); 27. } 250 CU IDOL SELF LEARNING MATERIAL (SLM)"]


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook