From 6c13c564486062157f79502a41e89b1ac31d9c06 Mon Sep 17 00:00:00 2001 From: epierre Date: Mon, 10 Aug 2015 21:46:02 +0200 Subject: [PATCH 01/11] updated with Hek remarks --- .../AirQuality-CO2-MH-Z14.ino | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 libraries/MySensors/examples/AirQualitySensor/AirQuality-CO2-MH-Z14.ino diff --git a/libraries/MySensors/examples/AirQualitySensor/AirQuality-CO2-MH-Z14.ino b/libraries/MySensors/examples/AirQualitySensor/AirQuality-CO2-MH-Z14.ino new file mode 100644 index 0000000..a9cbca7 --- /dev/null +++ b/libraries/MySensors/examples/AirQualitySensor/AirQuality-CO2-MH-Z14.ino @@ -0,0 +1,100 @@ +/** + * 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 + * 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. + * + ******************************* + * + * DESCRIPTION + * + * MH-Z14 CO2 sensor + * + * Wiring: + * Pad 1, Pad 5: Vin (Voltage input 4.5V-6V) + * Pad 2, Pad 3, Pad 12: GND + * Pad 6: PWM output ==> pin 6 + * + * From: http://davidegironi.blogspot.fr/2014/01/co2-meter-using-ndir-infrared-mh-z14.html + * MH-Z14 has a PWM output, with a sensitivity range of 0ppm to 2000ppm CO2, an accurancy of ±200ppm. + * The cycle is 1004ms±5%, given the duty cicle Th (pulse high), Tl is 1004-Th, we can convert it to CO2 value using the formula: + * CO2ppm = 2000 * (Th - 2ms) /(Th + Tl - 4ms) + * From: http://airqualityegg.wikispaces.com/Sensor+Tests + * - response time is less than 30 s + * - 3 minute warm up time + * datasheet: http://www.futurlec.com/Datasheet/Sensor/MH-Z14.pdf +* Contributor: epierre +**/ + + +#include +#include + +#define CHILD_ID_AIQ 0 +#define AIQ_SENSOR_ANALOG_PIN 6 + +unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) + +float valAIQ =0.0; +float lastAIQ =0.0; + +MySensor gw; +MyMessage msg(CHILD_ID_AIQ, V_LEVEL); +MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX); + +void setup() +{ + gw.begin(); + + // Send the sketch version information to the gateway and Controller + gw.sendSketchInfo("AIQ Sensor CO2 MH-Z14", "1.0"); + + // Register all sensors to gateway (they will be created as child devices) + gw.present(CHILD_ID_AIQ, S_AIR_QUALITY); + gw.send(msg2.set("ppm")); + + gw.sleep(SLEEP_TIME); + + pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT); + +} + +void loop() { + + //unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); + while(digitalRead(AIQ_SENSOR_ANALOG_PIN) == HIGH) {;} + //wait for the pin to go HIGH and measure HIGH time + unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); + + //Serial.print(duration/1000); Serial.println(" ms "); + //from datasheet + //CO2 ppm = 2000 * (Th - 2ms) / (Th + Tl - 4ms) + // given Tl + Th = 1004 + // Tl = 1004 - Th + // = 2000 * (Th - 2ms) / (Th + 1004 - Th -4ms) + // = 2000 * (Th - 2ms) / 1000 = 2 * (Th - 2ms) + long co2ppm = 2 * ((duration/1000) - 2); + //Serial.print(co2ppm); + if ((co2ppm != lastAIQ)&&(abs(co2ppm-lastAIQ)>=10)) { + gw.send(msg.set((long)ceil(co2ppm))); + lastAIQ = ceil(co2ppm); + } + + //Serial.println(); + + // 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 +} From 059d034f10d4763fceaed0733a99b0f78b857ba0 Mon Sep 17 00:00:00 2001 From: epierre Date: Mon, 10 Aug 2015 21:51:20 +0200 Subject: [PATCH 02/11] good sensibility sensor --- .../DustSensor/DustSensor_SamYoung_DSM501.ino | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino diff --git a/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino b/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino new file mode 100644 index 0000000..50514c8 --- /dev/null +++ b/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino @@ -0,0 +1,139 @@ +/** + * 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 + * 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. + * + ******************************* + * + * DESCRIPTION + * + * Dust Sensor for SamYoung DSM501 + * connect the sensor as follows : + * Pin 2 of dust sensor PM1 -> Digital 3 (PMW) + * Pin 3 of dust sensor -> +5V + * Pin 4 of dust sensor PM2.5 -> Digital 6 (PWM) + * Pin 5 of dust sensor -> Ground + * Datasheet: http://www.samyoungsnc.com/products/3-1%20Specification%20DSM501.pdf +* Contributor: epierre +**/ + + +#include +#include + +#define CHILD_ID_DUST_PM10 0 +#define CHILD_ID_DUST_PM25 1 +#define DUST_SENSOR_DIGITAL_PIN_PM10 6 +#define DUST_SENSOR_DIGITAL_PIN_PM25 3 + +unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) +//VARIABLES +int val = 0; // variable to store the value coming from the sensor +float valDUSTPM25 =0.0; +float lastDUSTPM25 =0.0; +float valDUSTPM10 =0.0; +float lastDUSTPM10 =0.0; +unsigned long duration; +unsigned long starttime; +unsigned long endtime; +unsigned long sampletime_ms = 30000; +unsigned long lowpulseoccupancy = 0; +float ratio = 0; +long concentrationPM25 = 0; +long concentrationPM10 = 0; + +MySensor gw; +MyMessage dustMsgPM10(CHILD_ID_DUST_PM10, V_LEVEL); +MyMessage msgPM10(CHILD_ID_DUST_PM10, V_UNIT_PREFIX); +MyMessage dustMsgPM25(CHILD_ID_DUST_PM25, V_LEVEL); +MyMessage msgPM25(CHILD_ID_DUST_PM25, V_UNIT_PREFIX); + +void setup() +{ + gw.begin(); + + // Send the sketch version information to the gateway and Controller + gw.sendSketchInfo("Dust Sensor DSM501", "1.4"); + + // Register all sensors to gateway (they will be created as child devices) + gw.present(CHILD_ID_DUST_PM10, S_DUST); + gw.send(msgPM10.set("ppm")); + gw.present(CHILD_ID_DUST_PM25, S_DUST); + gw.send(msgPM25.set("ppm")); + + pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT); + pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT); + Serial.begin(115200); +} + +void loop() +{ + + //get PM 2.5 density of particles over 2.5 μm. + concentrationPM25=(long)getPM(DUST_SENSOR_DIGITAL_PIN_PM25); + Serial.print("PM25: "); + Serial.println(concentrationPM25); + Serial.print("\n"); + + if ((concentrationPM25 != lastDUSTPM25)&&(concentrationPM25>0)) { + gw.send(dustMsgPM25.set((long)ceil(concentrationPM25))); + lastDUSTPM25 = ceil(concentrationPM25); + } + //get PM 1.0 - density of particles over 1 μm. + concentrationPM10=getPM(DUST_SENSOR_DIGITAL_PIN_PM10); + Serial.print("PM10: "); + Serial.println(concentrationPM10); + Serial.print("\n"); + if ((ceil(concentrationPM10) != lastDUSTPM10)&&((long)concentrationPM10>0)) { + gw.send(dustMsgPM10.set((long)ceil(concentrationPM10))); + lastDUSTPM10 = ceil(concentrationPM10); + } + + //sleep to save on radio + gw.sleep(SLEEP_TIME); + +} + + +long getPM(int DUST_SENSOR_DIGITAL_PIN) { + + starttime = millis(); + + while (1) { + + duration = pulseIn(DUST_SENSOR_DIGITAL_PIN, LOW); + lowpulseoccupancy += duration; + endtime = millis(); + + if ((endtime-starttime) > sampletime_ms) + { + ratio = (lowpulseoccupancy-endtime+starttime)/(sampletime_ms*10.0); // Integer percentage 0=>100 + long concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve + //Serial.print("lowpulseoccupancy:"); + //Serial.print(lowpulseoccupancy); + //Serial.print("\n"); + //Serial.print("ratio:"); + //Serial.print(ratio); + //Serial.print("\n"); + //Serial.print("DSM501A:"); + //Serial.println(concentration); + //Serial.print("\n"); + + lowpulseoccupancy = 0; + return(concentration); + } + } +} From e40939fba769457fbe8f58d5fb5d7894f3e0fb76 Mon Sep 17 00:00:00 2001 From: epierre Date: Mon, 10 Aug 2015 21:56:33 +0200 Subject: [PATCH 03/11] Vibration sensor sketch --- .../VibrationSensor/VibrationSensor.ino | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino diff --git a/libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino b/libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino new file mode 100644 index 0000000..93db4c5 --- /dev/null +++ b/libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino @@ -0,0 +1,94 @@ +/** + * 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 + * 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. + * + ******************************* + * + * DESCRIPTION + * + * Vibration Sensor + * + * connect the sensor as follows : + * + * VCC >>> 5V + * S >>> D3 + * GND >>> GND + * + * Based on: http://www.dfrobot.com/wiki/index.php/DFRobot_Digital_Vibration_Sensor_V2_SKU:DFR0027 + * Contributor: epierre +**/ + + +#include +#include +#include + +#define CHILD_ID_VIBRATION 0 +#define VIBRATION_SENSOR_DIGITAL_PIN 3 +#define SensorLED 13 + +unsigned long SLEEP_TIME = 10*1000; // Sleep time between reads (in seconds) + +//VARIABLES +int val = 0; // variable to store the value coming from the sensor +float valVIBRATION =0.0; +float lastVIBRATION =0.0; +unsigned char state = 0; + +MySensor gw; +MyMessage vibrationMsg(CHILD_ID_VIBRATION, V_LEVEL); + +void setup() +{ + gw.begin(); + + // Send the sketch version information to the gateway and Controller + gw.sendSketchInfo("VIBRATION Sensor", "1.0"); + + // Register all sensors to gateway (they will be created as child devices) + gw.present(CHILD_ID_VIBRATION, S_VIBRATION); + + + pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT); + attachInterrupt(1, blink, FALLING);// Trigger the blink function when the falling edge is detected + pinMode(SensorLED, OUTPUT); +} + +void loop() +{ + + if(state>=40){ // basically below 40 so ignire basic level + gw.send(vibrationMsg.set(int(state))); + state = 0; + digitalWrite(SensorLED,HIGH); + } else { + state = 0; + digitalWrite(SensorLED,LOW); + } + + + // Power down the radio. Note that the radio will get powered back up + // on the next write() call. + delay(1000); //delay to allow serial to fully print before sleep + + gw.sleep(SLEEP_TIME); //sleep for: sleepTime +} + +void blink()//Interrupts function +{ + state++; +} From 3e734d467c1ae1824b26931de28ed60f20bf6025 Mon Sep 17 00:00:00 2001 From: epierre Date: Mon, 10 Aug 2015 21:59:34 +0200 Subject: [PATCH 04/11] replacement with a better sketch --- .../SoilMoistSensor/SoilMoistSensor.ino | 65 ------ .../SoilMoistSensor/SoilMoistureSensor.ino | 185 ++++++++++++++++++ 2 files changed, 185 insertions(+), 65 deletions(-) delete mode 100644 libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino create mode 100644 libraries/MySensors/examples/SoilMoistSensor/SoilMoistureSensor.ino diff --git a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino deleted file mode 100644 index 2a2a108..0000000 --- a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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 - * 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 - * Example sketch sending soil moisture alarm to controller - * http://www.mysensors.org/build/moisture - */ - -#include -#include - -#define DIGITAL_INPUT_SOIL_SENSOR 3 // Digital input did you attach your soil sensor. -#define INTERRUPT DIGITAL_INPUT_SOIL_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) -#define CHILD_ID 0 // Id of the sensor child - -MySensor gw; -MyMessage msg(CHILD_ID, V_TRIPPED); -int lastSoilValue = -1; - -void setup() -{ - gw.begin(); - - // Send the sketch version information to the gateway and Controller - gw.sendSketchInfo("Soil Moisture Sensor", "1.0"); - // sets the soil sensor digital pin as input - pinMode(DIGITAL_INPUT_SOIL_SENSOR, INPUT); - // Register all sensors to gw (they will be created as child devices) - gw.present(CHILD_ID, S_MOTION); -} - -void loop() -{ - // Read digital soil value - int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR); // 1 = Not triggered, 0 = In soil with water - if (soilValue != lastSoilValue) { - Serial.println(soilValue); - gw.send(msg.set(soilValue==0?1:0)); // Send the inverse to gw as tripped should be when no water in soil - lastSoilValue = soilValue; - } - // Power down the radio and arduino until digital input changes. - gw.sleep(INTERRUPT,CHANGE); -} - - diff --git a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistureSensor.ino b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistureSensor.ino new file mode 100644 index 0000000..de99a37 --- /dev/null +++ b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistureSensor.ino @@ -0,0 +1,185 @@ +/** + * 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 + * 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. + * + ******************************* + * + * DESCRIPTION + * + * Arduino soil moisture based on gypsum sensor/resistive sensor to avoid electric catalyse in soil + * Required to interface the sensor: 2 * 4.7kOhm + 2 * 1N4148 + * + * Gypsum sensor and calibration: + * DIY: See http://vanderleevineyard.com/1/category/vinduino/1.html + * Built: Davis / Watermark 200SS + * http://www.cooking-hacks.com/watermark-soil-moisture-sensor?_bksrc=item2item&_bkloc=product + * http://www.irrometer.com/pdf/supportmaterial/sensors/voltage-WM-chart.pdf + * cb (centibar) http://www.irrometer.com/basics.html + * 0-10 Saturated Soil. Occurs for a day or two after irrigation + * 10-20 Soil is adequately wet (except coarse sands which are drying out at this range) + * 30-60 Usual range to irrigate or water (except heavy clay soils). + * 60-100 Usual range to irrigate heavy clay soils + * 100-200 Soil is becoming dangerously dry for maximum production. Proceed with caution. + * + * Connection: + * D6, D7: alternative powering to avoid sensor degradation + * A0, A1: alternative resistance mesuring + * + * Based on: + * "Vinduino" portable soil moisture sensor code V3.00 + * Date December 31, 2012 + * Reinier van der Lee and Theodore Kaskalis + * www.vanderleevineyard.com + * Contributor: epierre +**/ + +// Copyright (C) 2015, Reinier van der Lee +// www.vanderleevineyard.com + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +#include // Conversion equation from resistance to % +#include +#include + +// Setting up format for reading 3 soil sensors +#define NUM_READS 10 // Number of sensor reads for filtering +#define CHILD_ID 0 + +MySensor gw; // Arduino initialization +MyMessage msg(CHILD_ID, V_LEVEL); +unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) + +long buffer[NUM_READS]; +int index; + +typedef struct { // Structure to be used in percentage and resistance values matrix to be filtered (have to be in pairs) + int moisture; + long resistance; +} values; + +const long knownResistor = 4700; // Constant value of known resistor in Ohms + +int supplyVoltage; // Measured supply voltage +int sensorVoltage; // Measured sensor voltage + +values valueOf[NUM_READS]; // Calculated moisture percentages and resistances to be sorted and filtered + +int i; // Simple index variable + +void setup() { + // initialize serial communications at 9600 bps: + Serial.begin(115200); + gw.begin(); + gw.sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0"); + gw.present(CHILD_ID, S_HUM); + // initialize the digital pins as an output. + // Pin 6,7 is for sensor 1 + // initialize the digital pin as an output. + // Pin 6 is sense resistor voltage supply 1 + pinMode(6, OUTPUT); + + // initialize the digital pin as an output. + // Pin 7 is sense resistor voltage supply 2 + pinMode(7, OUTPUT); + + +} + +void loop() { + + measure(1,6,7,1); + Serial.print ("\t"); + Serial.println (average()); + long read1 = average(); + + measure(1,7,6,0); + Serial.print ("\t"); + Serial.println (average()); + long read2= average(); + + long sensor1 = (read1 + read2)/2; + + Serial.print ("resistance bias =" ); + Serial.println (read1-read2); + Serial.print ("sensor bias compensated value = "); + Serial.println (sensor1); + Serial.println (); + + //send back the values + gw.send(msg.set((long int)ceil(sensor1))); + // delay until next measurement (msec) + gw.sleep(SLEEP_TIME); +} + +void measure (int sensor, int phase_b, int phase_a, int analog_input) +{ + // read sensor, filter, and calculate resistance value + // Noise filter: median filter + + for (i=0; i= NUM_READS) index = 0; +} + +long average(){ + long sum = 0; + for (int i = 0; i < NUM_READS; i++){ + sum += buffer[i]; + } + return (long)(sum / NUM_READS); +} From c146aa2d048b10d1c760e7681fa039ee495fe98d Mon Sep 17 00:00:00 2001 From: epierre Date: Mon, 10 Aug 2015 22:03:59 +0200 Subject: [PATCH 05/11] formula is back --- .../examples/DustSensor/DustSensor_SamYoung_DSM501.ino | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino b/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino index 50514c8..43cae33 100644 --- a/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino +++ b/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino @@ -97,8 +97,13 @@ void loop() Serial.print("PM10: "); Serial.println(concentrationPM10); Serial.print("\n"); + //ppmv=mg/m3 * (0.08205*Tmp)/Molecular_mass + //0.08205 = Universal gas constant in atm·m3/(kmol·K) + int temp=20; //external temperature, if you can replace this with a DHT11 or better + long ppmv=(concentrationPM10*0.0283168/100/1000) * (0.08205*temp)/0.01; + if ((ceil(concentrationPM10) != lastDUSTPM10)&&((long)concentrationPM10>0)) { - gw.send(dustMsgPM10.set((long)ceil(concentrationPM10))); + gw.send(dustMsgPM10.set((long)ppmv)); lastDUSTPM10 = ceil(concentrationPM10); } From 2ba7ce09a7988ea1d06d339636d3d0e091a2870f Mon Sep 17 00:00:00 2001 From: epierre Date: Mon, 10 Aug 2015 22:06:29 +0200 Subject: [PATCH 06/11] removed serial initialization (<1.3) --- .../examples/DustSensor/DustSensor_SamYoung_DSM501.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino b/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino index 43cae33..ca88a73 100644 --- a/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino +++ b/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino @@ -76,7 +76,7 @@ void setup() pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT); pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT); - Serial.begin(115200); + } void loop() From dff73e46bafa7fccbe8be4fd1fb9108c11de2e36 Mon Sep 17 00:00:00 2001 From: epierre Date: Mon, 10 Aug 2015 22:08:15 +0200 Subject: [PATCH 07/11] shorter name --- .../{SoilMoistureSensor.ino => SoilMoistSensor.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libraries/MySensors/examples/SoilMoistSensor/{SoilMoistureSensor.ino => SoilMoistSensor.ino} (100%) diff --git a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistureSensor.ino b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino similarity index 100% rename from libraries/MySensors/examples/SoilMoistSensor/SoilMoistureSensor.ino rename to libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino From 9483683a5f659eb261ac120740100e4f4ba14703 Mon Sep 17 00:00:00 2001 From: empierre Date: Tue, 11 Aug 2015 12:37:40 +0200 Subject: [PATCH 08/11] Delete AirQuality-CO2-MH-Z14.ino compilation issue if twosketches in the same sub dir --- .../AirQuality-CO2-MH-Z14.ino | 100 ------------------ 1 file changed, 100 deletions(-) delete mode 100644 libraries/MySensors/examples/AirQualitySensor/AirQuality-CO2-MH-Z14.ino diff --git a/libraries/MySensors/examples/AirQualitySensor/AirQuality-CO2-MH-Z14.ino b/libraries/MySensors/examples/AirQualitySensor/AirQuality-CO2-MH-Z14.ino deleted file mode 100644 index a9cbca7..0000000 --- a/libraries/MySensors/examples/AirQualitySensor/AirQuality-CO2-MH-Z14.ino +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 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 - * 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. - * - ******************************* - * - * DESCRIPTION - * - * MH-Z14 CO2 sensor - * - * Wiring: - * Pad 1, Pad 5: Vin (Voltage input 4.5V-6V) - * Pad 2, Pad 3, Pad 12: GND - * Pad 6: PWM output ==> pin 6 - * - * From: http://davidegironi.blogspot.fr/2014/01/co2-meter-using-ndir-infrared-mh-z14.html - * MH-Z14 has a PWM output, with a sensitivity range of 0ppm to 2000ppm CO2, an accurancy of ±200ppm. - * The cycle is 1004ms±5%, given the duty cicle Th (pulse high), Tl is 1004-Th, we can convert it to CO2 value using the formula: - * CO2ppm = 2000 * (Th - 2ms) /(Th + Tl - 4ms) - * From: http://airqualityegg.wikispaces.com/Sensor+Tests - * - response time is less than 30 s - * - 3 minute warm up time - * datasheet: http://www.futurlec.com/Datasheet/Sensor/MH-Z14.pdf -* Contributor: epierre -**/ - - -#include -#include - -#define CHILD_ID_AIQ 0 -#define AIQ_SENSOR_ANALOG_PIN 6 - -unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) - -float valAIQ =0.0; -float lastAIQ =0.0; - -MySensor gw; -MyMessage msg(CHILD_ID_AIQ, V_LEVEL); -MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX); - -void setup() -{ - gw.begin(); - - // Send the sketch version information to the gateway and Controller - gw.sendSketchInfo("AIQ Sensor CO2 MH-Z14", "1.0"); - - // Register all sensors to gateway (they will be created as child devices) - gw.present(CHILD_ID_AIQ, S_AIR_QUALITY); - gw.send(msg2.set("ppm")); - - gw.sleep(SLEEP_TIME); - - pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT); - -} - -void loop() { - - //unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); - while(digitalRead(AIQ_SENSOR_ANALOG_PIN) == HIGH) {;} - //wait for the pin to go HIGH and measure HIGH time - unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); - - //Serial.print(duration/1000); Serial.println(" ms "); - //from datasheet - //CO2 ppm = 2000 * (Th - 2ms) / (Th + Tl - 4ms) - // given Tl + Th = 1004 - // Tl = 1004 - Th - // = 2000 * (Th - 2ms) / (Th + 1004 - Th -4ms) - // = 2000 * (Th - 2ms) / 1000 = 2 * (Th - 2ms) - long co2ppm = 2 * ((duration/1000) - 2); - //Serial.print(co2ppm); - if ((co2ppm != lastAIQ)&&(abs(co2ppm-lastAIQ)>=10)) { - gw.send(msg.set((long)ceil(co2ppm))); - lastAIQ = ceil(co2ppm); - } - - //Serial.println(); - - // 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 -} From df6579cf1a98ebcd573566669b1caa6fa615c15d Mon Sep 17 00:00:00 2001 From: empierre Date: Tue, 11 Aug 2015 12:41:09 +0200 Subject: [PATCH 09/11] Create AirQualityCO2 moved the file --- .../examples/CO2Sensor/AirQualityCO2 | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 libraries/MySensors/examples/CO2Sensor/AirQualityCO2 diff --git a/libraries/MySensors/examples/CO2Sensor/AirQualityCO2 b/libraries/MySensors/examples/CO2Sensor/AirQualityCO2 new file mode 100644 index 0000000..a9cbca7 --- /dev/null +++ b/libraries/MySensors/examples/CO2Sensor/AirQualityCO2 @@ -0,0 +1,100 @@ +/** + * 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 + * 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. + * + ******************************* + * + * DESCRIPTION + * + * MH-Z14 CO2 sensor + * + * Wiring: + * Pad 1, Pad 5: Vin (Voltage input 4.5V-6V) + * Pad 2, Pad 3, Pad 12: GND + * Pad 6: PWM output ==> pin 6 + * + * From: http://davidegironi.blogspot.fr/2014/01/co2-meter-using-ndir-infrared-mh-z14.html + * MH-Z14 has a PWM output, with a sensitivity range of 0ppm to 2000ppm CO2, an accurancy of ±200ppm. + * The cycle is 1004ms±5%, given the duty cicle Th (pulse high), Tl is 1004-Th, we can convert it to CO2 value using the formula: + * CO2ppm = 2000 * (Th - 2ms) /(Th + Tl - 4ms) + * From: http://airqualityegg.wikispaces.com/Sensor+Tests + * - response time is less than 30 s + * - 3 minute warm up time + * datasheet: http://www.futurlec.com/Datasheet/Sensor/MH-Z14.pdf +* Contributor: epierre +**/ + + +#include +#include + +#define CHILD_ID_AIQ 0 +#define AIQ_SENSOR_ANALOG_PIN 6 + +unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) + +float valAIQ =0.0; +float lastAIQ =0.0; + +MySensor gw; +MyMessage msg(CHILD_ID_AIQ, V_LEVEL); +MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX); + +void setup() +{ + gw.begin(); + + // Send the sketch version information to the gateway and Controller + gw.sendSketchInfo("AIQ Sensor CO2 MH-Z14", "1.0"); + + // Register all sensors to gateway (they will be created as child devices) + gw.present(CHILD_ID_AIQ, S_AIR_QUALITY); + gw.send(msg2.set("ppm")); + + gw.sleep(SLEEP_TIME); + + pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT); + +} + +void loop() { + + //unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); + while(digitalRead(AIQ_SENSOR_ANALOG_PIN) == HIGH) {;} + //wait for the pin to go HIGH and measure HIGH time + unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); + + //Serial.print(duration/1000); Serial.println(" ms "); + //from datasheet + //CO2 ppm = 2000 * (Th - 2ms) / (Th + Tl - 4ms) + // given Tl + Th = 1004 + // Tl = 1004 - Th + // = 2000 * (Th - 2ms) / (Th + 1004 - Th -4ms) + // = 2000 * (Th - 2ms) / 1000 = 2 * (Th - 2ms) + long co2ppm = 2 * ((duration/1000) - 2); + //Serial.print(co2ppm); + if ((co2ppm != lastAIQ)&&(abs(co2ppm-lastAIQ)>=10)) { + gw.send(msg.set((long)ceil(co2ppm))); + lastAIQ = ceil(co2ppm); + } + + //Serial.println(); + + // 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 +} From d0290e48ef6f5f9af2f30b044e3adb0e1ca057d5 Mon Sep 17 00:00:00 2001 From: empierre Date: Tue, 11 Aug 2015 12:43:51 +0200 Subject: [PATCH 10/11] Rename libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino to libraries/MySensors/examples/DustSensorDSM/DustDSM501Sensor.ino renaming and moving --- .../DustDSM501Sensor.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libraries/MySensors/examples/{DustSensor/DustSensor_SamYoung_DSM501.ino => DustSensorDSM/DustDSM501Sensor.ino} (100%) diff --git a/libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino b/libraries/MySensors/examples/DustSensorDSM/DustDSM501Sensor.ino similarity index 100% rename from libraries/MySensors/examples/DustSensor/DustSensor_SamYoung_DSM501.ino rename to libraries/MySensors/examples/DustSensorDSM/DustDSM501Sensor.ino From 6f42c7008ab2d587b135991fa0a718fa7d2f95f5 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 12 Aug 2015 14:23:05 +0200 Subject: [PATCH 11/11] Update SoilMoistSensor.ino removed sensor parameter call as it is unused --- .../MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino index de99a37..2c3c74e 100644 --- a/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino +++ b/libraries/MySensors/examples/SoilMoistSensor/SoilMoistSensor.ino @@ -110,12 +110,12 @@ void setup() { void loop() { - measure(1,6,7,1); + measure(6,7,1); Serial.print ("\t"); Serial.println (average()); long read1 = average(); - measure(1,7,6,0); + measure(7,6,0); Serial.print ("\t"); Serial.println (average()); long read2= average(); @@ -134,7 +134,7 @@ void loop() { gw.sleep(SLEEP_TIME); } -void measure (int sensor, int phase_b, int phase_a, int analog_input) +void measure (int phase_b, int phase_a, int analog_input) { // read sensor, filter, and calculate resistance value // Noise filter: median filter