From 6a549c0ac5ebefbb5ea9e55d2f509d2b47b1f3f6 Mon Sep 17 00:00:00 2001 From: miguel5612 Date: Tue, 9 Jul 2019 19:56:52 -0500 Subject: [PATCH] Added smoke example --- examples/smokeDetector/smokeDetector.ino | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/smokeDetector/smokeDetector.ino diff --git a/examples/smokeDetector/smokeDetector.ino b/examples/smokeDetector/smokeDetector.ino new file mode 100644 index 0000000..f771486 --- /dev/null +++ b/examples/smokeDetector/smokeDetector.ino @@ -0,0 +1,51 @@ +/* + MQUnifiedsensor Library - smokeDetector + + Demonstrates the use a MQ2 sensor. + Library originally added 01 may 2019 + by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez + + Added example + modified 23 May 2019 + by Miguel Califa + + This example code is in the public domain. + +*/ + +//Include the library +#include + +//Definitions +#define pin A0 //Analog input 0 of your arduino +#define type 4 //MQ4 + +//Declare Sensor +MQUnifiedsensor MQ4(pin, type); + +void setup() { + //Init serial port + Serial.begin(115200); + /***************************** MQInicializar**************************************** + Input: + Output: + Remarks: This function configure the pinMode + ************************************************************************************/ + //init the sensor + MQ4.inicializar(); +} + + void loop() { + /***************************** MQReadSensor **************************************** + Input: Gas - Serial print flag + Output: Value in PPM + Remarks: This function use readPPM to read the value in PPM the gas in the air. + ************************************************************************************/ + //Read the sensor and print in serial port + //Lecture will be saved in lecture variable + int lecture = MQ4.readSensor("smoke"); // Return smoke concentration + Serial.print("MQ4 smoke ppm lecture: "); + Serial.print(lecture); + Serial.println(" ppm"); + delay(400); +}