Serial.print(threshold_value) //prints the threshold_value reached as either LOW or HIGH (above or underneath)ĭigitalWrite(Led_Pin, HIGH) //if threshold_value has been reached, LED turns on as status indicatorĭigitalWrite(Led_Pin, LOW) //if threshold not reached, LED remains offįirst, we need to define the pins of the MQ4 sensor module which are connected to Arduino. Serial.println(AO_Out) //prints the methane value Threshold_value= digitalRead(DO_Pin) //Read digital output of MQ4 sensor PinMode(Led_Pin, OUTPUT) //Configure D3 pin as a digital output pinĪO_Out= analogRead(AO_Pin) // Take Analog output measurement sample from AO pin of MQ4 sensor PinMode(DO_Pin, INPUT) // Configure D8 pin as a digital input pin Serial.begin(115200) // Initialize serial communictation with a baud rate of 115200 Int AO_Out // stores analog output of MQ4 sensor Int threshold_value // A variable to store digital output of MQ4 The Arduino code for MQ-4 Methane Sensor is provided below: /* MQ-4 Methane Sensor module with Arduino */Ĭonst int AO_Pin=0 // Connect AO of MQ4 with Analog channel 0 pin (A0) of ArduinoĬonst int DO_Pin=8 // Connect DO of MQ4 with Digital pin 8 (D8) of ArduinoĬonst int Led_Pin=13 // Connect an LED with D13 pin of Arduino ![]() An LED is connected to indicate whenever methane gas is detected in a particular area.Connect the analog and digital pins of the mentioned methane sensor to the analog pin and digital pin of the Arduino UNO for transferring data readings respectively. ![]() Connect the power supply pins of the MQ-4 methane sensor to the GND pin and the 5 Volts pin of the Arduino UNO.This section will guide through the interfacing of the Arduino UNO and MQ-4 Methane sensor. This digital pin can also be used for different activities being commanded by a microcontroller. When methane gas is detected, the digital pin goes HIGH and the Digital output inbuilt led glows up. Similarly, the same goes for the digital output pin of the MQ4 methane sensor. Based on this measurement, we can take proper actions such as alarm triggering, etc. Microcontroller reads the analog output signal of the methane gas sensor and performs signal conditioning to convert the measured analog voltage into Methane concentration in air. Nowadays most microcontrollers come with a built-in ADC peripheral which can be used to read the analog output of such sensors such as MQ4. We can measure the analog output of a sensor with an ADC microcontroller. The analog pin of the sensor then generates an analog signal proportional to the amount of CH4 in the air. The MQ-4 works by sensing the methane concentration in the air. A small compact sensor for easy assembly in DIY projects.Īs soon as the module is powered, the power LED lights up.It is very sensitive to methane making it quite useful for detecting systems.The device sensitivity may vary due to oxygen concentration.The sensor is a simple and stable circuit with a TTL DO pin.Output Analog Voltage: 2.5 – 4 Volts (5000 ppm CH4). ![]() Sensing Resistance Range: 10 – 60 Kohms.One is ground and the other is used for output. These are connected together to the supply pin.Ģ Test pins. One is connected to the power supply and the other to the ground.Ģ Test pins. If you are using MQ-4 Methane Gas Sensor only, the listed table should be followed to configure the connections. It also produces a digital signal whose limit can be set using a potentiometer. It generates a signal proportional to the intensity of methane.ĭigital Output pin.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |