Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. DannyM
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by DannyM

    • RE: BMP085 + DHT22

      @pepson

      I did what you tried to do, and it worked, also in Domoticz two temps are visible.

      This is my code:

      /**
       * 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
       * Pressure sensor example using BMP085 module  
       * http://www.mysensors.org/build/pressure
       * Toegevoegd: na 10x dezelfde waarde te hebben gelezen bij TeEmp en Hum toch een waarde aan de GW sturen.
       */
       
      #include <SPI.h>
      #include <Wire.h>
      #include <DHT.h>  
      #include <MySensor.h>  
      #include <Adafruit_BMP085.h>
      
      static const uint8_t FORCE_UPDATE_N_READS = 10;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      
      #define BARO_CHILD 0
      #define TEMP_CHILD 1
      #define CHILD_ID_HUM 2
      #define CHILD_ID_TEMP 3
      
      #define HUMIDITY_SENSOR_DIGITAL_PIN 3
      
      const float ALTITUDE = 1.05; // <-- adapt this value to your own location's altitude.
      
      // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute.
      const unsigned long SLEEP_TIME = 60000; 
      
      const char *weather[] = { "stabiel", "zonnig", "bewolkt", "onstabiel", "onweer", "onbekend" };
      enum FORECAST
      {
      	STABIEL = 0,		// "Stable Weather Pattern"
      	ZONNIG = 1,			// "Slowly rising Good Weather", "Clear/Sunny "
      	BEWOLKT = 2,		// "Slowly falling L-Pressure ", "BEWOLKT/Rain "
      	ONSTABIEL = 3,	// "Quickly rising H-Press",     "Not Stable"
      	ONWEER = 4,	    // "Quickly falling L-Press",    "ONWEER"
      	ONBEKEND = 5		// "ONBEKEND (More Time needed)
      };
      
      Adafruit_BMP085 bmp = Adafruit_BMP085();      // Digital Pressure Sensor 
      MySensor gw;
      
      float lastPressure = -1;
      float lastTempBMP = -1;
      int lastForecast = -1;
      
      const int LAST_SAMPLES_COUNT = 5;
      float lastPressureSamples[LAST_SAMPLES_COUNT];
      
      // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm
      // get kPa/h be dividing hPa by 10 
      #define CONVERSION_FACTOR (1.0/10.0)
      
      int minuteCount = 0;
      bool firstRound = true;
      // average value is used in forecast algorithm.
      float pressureAvg;
      // average after 2 hours is used as reference value for the next iteration.
      float pressureAvg2;
      
      float dP_dt;
      
      DHT dht;
      float lastTempDHT;
      float lastHum;
      
      boolean metric = true; 
      
      MyMessage tempMsg(TEMP_CHILD, V_TEMP);
      MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
      MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
      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 and Controller
      	
      	gw.sendSketchInfo("BaroHum", "2.0");
      
      	if (!bmp.begin()) 
      	{
      		Serial.println("Could not find a valid BMP085 sensor, check wiring!");
      		while (1) {}
      	}
      
      	// Register sensors to gw (they will be created as child devices)
      	gw.present(BARO_CHILD, S_BARO);
      	gw.present(TEMP_CHILD, S_TEMP);
        gw.present(CHILD_ID_HUM, S_HUM);
        gw.present(CHILD_ID_TEMP, S_TEMP);
       
      	metric = gw.getConfig().isMetric;
      }
      
      void loop() 
      {
      	float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;
      	float temperatureBMP = bmp.readTemperature();
      
      	if (metric) 
      	{
      		// Convert to fahrenheit
      		temperatureBMP = temperatureBMP * 9.0 / 5.0 + 32.0;
      	}
      
      	int forecast = sample(pressure);
      
      	Serial.print("Temperature = ");
      	Serial.print(temperatureBMP);
      	Serial.println(metric ? " *C" : " *F");
      	Serial.print("Pressure = ");
      	Serial.print(pressure);
      	Serial.println(" hPa");
      	Serial.print("Forecast = ");
      	Serial.println(weather[forecast]);
      
      
      	if (temperatureBMP != lastTempBMP) 
      	{
      		gw.send(tempMsg.set(temperatureBMP, 1));
      		lastTempBMP = temperatureBMP;
      	}
      
      	if (pressure != lastPressure) 
      	{
      		gw.send(pressureMsg.set(pressure, 0));
      		lastPressure = pressure;
      	}
      
      	if (forecast != lastForecast)
      	{
      		gw.send(forecastMsg.set(weather[forecast]));
      		lastForecast = forecast;
      	}
      
        delay(dht.getMinimumSamplingPeriod());
      
      float temperatureDHT = dht.getTemperature();
        if (isnan(temperatureDHT)) {
            Serial.println("Failed reading temperature from DHT");
        } else if (temperatureDHT != lastTempDHT  || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          lastTempDHT = temperatureDHT;
          if (!metric) {
            temperatureDHT = dht.toFahrenheit(temperatureDHT);
          }
          nNoUpdatesTemp = 0;
          gw.send(msgTemp.set(temperatureDHT, 1));
          Serial.print("T: ");
          Serial.println(temperatureDHT);
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
        
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
            Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum  || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
            lastHum = humidity;
      
            nNoUpdatesHum = 0;
            gw.send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesHum++;
        }
      
      	gw.sleep(SLEEP_TIME);
      }
      
      float getLastPressureSamplesAverage()
      {
      	float lastPressureSamplesAverage = 0;
      	for (int i = 0; i < LAST_SAMPLES_COUNT; i++)
      	{
      		lastPressureSamplesAverage += lastPressureSamples[i];
      	}
      	lastPressureSamplesAverage /= LAST_SAMPLES_COUNT;
      
      	return lastPressureSamplesAverage;
      }
      
      
      
      // Algorithm found here
      // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
      // Pressure in hPa -->  forecast done by calculating kPa/h
      int sample(float pressure)
      {
      	// Calculate the average of the last n minutes.
      	int index = minuteCount % LAST_SAMPLES_COUNT;
      	lastPressureSamples[index] = pressure;
      
      	minuteCount++;
      	if (minuteCount > 185)
      	{
      		minuteCount = 6;
      	}
      
      	if (minuteCount == 5)
      	{
      		pressureAvg = getLastPressureSamplesAverage();
      	}
      	else if (minuteCount == 35)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change * 2; // note this is for t = 0.5hour
      		}
      		else
      		{
      			dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value.
      		}
      	}
      	else if (minuteCount == 65)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) //first time initial 3 hour
      		{
      			dP_dt = change; //note this is for t = 1 hour
      		}
      		else
      		{
      			dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 95)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 1.5; // note this is for t = 1.5 hour
      		}
      		else
      		{
      			dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 125)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		pressureAvg2 = lastPressureAvg; // store for later use.
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 2; // note this is for t = 2 hour
      		}
      		else
      		{
      			dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 155)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 2.5; // note this is for t = 2.5 hour
      		}
      		else
      		{
      			dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 185)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 3; // note this is for t = 3 hour
      		}
      		else
      		{
      			dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value
      		}
      		pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past.
      		firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop.
      	}
      
      	int forecast = ONBEKEND;
      	if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval.
      	{
      		forecast = ONBEKEND;
      	}
      	else if (dP_dt < (-0.25))
      	{
      		forecast = ONWEER;
      	}
      	else if (dP_dt > 0.25)
      	{
      		forecast = ONSTABIEL;
      	}
      	else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05)))
      	{
      		forecast = BEWOLKT;
      	}
      	else if ((dP_dt > 0.05) && (dP_dt < 0.25))
      	{
      		forecast = ZONNIG;
      	}
      	else if ((dP_dt >(-0.05)) && (dP_dt < 0.05))
      	{
      		forecast = STABIEL;
      	}
      	else
      	{
      		forecast = ONBEKEND;
      	}
      
      	// uncomment when debugging
      	//Serial.print(F("Forecast at minute "));
      	//Serial.print(minuteCount);
      	//Serial.print(F(" dP/dt = "));
      	//Serial.print(dP_dt);
      	//Serial.print(F("kPa/h --> "));
      	//Serial.println(weather[forecast]);
      
      	return forecast;
      }
      /**
       * 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
       * Pressure sensor example using BMP085 module  
       * http://www.mysensors.org/build/pressure
       * Toegevoegd: na 10x dezelfde waarde te hebben gelezen bij TeEmp en Hum toch een waarde aan de GW sturen.
       */
       
      #include <SPI.h>
      #include <Wire.h>
      #include <DHT.h>  
      #include <MySensor.h>  
      #include <Adafruit_BMP085.h>
      
      static const uint8_t FORCE_UPDATE_N_READS = 10;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      
      #define BARO_CHILD 0
      #define TEMP_CHILD 1
      #define CHILD_ID_HUM 2
      #define CHILD_ID_TEMP 3
      
      #define HUMIDITY_SENSOR_DIGITAL_PIN 3
      
      const float ALTITUDE = 1.05; // <-- adapt this value to your own location's altitude.
      
      // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute.
      const unsigned long SLEEP_TIME = 60000; 
      
      const char *weather[] = { "stabiel", "zonnig", "bewolkt", "onstabiel", "onweer", "onbekend" };
      enum FORECAST
      {
      	STABIEL = 0,		// "Stable Weather Pattern"
      	ZONNIG = 1,			// "Slowly rising Good Weather", "Clear/Sunny "
      	BEWOLKT = 2,		// "Slowly falling L-Pressure ", "BEWOLKT/Rain "
      	ONSTABIEL = 3,	// "Quickly rising H-Press",     "Not Stable"
      	ONWEER = 4,	    // "Quickly falling L-Press",    "ONWEER"
      	ONBEKEND = 5		// "ONBEKEND (More Time needed)
      };
      
      Adafruit_BMP085 bmp = Adafruit_BMP085();      // Digital Pressure Sensor 
      MySensor gw;
      
      float lastPressure = -1;
      float lastTempBMP = -1;
      int lastForecast = -1;
      
      const int LAST_SAMPLES_COUNT = 5;
      float lastPressureSamples[LAST_SAMPLES_COUNT];
      
      // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm
      // get kPa/h be dividing hPa by 10 
      #define CONVERSION_FACTOR (1.0/10.0)
      
      int minuteCount = 0;
      bool firstRound = true;
      // average value is used in forecast algorithm.
      float pressureAvg;
      // average after 2 hours is used as reference value for the next iteration.
      float pressureAvg2;
      
      float dP_dt;
      
      DHT dht;
      float lastTempDHT;
      float lastHum;
      
      boolean metric = true; 
      
      MyMessage tempMsg(TEMP_CHILD, V_TEMP);
      MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
      MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
      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 and Controller
      	
      	gw.sendSketchInfo("BaroHum", "2.0");
      
      	if (!bmp.begin()) 
      	{
      		Serial.println("Could not find a valid BMP085 sensor, check wiring!");
      		while (1) {}
      	}
      
      	// Register sensors to gw (they will be created as child devices)
      	gw.present(BARO_CHILD, S_BARO);
      	gw.present(TEMP_CHILD, S_TEMP);
        gw.present(CHILD_ID_HUM, S_HUM);
        gw.present(CHILD_ID_TEMP, S_TEMP);
       
      	metric = gw.getConfig().isMetric;
      }
      
      void loop() 
      {
      	float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;
      	float temperatureBMP = bmp.readTemperature();
      
      	if (metric) 
      	{
      		// Convert to fahrenheit
      		temperatureBMP = temperatureBMP * 9.0 / 5.0 + 32.0;
      	}
      
      	int forecast = sample(pressure);
      
      	Serial.print("Temperature = ");
      	Serial.print(temperatureBMP);
      	Serial.println(metric ? " *C" : " *F");
      	Serial.print("Pressure = ");
      	Serial.print(pressure);
      	Serial.println(" hPa");
      	Serial.print("Forecast = ");
      	Serial.println(weather[forecast]);
      
      
      	if (temperatureBMP != lastTempBMP) 
      	{
      		gw.send(tempMsg.set(temperatureBMP, 1));
      		lastTempBMP = temperatureBMP;
      	}
      
      	if (pressure != lastPressure) 
      	{
      		gw.send(pressureMsg.set(pressure, 0));
      		lastPressure = pressure;
      	}
      
      	if (forecast != lastForecast)
      	{
      		gw.send(forecastMsg.set(weather[forecast]));
      		lastForecast = forecast;
      	}
      
        delay(dht.getMinimumSamplingPeriod());
      
      float temperatureDHT = dht.getTemperature();
        if (isnan(temperatureDHT)) {
            Serial.println("Failed reading temperature from DHT");
        } else if (temperatureDHT != lastTempDHT  || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          lastTempDHT = temperatureDHT;
          if (!metric) {
            temperatureDHT = dht.toFahrenheit(temperatureDHT);
          }
          nNoUpdatesTemp = 0;
          gw.send(msgTemp.set(temperatureDHT, 1));
          Serial.print("T: ");
          Serial.println(temperatureDHT);
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
        
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
            Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum  || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
            lastHum = humidity;
      
            nNoUpdatesHum = 0;
            gw.send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesHum++;
        }
      
      	gw.sleep(SLEEP_TIME);
      }
      
      float getLastPressureSamplesAverage()
      {
      	float lastPressureSamplesAverage = 0;
      	for (int i = 0; i < LAST_SAMPLES_COUNT; i++)
      	{
      		lastPressureSamplesAverage += lastPressureSamples[i];
      	}
      	lastPressureSamplesAverage /= LAST_SAMPLES_COUNT;
      
      	return lastPressureSamplesAverage;
      }
      
      
      
      // Algorithm found here
      // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
      // Pressure in hPa -->  forecast done by calculating kPa/h
      int sample(float pressure)
      {
      	// Calculate the average of the last n minutes.
      	int index = minuteCount % LAST_SAMPLES_COUNT;
      	lastPressureSamples[index] = pressure;
      
      	minuteCount++;
      	if (minuteCount > 185)
      	{
      		minuteCount = 6;
      	}
      
      	if (minuteCount == 5)
      	{
      		pressureAvg = getLastPressureSamplesAverage();
      	}
      	else if (minuteCount == 35)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change * 2; // note this is for t = 0.5hour
      		}
      		else
      		{
      			dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value.
      		}
      	}
      	else if (minuteCount == 65)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) //first time initial 3 hour
      		{
      			dP_dt = change; //note this is for t = 1 hour
      		}
      		else
      		{
      			dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 95)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 1.5; // note this is for t = 1.5 hour
      		}
      		else
      		{
      			dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 125)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		pressureAvg2 = lastPressureAvg; // store for later use.
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 2; // note this is for t = 2 hour
      		}
      		else
      		{
      			dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 155)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 2.5; // note this is for t = 2.5 hour
      		}
      		else
      		{
      			dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 185)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 3; // note this is for t = 3 hour
      		}
      		else
      		{
      			dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value
      		}
      		pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past.
      		firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop.
      	}
      
      	int forecast = ONBEKEND;
      	if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval.
      	{
      		forecast = ONBEKEND;
      	}
      	else if (dP_dt < (-0.25))
      	{
      		forecast = ONWEER;
      	}
      	else if (dP_dt > 0.25)
      	{
      		forecast = ONSTABIEL;
      	}
      	else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05)))
      	{
      		forecast = BEWOLKT;
      	}
      	else if ((dP_dt > 0.05) && (dP_dt < 0.25))
      	{
      		forecast = ZONNIG;
      	}
      	else if ((dP_dt >(-0.05)) && (dP_dt < 0.05))
      	{
      		forecast = STABIEL;
      	}
      	else
      	{
      		forecast = ONBEKEND;
      	}
      
      	// uncomment when debugging
      	//Serial.print(F("Forecast at minute "));
      	//Serial.print(minuteCount);
      	//Serial.print(F(" dP/dt = "));
      	//Serial.print(dP_dt);
      	//Serial.print(F("kPa/h --> "));
      	//Serial.println(weather[forecast]);
      
      	return forecast;
      }
      
      posted in Development
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      Hi all,

      All works fine now! After the reshuffle of the connection pins it does what I want it to do.
      Only thing I need to change is the sleeptime, it's now set to 6000 and when no change send a value to the GW after ten readings. But it is to often now..

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      @MLs

      Hi, thanks for your input, whit setup of the pins you used I have no more failed to read from DHT sensors in my serial monitor.

      Now I need to revise my sketch, so it will send correct values.

      Thanks again!

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      Hi all,

      Now I have bought a stepdown regulator to regulate the power for the radio.
      The readings of the sensor are the same as not using the stepdown regulator. So what can be wrong?
      Or is it not possible to use a LDR and a DHT11 together?

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      @TheoL I use a telephone charger most of the time, I'm a beginner with all.
      Hope to make this a battery oparated sensor, will search for the components you mentioned.

      thanks

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      Yes, that did it,

      Thanks @sundberg84 and @TheoL for your time..

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      Maybe This has something to do with it:

       dht.setup(LIGHT_SENSOR_ANALOG_PIN); 
      

      The Lightsensor isn't belonging to the DHT sensor.. I think 😕

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      I have now rebooted my GW so sending will be OK:

      send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=fail:1.5
      send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
      sensor started, id=1, parent=0, distance=1
      send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=16,sg=0,st=fail:HumidityAndLight
      send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:0.2
      send: 1-1-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=fail:
      send: 1-1-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=fail:
      find parent
      send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
      send: 1-1-0-0 s=2,c=0,t=16,pt=0,l=0,sg=0,st=fail:
      Failed reading temperature from DHT
      Failed reading humidity from DHT
      send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=fail:61.2
      L: 61.2
      Failed reading temperature from DHT
      Failed reading humidity from DHT
      send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=ok:6.9
      L: 6.9
      Failed reading temperature from DHT
      Failed reading humidity from DHT
      send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=ok:7.1
      L: 7.1
      
      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      @sundberg84 My node is approx 3 meters away from the gateway, and now I am powering it from the computer, it's an Arduino Nano with USB cable.

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      Hi @sundberg84 I made a higher delay before of the reading of the lightLevel, [delay(1000);] But that didn't change any of the outcome.
      What about the capacitator? do I have to use another one?

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: DHT and LDR separately working, but together not, what's wrong?

      Okay,

      I understand, here they are:

      TempHum only:

      send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=fail:1.5
      send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
      sensor started, id=1, parent=0, distance=1
      send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=8,sg=0,st=fail:Humidity
      send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.0
      send: 1-1-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=fail:
      send: 1-1-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=fail:
      find parent
      send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
      send: 1-1-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,st=fail:24.0
      T: 24.00
      send: 1-1-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=fail:38.0
      H: 38.00
      
      

      With LDR added:

      send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=fail:1.5
      send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
      sensor started, id=1, parent=0, distance=1
      send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=16,sg=0,st=fail:HumidityAndLight
      send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.0
      send: 1-1-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=fail:
      send: 1-1-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=fail:
      find parent
      send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
      send: 1-1-0-0 s=2,c=0,t=16,pt=0,l=0,sg=0,st=fail:
      Failed reading temperature from DHT
      Failed reading humidity from DHT
      send: 1-1-0-0 s=2,c=1,t=23,pt=2,l=2,sg=0,st=fail:62
      L: 62
      Failed reading temperature from DHT
      Failed reading humidity from DHT
      
      
      posted in Troubleshooting
      DannyM
      DannyM
    • DHT and LDR separately working, but together not, what's wrong?

      Hi all,

      I have a simple sketch for humidity and temperature reading and I want to add a LDR for light level readings. But, separately the sketches for the humidity and temp is working. when putting it together only the LightReading is working.

      What's wrong? hardware is the same for both sketches.

      Thanks, Danny

      Hum/Temp code:

      /**
       * 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>  
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define HUMIDITY_SENSOR_DIGITAL_PIN 3
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      
      MySensor gw;
      DHT dht;
      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;
      }
      
      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);
        }
      
        gw.sleep(SLEEP_TIME); //sleep a bit
      }
      
      
      

      Code: HUM/TMP/LDR:

      /**
      * 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>  
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_LIGHT 2
      #define HUMIDITY_SENSOR_DIGITAL_PIN 4
      #define LIGHT_SENSOR_ANALOG_PIN A1
      
      #define MY_DEBUG
      
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      
      MySensor gw;
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true; 
      int lastLightLevel;
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      
      void setup()  
      { 
       gw.begin();
       dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
       dht.setup(LIGHT_SENSOR_ANALOG_PIN); 
      
       // Send the Sketch Version Information to the Gateway
       gw.sendSketchInfo("HumidityAndLight", "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);
       gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
         
       metric = gw.getConfig().isMetric;
      }
      
      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);
       }
           
       int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
       Serial.print("L: "); 
       Serial.println(lightLevel);
       if (lightLevel != lastLightLevel) {
           gw.send(msgLight.set(lightLevel));
           lastLightLevel = lightLevel;
       }
      
       gw.sleep(SLEEP_TIME); //sleep a bit
      }
      
      
      posted in Troubleshooting
      DannyM
      DannyM
    • RE: RFID Garage door opener

      Hi @BartE,

      Works great, but I want to let the masterkey trigger a second alarm, what way should I think; I have tried to let the mastercard open a second relay, but it didn't work. Maybe I should use a second programmed key lets say personkey and trigger on that? Can you give me some directions?

      Thanks Danny

      posted in My Project
      DannyM
      DannyM
    • RE: Led Ring ideas?

      Maybe you can show your solar power output displayed!

      posted in My Project
      DannyM
      DannyM
    • RE: RFID 2 person readout

      @BartE

      I think I have enough code for what I want, it is in the

      void storeEprom() 
      void recallEeprom()
      

      functions. So I am gonna try to implement this into my code.

      Thanks so far..

      posted in Troubleshooting
      DannyM
      DannyM
    • RE: help . power supply and add motion sensor to vera controller

      @Reza

      Hi, for question 2, you can go to this url on this website, everything is explained thee.
      vera#including-new-sensors

      You only have to startup your device two times, after initiate a start in the Vera Mysensors plugin.

      For question 2; you can use a usb to telephone charger for it too..

      posted in My Project
      DannyM
      DannyM
    • RFID 2 person readout

      Hi all,

      IDE1.6.5; nano v3

      I want to make a sketch to check with RFID cards which person is present.

      So far I have it working for one person, but I don't know how to change the code so It will work for two or more persons. Each person (card) needs to (un)lock another lock in Vera.

      Is there somebody who can help me to get started?

      This is my code:

      /*
       * ----------------------------------------------------------------------------
       * This sketch uses the MFRC522 library ; see https://github.com/miguelbalboa/rfid
       * for further details and other examples.
       * 
       * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
       * 
       * This sketch show a simple locking mechanism using the RC522 RFID module.
       * ----------------------------------------------------------------------------
       * Typical pin layout used:
       * -----------------------------------------------------------------------------------------
       *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
       *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
       * Signal      Pin          Pin           Pin       Pin        Pin              Pin
       * -----------------------------------------------------------------------------------------
       * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
       * SPI SS      SDA(SS)      10            53        D10        10               10
       * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
       * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
       * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
       *
       * RC522 module shares pins:
       * Pin 11 MOSI
       * Pin12 MISO
       * Pin 13 SCK
       * And extra:
       * pin7 (iso9) for CE
       * pin 8(iso10) for CSN/CS
       * If your SPI module needs an IRQ also use a different pin for pin 2 (IRQ) as well
       */
      #include <MySensor.h>
      #include <SPI.h>
      #include <MFRC522.h>
      
      #define RST_PIN         7           // Configurable, see typical pin layout above
      #define SS_PIN          8          // Configurable, see typical pin layout above
      
      #define CHILD_ID_RFID1 0
      #define CHILD_ID_RFID2 1
      
      bool lockStatus;
      MySensor gw;
      MyMessage msgP1(CHILD_ID_RFID1, V_LOCK_STATUS);
      MyMessage msgP2(CHILD_ID_RFID2, V_LOCK_STATUS);
      
      MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
      
      String read_rfid;
      String ok_rfid_1="abcdefg";
      String ok_rfid_2="hijklmn"; //add as many as you need.
      
      //Use the lines below if you plan on using a servo as a locking mechanism.
      #include <Servo.h> 
      Servo myservo;  // create servo object to control a servo 
      int posClosed = 0;    // variable to store the servo position for locked
      int posOpen = 270;    //same for open...
      
      /*
       * Initialize.
       */
      void setup() {
          Serial.begin(11500);         // Initialize serial communications with the PC
          while (!Serial);            // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
      // First make sure mfrc is releasing the SPI bus 
          pinMode(RST_PIN, OUTPUT);     
          digitalWrite(RST_PIN, LOW);
          pinMode(SS_PIN, OUTPUT);     
          digitalWrite(SS_PIN, LOW);
      
          // Init mysensors library
          gw.begin(incomingMessage);
      
           // Init MFRC RFID sensor
          SPI.begin();            // Init SPI bus
          mfrc522.PCD_Init();     // Init MFRC522
      
          //Choose which lock below:
          //pinMode(lock, OUTPUT);
          myservo.attach(2);  // attaches the servo on pin 2 to the servo object 
      
            // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("RFID", "0.0.5");
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_RFID1, S_LOCK);
        gw.present(CHILD_ID_RFID2, S_LOCK);
      
        lockStatus = gw.loadState(0);    // Read last lock status from eeprom
        setLockState(lockStatus, true); // Now set the last known state and send it to controller 
      }
      
      /*
       * Helper routine to dump a byte array as hex values to Serial.
       */
      void dump_byte_array(byte *buffer, byte bufferSize) {
          read_rfid="";
          for (byte i = 0; i < bufferSize; i++) {
              read_rfid=read_rfid + String(buffer[i], HEX);
          }
      }
      
      void open_lock() {
        //Use this routine when working with Relays and Solenoids etc.
        //digitalWrite(lock, HIGH);
        //delay(2000);
        //digitalWrite(lock,LOW);
        
        //Use this routine when working with Servos.
        myservo.write(posOpen); 
        delay(2000);
        myservo.write(posClosed);
      
      }
      
      void loop() {
          gw.process(); // Process incomming messages
      
      //  boolean success;  //niet nodig met onderstaande if functie
          // Look for new cards
          if ( ! mfrc522.PICC_IsNewCardPresent())
              return;
      
          // Select one of the cards
          if ( ! mfrc522.PICC_ReadCardSerial())
              return;
      
          dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
          //Serial.println(read_rfid);
          if (read_rfid==ok_rfid_1) {
            //ok, open the door.
            setLockState(!lockStatus, true);
            Serial.println("Hi person1");
            open_lock();     
          }
          if (read_rfid==ok_rfid_2) {
            //ok, open the door.
            //setLockState(!lockStatus, true);
            Serial.println("Hi person2");
            open_lock();
          }
          //Add below as many "keys" as you want
          //if (read_rfid==ok_rfid_2) {
            //also ok, open the door
          //  open_lock();
          //}
          // else not needed. Anything else is not ok, and will not open the door..
      }
      
      // open door and set state.
      void setLockState(bool state, bool send){
        if (state) 
           Serial.println("open lock");
        else
           Serial.println("close lock");
        if (send)
           gw.send(msgP1.set(state));
      //  digitalWrite(lockPin, state);
         gw.saveState(0,state);
         lockStatus = state;
       }
      
      void incomingMessage(const MyMessage &message) {
         // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LOCK_STATUS) {
           // Change relay state
            setLockState(message.getBool(), false);
          }  
           // Write some debug info
           Serial.print("Incoming lock status:");
           Serial.println(message.getBool());
      } 
      
      posted in Troubleshooting
      DannyM
      DannyM