Build a gas leak system - Internet of Things - ثاني ثانوي
Part 1
1. IoT Fundamentals
2. The IoT in Our Lives
3. Building IoT applications with Arduino
4. Building an IoT cloud application
Part 2
5. IoT Advanced Applications
6. ++IoT Programming With C
7. IoT messaging
8. IoT Wireless Sensor Network Simulation
Lesson 3 Build a Gas Leak System Build a Gas Leak Alarm System Many facilities, such as houses and working environments, are susceptible to gas leaks from appliances or have flammable materials that impose fire hazards. One method to prevent accidents is to equip those areas with smart gas detection systems. This is a circuit that uses the Arduino UNO R3 to simutate a Gas Leak Alarm System. When the Arduino receives a signal from the gas sensor indicating high smoke concentration, it will send signals to the LEDs to flash alternately and to the Piezo buzzer to make a short beeping sound. In this project you will be using the following components: • 1 Piezo • 1 Gas Sensor • 2 LEDs • 3. Resistors ⚫1 Arduino Uno R3 •1 Breadboard Small Components that you will use in this project LEDS Link to digital lesson www.len.edusa Resistors Piezo تعليم Gas Sensor Arduino Uno R3 Breadboard Small 173-1489 100 Figure 1.29 Project components
Build a Gas Leak Alarm System
We will start by adding the components that you will need for this project to the workplane. First, find the Arduino UNO R3 and the Breadboard. To add the Arduino UNO R3 and the Breadboard: > Drag and drop the Arduino UNO R3 from the components library to the workplane. > Drag and drop the Breadboard Small from the components library to the workplane. Gas Leak Alarm System وزارة الصدر 1 COLL 2 To Figure 3.30 Add the Arduino UNO 13 and the Breadboard 101
We will start by adding the components that you will need for this project to the workplane.
102 Now, find the Gas Sensor and the Piezo buzzer, and connect them to the Breadboard. To add components to the Breadboard Small: > Find the Gas Sensor from the components library and drag and drop it into the Breadboard. > Drag and drop the Piezo from the components library into the Breadboard. Gas Loak Alarm System 2 وزارة التعليم H1 Α1 AZ B1 BZ H2 Figure 3.31 Gas Sensor 27 Code All Seych You can find the Gas Sensor by changing the components library to "All". 3 Figure 3.32 Add components to the Breadboard Quig 1 00 Sind To
Now, find the Gas Sensor and the Piezo buzzer, and connect them to the Breadboard.
Continue by adding two LEDs to the Breadboard and changing their colors. To add LEDs: > Drag and drop an LED from the components library into the Breadboard and change its color to orange. > Drag and drop another LED into the Breadboard and change its color to green. 2 Next, add resistors to the circuit and change their resistance to 2200. You will need three resistors; one for each LED and one for the Gas Sensor. To add Resistors: > Drag and drop two resistors from the components library and connect them to the anodes of the LEDs. > Drag and drop another resistor from the components library and connect it to the negative column of the Breadboard and to the Gas Sensor pin A1. > Set the Resistance of each resistor to 2200. Figure 3.33 Auld LEDs All LEDs have two states, on and off. When they are not lit, their color is darker. For example, the orange LED has a brown color. Resistor Name 1 Kristalic 220 3 Code fghij 2 حرارة 2 4 55 619 S (146) DE Figure 3.34 Add Resistors 103
Continue by adding two LEDs to the Breadboard and changing their colors.
104 Proceed with wiring the circuit. First, you will connect the Arduino to the Breadboard. To wire the Arduino Microcontroller > Connect the Arduino UNO R3 5V to the positive column of the Breadboard and change the wire color to red. > Connect the Arduino UNO R3 GND to the negative column of the Breadboard and change the wire color to black. > Connect the two negative columns of the Breadboard and change the wire color to black. دارة التعليم POWER ANALOG IN 1 2 Figure 3.15: Wire the Arduino Microcontroller R 3
Proceed with wiring the circuit. First, you will connect the Arduino to the Breadboard.
Continue by wiring the Piezo buzzer. To wire the Piezo: > Connect the Piezo Positive pin to Analog pin A2 of the Arduino and change the wire color to yellow. > Connect the Piezo Negative pin to the negative column of the Breadboard and change the wire color to black. Das Lesk Alim steni www INO ANALOG IN وزارة التعليم 1 0 2 Figure 3.36 Wire The Prezo 105
Continue by wiring the Piezo buzzer.
106 Next, you will connect the LEDs. To wire the LEDs: > Connect the cathode of the Orange LED to the negative column of the Breadboard and change the wire color to black. > Connect the resistor of the Orange LED to Digital pin 3 and change the wire color to orange. > Connect the cathode of the Green LED to the negative column of the Breadboard and change the wire color to black. > Connect the Resistor of the Green LED to Digital pin 2 and change the wire color to green. Gas Leak Alarm System UNO وزارة التعليم 2 Figure 3.J7 Wire Ine LEDs 3 | 0
Next, you will connect the LEDs.
Finally, you will wire the Gas Sensor. To wire the Gas Sensor: > Connect the Gas Sensor H1 pin to the negative column of the Breadboard and change the wire color to black. > Connect the Gas Sensor A2 pin to the Arduino Analog pin A4 and change the wire color to purple. > Connect the Gas Sensor B1 pin to the positive column of the Breadboard and change the wire color to red. > Connect the Gas Sensor H2 pin to the positive column of the Breadboard. > Connect the Gas Sensor B2 pin to the positive column of the Breadboard. Gas Lesk Arm System VM-) € ANALOG IN وزارة الصايم 461 abcde 3 1 2 HBA 4 5 ཋ ཋ ཐ མ- !| * h Figure 3. Wire the Gas Sensor 107
Finally, you will wire the Gas Sensor.
108 How the Gas Sensor Works: The Gas Sensor has 6 pins; two A, two B and two H pins. The way it works is by detecting gas particles and transforming different concentrations to different electric voltages. The purpose of the H pins is to warm the heater coil, which in turn activates the electrochemical sensor. One H pin must connect to a VCC (e.g. 5V or 3.3V) and the other H pin to Ground. To transmit data from the Gas Sensor to be transmitted to the Arduino, either the A or the B pair has to be connected. One pin of the pair must connect to a VCC and the other pin to Ground through a resistor so the sensor's sensitivity can be adjustable. The unused pins must be connected to a VCC. A1 B1 141 A2 B2 H2 Figure 39, Gas Sellsor The Piezo Buzzer The Piezo buzzer can produce a wide array of sounds of different tone and duration. To make the speaker on pin A2 play a tone of 110Hz for 1 second, use: play speaker on pin A2 with lone 110 for 1 seo Duration is in seconds, but you may be less familiar with the units for the tone. These values correspond to the frequencies of musical notes, measured in Hertz (Hz). Some musical notes and their tones, if you want to try them, are shown here: Table 3.3: Sound frequencies Notes Frequencies LA 110 Hz DO 131 Mz RE 147 HA FA 175 Hz Tone Duration
How the Gas Sensor Works:
The Piezo Buzzer
Table 3.3: Sound frequencies
Gas Leak Alarm System Code Now that we have wired our circuit and looked at how Gas Sensors and Piezo Buzzers work, it's time to write the code for our alarm system. The program monitors the output from the Gas Sensor to check if there is a fire hazard. If it detects a hazard, it raises the alarm by sounding the Piezo and flashing the LEDs. If not, the program waits before checking again. If it is, it alarms by playing a frequency with the Piezo and by blinking the LEDs. If it is not, the program just waits some time. Create the following program in the coding area and press Start Simulation to run the Gas Leak Alarm System: - 40 diy die min A walime 110 to 2 Initially, the if () then block evaluates whether the gas sensor input excedes 40, a value for which gas emissions may be dangerous. If it returns true, the Piezo plays a tone of 110 Hz for 1 second to alert the user, and then the LEDs blink twice alternately, for half a second each. 900 Lox LOW- toin 21 to: HIGH- 500 WARNING) Gas Eesions Highwa If the evaluation returns true. after sounding the Piezo and flashing the LEDs, the program prints to the Serial Monitor a warning message to inform the user that there is danger gm ber INFO] Nammal Activity If the evaluation returns False, the program waits for 2 seconds and prints a message to the Serial Monitor to reassure the user that there is no danger. وزارة التعليم 123-1985 Figure 3.40: Gas Leak Alarm System Code 109
Gas Leak Alarm System Code
Run the program to test it. IB Smoke simulation. Figure 3.4L Code implementation When the smoke cluster is away from the Gas Sensor, the Piezo does not make a sound and the LEDs do not flash. But when the smoke cluster is close to the sensor, the Piezo starts beeping and the orange and green LEDs flash alternately 110 Figure 3 42. No gas detected Figure 3.43 Gas detected
Run the program to test it.
Exercises 1 Search the Internet for different types of gas hazards that could be detected with a gas sensor and analyze them. Present your findings below. 2 Consider how different tones from the Piezo buzzer could signal different alarms for different types of hazards. Present your ideas below. وزارة التعليم 1-1445 117
Search the Internet for different types of gas hazardsthat could be detected with a gas sensor and analyze them. Present your findings below.
Consider how different tones from the Piezo buzzer could signal different alarms for different types of hazards. Present your ideas below.
112 3 Describe Uses for the Piezo buzzer other than for an alarm system. The gas sensor has more pins for connecting to a microcontroller than most other sensors. Review the information that the gas sensor sends and explain why it differs from other sensors. صارت التعليم 21-145)
Describe uses for the Piezo buzzer other than for an alarm system.
The gassensor hasmore pinsfor connecting to amicrocontrollerthanmost othersensors. Review the information that the gas sensor sends and explain why it differs from other sensors.
5 Change the flashing pattern of the LEDS so that, instead of each LED turning on and off twice for 500mns, only the green LED turns on and off, 3 times, for 1 second each time. ㄖ. XD 6 Change the beeping pattern of the Piezo so that, instead of beeping with a tone of 110Hz for 1 second, it beeps with a tone of 220Hz for 700ms. a 8 LHD P the circuit so it also outputs an additional warning when gas values are over 100. 113