3-in-1 Humidity Temp and Motion
-
hi,
thanks I did some reading my self and realised I needed the resistor works a treat now. thanks for the reply.
@Opus40 Great!
I am currently finalising a 5 in 1 sensor... just testing and so far its working fantastic
-
@Opus40 Great!
I am currently finalising a 5 in 1 sensor... just testing and so far its working fantastic
@Konrad-Walsh said:
I am currently finalising a 5 in 1 sensor... just testing and so far its working fantastic
Hum-temp-motion-light-???
-
@Konrad-Walsh said:
I am currently finalising a 5 in 1 sensor... just testing and so far its working fantastic
Hum-temp-motion-light-???
@Nuubi LOL.. its a secret!!!
and I will share my carefully guarded secret... Air quality sensor!! or in other words.. smoke and gas detector...
-
Did you mount your PIR behind the rounded screen area on those cases? It works through that?
I have yet to get to integrating PIR's in to my sensors, but do plan to, and was curious how to effectively mount them. Need to offer protection from the circuitry, but visibility to the sensor itself.
-
Question about a minor detail:
Wouldn't a motionsenser trip be missed during:
delay(dht.getMinimumSamplingPeriod()); ?
For a DHT22 this is 2 seconds... or does the interrupt still has precedence?@C4Vette you could just use a non-blocking method to read the temperature instead of the delay.
The delay is method is in the library and used so that multiple reads to the sensor don't affect the reading (overheating the sensor).
since SLEEP_TIME is 30s in the code above... I'd just read the temperature each time the sensor was awakened.
you could just timestamp the last reading and check that at least the 2 seconds elapsed since the last reading before you take a new one (in the case that motion was detected.
-
@C4Vette you could just use a non-blocking method to read the temperature instead of the delay.
The delay is method is in the library and used so that multiple reads to the sensor don't affect the reading (overheating the sensor).
since SLEEP_TIME is 30s in the code above... I'd just read the temperature each time the sensor was awakened.
you could just timestamp the last reading and check that at least the 2 seconds elapsed since the last reading before you take a new one (in the case that motion was detected.
@BulldogLowell
Ok, thanks for explaining. I'm no programmer but trying to understand the code. So because there is also a sleep-periode, the earlier mentioned delay could be omitted? I do not fully understand how the motion interrupt is working but I replaced the 30 second sleep with a few lines using millis, as you implied so that the loop keeps on running to do other things.
At the moment my sensor is a working combination of a LED-dimmer with a motion-sensor and now trying to add a DHT. This stuff is fun!
Posted some photo's at http://forum.mysensors.org/topic/781/my-led-dimmer-motion-temp-hum-sensor -
I am wanted to share my 3-in-1 sensor in case its of use to anyone
Its really just a combination of what's already availableI used the following hardware:
Arduino Nano LINK - Gave me both 3.3v and 5v output without having to mess with extra hardware(steppers)
1 x Motion Sensor LINK
1 x DHT22 LINKConnections is as all other guides except:
Motion Sensor digital to Pin D3
and the DHT to Pin D4Here is my code
#include <SPI.h> #include <MySensor.h> #include <DHT.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_MOT 2 // Id of the sensor child #define HUMIDITY_SENSOR_DIGITAL_PIN 4 #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) 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); MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED); void setup() { gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Humidity/Motion", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input // 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_MOT, S_MOTION); metric = gw.getConfig().isMetric; } void loop() { // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); gw.send(msgMot.set(tripped?"1":"0")); // Send tripped value to gw 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); } // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); }If anyone wants more info please ask.. I will put up pictures or diagrams if needed
@Konrad-Walsh said:
I am wanted to share my 3-in-1 sensor in case its of use to anyone
Its really just a combination of what's already availableIf anyone wants more info please ask.. I will put up pictures or diagrams if needed
I'm having a problem with this build.
i'm using the same hardware.I get nothing in the serial output screen.
i am able to compile and load the code.
when i measure on the 3.3 rail i get 3.8 (only when the radio is hooked up, i get 3.3 when nothing is hooked to the board)
when i measure on the 5v rail, i get 4.7v when the motion and temp sensor are hooked up.I suspect my issues may be voltage related. although i'm not sure why i'm getting nothing on the serial monitor.
since you said you didn't need any steppers, do you have any suggestions?
thanks -
I am wanted to share my 3-in-1 sensor in case its of use to anyone
Its really just a combination of what's already availableI used the following hardware:
Arduino Nano LINK - Gave me both 3.3v and 5v output without having to mess with extra hardware(steppers)
1 x Motion Sensor LINK
1 x DHT22 LINKConnections is as all other guides except:
Motion Sensor digital to Pin D3
and the DHT to Pin D4Here is my code
#include <SPI.h> #include <MySensor.h> #include <DHT.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_MOT 2 // Id of the sensor child #define HUMIDITY_SENSOR_DIGITAL_PIN 4 #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) 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); MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED); void setup() { gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Humidity/Motion", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input // 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_MOT, S_MOTION); metric = gw.getConfig().isMetric; } void loop() { // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); gw.send(msgMot.set(tripped?"1":"0")); // Send tripped value to gw 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); } // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); }If anyone wants more info please ask.. I will put up pictures or diagrams if needed
@Konrad-Walsh my nano and pro mini on the way! double each! cant wait!! fed up all confused so have ard r3 n mega n nano n promini all tick tick!
-
Works like a charm...
Thanks for sharing :)
-
Looks pretty sweet. How is it working comparing to existing products with the same features?
-
Hi Konrad
Thx for great code. It works like charm but...
I have a question... It is possible to add to Your code one more (Door/Window) sensor?
Mayby You can post that code on this forum?
Best regards -
Hi to all
I changed a little Konrad sketch and add to 3in1 Humidity Temp and Motion one more sensor (Door\Window)
Here is my code:
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
#include <Bounce2.h>#define CHILD_ID_DOOR 3
#define BUTTON_PIN_DOOR 2
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define CHILD_ID_MOT 2 // Id of the sensor child
#define HUMIDITY_SENSOR_DIGITAL_PIN 4#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
MySensor gw;
Bounce debouncer = Bounce();
int oldValue=-1;DHT dht;
float lastTemp;
float lastHum;
boolean metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
MyMessage msgDoor(CHILD_ID_DOOR,V_TRIPPED);void setup()
{
gw.begin();
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);pinMode(BUTTON_PIN_DOOR,INPUT);
digitalWrite(BUTTON_PIN_DOOR,HIGH);debouncer.attach(BUTTON_PIN_DOOR);
debouncer.interval(5);// Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("4in1", "1.0");pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
// 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_MOT, S_MOTION);
gw.present(CHILD_ID_DOOR, S_DOOR);metric = gw.getConfig().isMetric;
}void loop()
{
// Read digital motion value
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;Serial.println(tripped);
gw.send(msgMot.set(tripped?"1":"0")); // Send tripped value to gwdelay(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);
}debouncer.update();
// Get the update value
int value = debouncer.read();if (value != oldValue) {
// Send in the new value
gw.send(msgDoor.set(value==HIGH ? 1 : 0));
oldValue = value;
}// Sleep until interrupt comes in on motion sensor. Send update every two minute.
//gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
}Now it is 4in1 :)
-
This post is deleted!
-
Has the 3in1 sketch been updated to 2.0 yet? I need some help with it, im not tot keen with coding...
-
Has the 3in1 sketch been updated to 2.0 yet? I need some help with it, im not tot keen with coding...
This is HUM TEMP and PIR
This is what I'm using and it runs in mysensors 2.0
None battery powered. NO sleep mode and dirty code but it runs well enough for me right now.
If you add or fix anything please post it for everyone.#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <MySensors.h> #include <DHT.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_MOT 2 //me #define HUMIDITY_SENSOR_DIGITAL_PIN 4 #define DIGITAL_INPUT_SENSOR 2 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) DHT dht; float lastTemp; float lastHum; boolean metric = false; unsigned long interval= 3000;//dht.getMinimumSamplingPeriod(); // the time we need to wait unsigned long previousMillis=0; // millis() returns an unsigned long. unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED); //me void setup() { dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // metric = getConfig().isMetric; pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input } void presentation() { // Send the Sketch Version Information to the Gateway sendSketchInfo("3-1 Sensor", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); present(CHILD_ID_MOT, V_TRIPPED); //me } void loop() { // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; // only run loop if time has passed. unsigned long currentMillis = millis(); // grab current time // check if "interval" time has passed if ((unsigned long)(currentMillis - previousMillis) >= interval) { send(msgMot.set(tripped?"1":"0")); #ifdef MY_DEBUG Serial.print("Motion: "); Serial.println(tripped); #endif // Fetch temperatures from DHT sensor 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); } send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } // Fetch humidity from DHT sensor float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum) { lastHum = humidity; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } // save the "current" time previousMillis = millis(); } // Sleep until interrupt comes in on motion sensor. Send update every two minute. //sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); }``` -
My sample is here, unfortunately I didn't see this thread before starting it :)
It works for temp, humidity, door and motion, and interrupts for door and motion, otherwise sleeps the intervals:https://github.com/ikke-t/sensebender
There is also pro-mini to code to monitor only door and motion.
This is also for 2.0 MySensors.