Sensing Bad Air Well, we talked about how to meassure temperature and humidity with ledunia, but bad air? The MQ-7 is a simple-to-use Carbon Monoxide (CO) sensor, suitable for sensing CO concentrations in the air. The MQ-7 can detect CO-gas concentrations anywhere from 20 to 2000ppm. This sensor has a high sensitivity and fast response time. The sensor’s output is an analog resistance. The drive circuit is very simple; all you need to do is power the heater coil with 5V, add a load resistance, and connect the output to an ADC. And this is how it looks like:

PRTG Screenshot
MQ-7 with ledunia

Example Code:

 

/*
*******************************************************************

 Analog Sense for MQ02 - MQ012
 PRTG: Use sensor: "HTTP Push Data Advanced Sensor"
 MQ-7 is 5V tolerant
 MQ-7 "Analog Out" goes to ledunia "Analog In" (ADO)
 NodeMCU boards should also work the same way

*******************************************************************
*/

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
extern "C" {
#include "user_interface.h"
}

const char* DNSNAME = "YOUR-DNS-NAME";
const char hosttarget[] = "PRTG-IP";
String token = "YOUR-PRTG-TOKEN";
const char* ssid = "YOUR-SSID";
const char* password = "YOUR-PASSWORD";
unsigned char mac[6];

MDNSResponder mdns;

float voltage_Sense; //Float var voltage_sense
float sensor_value; //Float var sensor value

void setup() {
Serial.begin(115200); //Start Serial Communication
delay(10);

WiFi.begin(ssid, password);

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
if (mdns.begin((DNSNAME), WiFi.localIP())) {
Serial.println("MDNS responder started");
}
}

void loop() {
int32_t rssi = wifi_station_get_rssi(); // Signalstrength in dBm
sensor_value = analogRead(A0); //Read value from analog A0
//voltage_Sense = sensor_value/1024*5.0; // Voltage / 1024 * 5.0
int32_t voltage_Sense = sensor_value/1024*5000; // Voltage / 1024 * 5.0
String voltage = String(system_get_free_heap_size()/100);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 5050; // http push data port for PRTG
if (!client.connect(hosttarget, httpPort)) {
Serial.println("connection failed");
return;
}
String data1 = "?content=<prtg><result><channel>Air Quality</channel><value>";
String data2 = "</value></result><text>Air Quality | MQ-7</text><result><channel>Signal</channel><value>";
String data3 = "</value></result><text>dBi</text><result><channel>Voltage</channel><value>";
String data4 = "</value></result><text>Volts</text></prtg>";

// We now create a URI for the request
String url = "GET /" + token + data1 + voltage_Sense + data2 + rssi + data3 + voltage + data4 +" HTTP/1.1";


client.println(url);
Serial.println(url);

client.println("Host: gassensor.local");
client.println("Connection: close");
client.println();
client.println();
delay(10);


Serial.print("Signal: ");
Serial.print(rssi);
Serial.print("dBi ");
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.print("V ");
Serial.print("voltage_Sense = ");
Serial.print(voltage_Sense);
Serial.println("Gas Voltage");
delay(1000); // Delay at 1 second

// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}

Serial.println();
Serial.println("closing connection. going to sleep...");
delay(1000);

}

Note: We will also share all software for any other of our projects once we have successfully finished our kickstarter campaign.

About Ledunia

Ledunia is a powerful WiFi enabled IoT development board with a full TCP/IP stack and microcontroller unit based on the mature of the ESP8266 technology.

Latest News

25 July 2017

More

Translate