The detection of certain components in the air usually requires a more precise and costly instrument, which cannot be done with a single gas sensor. The following picture shows the output of the serial monitor with the program code in the next section.Note that The sensor value only reflects the approximated trend of gas concentration in a permissible error range, it DOES NOT represent the exact gas concentration. After this one second we deactivate the active buzzer again. If the analog sensor is greater than 1000, gas is detected and we set the buzzer active for one second. Therefore we compare the current analog sensor value with a constant, in my case 1000. Now we have to define the threshold when we want to activate the buzzer or not. For a better reading we separate each variable with a tabulator. Now we print the values to the serial output to see the values in the serial monitor of the Arduino IDE. In the loop function we read the analog and digital value of the MQ2 gas sensor and save the values in different variables. The microcontroller gets the current digital status of the MQ2 gas sensor → Input.The microcontroller sends the digital value to the buzzer → Output.In the setup function we set the baud rate to 115200 and define the pin modes: The pins that you can use as analog pins are described in the ESP32 pinout tutorial. The ESP32 has a build-in analog to digital converter, so you can use multiple pins as analog input. Now there is a potential difference between resistor R3 and LED (DOUT_LED), the LED is on. In this case, the output of the comparator switches from VCC to GND and therefore also the digital output. If the gas concentration rises, the reference voltage (2) rises and should exceed the input voltage of the comparator (3). Because there is no potential difference between resistor R3 and LED (DOUT_LED), the LED is off. In this case, the output of the comparator is equal to VCC and therefore also the digital output of the sensor module. The potentiometer must be calibrated in a way that if there is no relevant gas concentration, the input voltage of the comparator (3) has to be higher than the output voltage of the MQ2 sensor that equals the reference voltage of the comparator (2). The analog sensor value increases due to the increase of gas concentration. Because the voltage between VCC and GND must be the same, the voltage over resistance R2 increases and therefore the potential on the point where the analog value is measured. If the gas concentration increases, the voltage over the MQ2 sensor decreases due to the decrease of resistance (U=R*I). We already know from the picture of the gas measurement that the resistance of the MQ2 gas sensor decreases when the gas concentration that is measured increases. In the next sub-chapter, we take a look at the MQ2 gas sensor pinout but you could also add every other gas sensor to the sensor module when the pinout and geometry of the sensor is the same.Īfter we know the schematic of the MQ2 gas sensor module, the functionality is not hard to understand. 2 Capacitors to filter the voltage and stabilize the input and output.LM393 dual comparator to compare the signal created by the MQ2 gas sensor with the predefined value through the potentiometer and to control the status of the LED that indicates the status of the digital output.5 Resistors to prevent LEDs for too high voltages and to operate as voltage dividers.2 LEDs to indicate that the module is operating (POWER_LED) and to indicate the status of the digital pin (DOUT_LED).Potentiometer to define a threshold for the digital output pin.D0: Digital output based on a predefined threshold through the potentiometer and the operation voltage of the microcontroller.VCC: Pin for the 5V operation voltage regarding to the technical datasheet.GND: Ground to connect the gas sensor to ground with the microcontroller.A0: Analog pin to transfer an analog signal.4 output pins that connect the gas sensor to a microcontroller.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |