Thx helped me, seems to work correct in Pimatic.
Just have to check if the values of the MQ135 are correct.
Posts made by Unci
-
RE: Help combining 2 Sketches
-
RE: Help combining 2 Sketches
Thx to your fast answers.
@mfalkvidd thx that was the reason!
@Sparkman thx changed it, seems to work
Have seen some output in the serial monitor, now i just have to read more about the meaning off it ^^
-
Help combining 2 Sketches
Hi everybody,
sry for my bad english at the beginning!I'm very noobie in arduino & my sensors.
I try to combining a DHT11 & a MQ135 on a arduino nano with a NRF24I01+.
I think the connection should be ok.My problem is the sketch! I surely made a mistake, but i dont know where! I took the HumiditySensor Example and the code from here:
arduino/AirQuality-MQ135.ino/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik EKblad * * DESCRIPTION * This sketch provides an example how to implement a humidity/temperature * sensor using DHT11/DHT-22 * http://www.mysensors.org/build/humidity */ #include <SPI.h> #include <MySensor.h> #include <DHT.h> #include <Wire.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define HUMIDITY_SENSOR_DIGITAL_PIN 8 #define CHILD_ID_AIQ 3 #define AIQ_SENSOR_ANALOG_PIN 0 #define MQ135_DEFAULTPPM 399 //default ppm of CO2 for calibration #define MQ135_DEFAULTRO 68550 //default Ro for MQ135_DEFAULTPPM ppm of CO2 #define MQ135_SCALINGFACTOR 116.6020682 //CO2 gas value #define MQ135_EXPONENT -2.769034857 //CO2 gas value #define MQ135_MAXRSRO 2.428 //for CO2 #define MQ135_MINRSRO 0.358 //for CO2 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) float mq135_ro = 10000.0; // this has to be tuned 10K Ohm int val = 0; // variable to store the value coming from the sensor float valAIQ =0.0; float lastAIQ =0.0; MySensor gw; DHT dht; MyMessage msg(CHILD_ID_AIQ, V_LEVEL); float lastTemp; float lastHum; boolean metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); void setup() { gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Humidity", "1.0"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); metric = gw.getConfig().isMetric; gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("AIQ Sensor MQ135", "1.0"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_AIQ, S_AIR_QUALITY); } /* * get the calibrated ro based upon read resistance, and a know ppm */ long mq135_getro(long resvalue, double ppm) { return (long)(resvalue * exp( log(MQ135_SCALINGFACTOR/ppm) / MQ135_EXPONENT )); } /* * get the ppm concentration */ double mq135_getppm(long resvalue, long ro) { double ret = 0; double validinterval = 0; validinterval = resvalue/(double)ro; if(validinterval<MQ135_MAXRSRO && validinterval>MQ135_MINRSRO) { ret = (double)MQ135_SCALINGFACTOR * pow( ((double)resvalue/ro), MQ135_EXPONENT); } return ret; } void loop() { delay(dht.getMinimumSamplingPeriod()); float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT"); } else if (temperature != lastTemp) { lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } gw.send(msgTemp.set(temperature, 1)); Serial.print("T: "); Serial.println(temperature); } float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum) { lastHum = humidity; gw.send(msgHum.set(humidity, 1)); Serial.print("H: "); Serial.println(humidity); } uint16_t valr = analogRead(AIQ_SENSOR_ANALOG_PIN);// Get AIQ value Serial.println(val); uint16_t val = ((float)22000*(1023-valr)/valr); //during clean air calibration, read the Ro value and replace MQ135_DEFAULTRO value with it, you can even deactivate following function call. mq135_ro = mq135_getro(val, MQ135_DEFAULTPPM); //convert to ppm (using default ro) valAIQ = mq135_getppm(val, MQ135_DEFAULTRO); Serial.print ( "Val / Ro / value:"); Serial.print ( val); Serial.print ( " / "); Serial.print ( mq135_ro); Serial.print ( " / "); Serial.print ( valAIQ); if (valAIQ != lastAIQ) { gw.send(msg.set(MQ135_DEFAULTPPM+(int)ceil(valAIQ))); lastAIQ = ceil(valAIQ); } // Power down the radio. Note that the radio will get powered back up // on the next write() call. gw.sleep(SLEEP_TIME); //sleep for: sleepTime } /***************************** MQGetPercentage ********************************** Input: rs_ro_ratio - Rs divided by Ro pcurve - pointer to the curve of the target gas Output: ppm of the target gas Remarks: By using the slope and a point of the line. The x(logarithmic value of ppm) of the line could be derived if y(rs_ro_ratio) is provided. As it is a logarithmic coordinate, power of 10 is used to convert the result to non-logarithmic value. ************************************************************************************/ int MQGetPercentage(float rs_ro_ratio, float ro, float *pcurve) { return (double)(pcurve[0] * pow(((double)rs_ro_ratio/ro), pcurve[1])); }
When I try to upload it there comes the output:
Arduino: 1.6.9 (Windows 10), Board: "Arduino Nano, ATmega328" WARNUNG: Kategorie '' in der Bibliothek UIPEthernet ist ungültig und wird auf 'Uncategorized' festgelegt libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::MySensor(MyTransport&, MyHw&)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::MySensor(MyTransport&, MyHw&)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::getNodeId()' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::getConfig()' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::sendWrite(unsigned char, MyMessage&)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::getLastMessage()' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::saveState(unsigned char, unsigned char)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::loadState(unsigned char)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::wait(unsigned long)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::process()' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::requestNodeId()' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::findParentNode()' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::sendRoute(MyMessage&)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::send(MyMessage&, bool)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::sendBatteryLevel(unsigned char, bool)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::present(unsigned char, unsigned char, char const*, bool)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::sendSketchInfo(char const*, char const*, bool)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::request(unsigned char, unsigned char, unsigned char)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::requestTime(void (*)(unsigned long))' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::setupNode()' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::begin(void (*)(MyMessage const&), unsigned char, bool, unsigned char)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::sleep(unsigned long)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::sleep(unsigned char, unsigned char, unsigned long)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here libraries\MySensors\MySensor.cpp.o: In function `MySensor::MySensor(MyTransport&, MyHw&)': Mehrere Bibliotheken wurden für "DHT.h" gefunden Benutzt: C:\Users\Mike\Documents\Arduino\libraries\DHT Nicht benutzt: C:\Users\Mike\Documents\Arduino\libraries\DHT_sensor_library C:\Users\Mike\Documents\Arduino\libraries\MySensors/MySensor.cpp:52: multiple definition of `MySensor::sleep(unsigned char, unsigned char, unsigned char, unsigned char, unsigned long)' sketch\MySensor.cpp.o:sketch/MySensor.cpp:52: first defined here collect2.exe: error: ld returned 1 exit status exit status 1 Fehler beim Kompilieren für das Board Arduino Nano. Dieser Bericht wäre detaillierter, wenn die Option "Ausführliche Ausgabe während der Kompilierung" in Datei -> Voreinstellungen aktiviert wäre.
I hope somebody can help me!
Thx Unci