@m26872 Thanks for the input.
@Tom71 Have you looked at your controller software if you could manage the "no Motion state" after 20sec ? I'm using domoticz and I could set an "Off delay", avoiding the emission of a zero from the sensor.
@m26872 Thanks for the input.
@Tom71 Have you looked at your controller software if you could manage the "no Motion state" after 20sec ? I'm using domoticz and I could set an "Off delay", avoiding the emission of a zero from the sensor.
There are a some low voltage temp+hum alternatives, although not cheaper than the DHT.
There's at least the Si7021, which should work between 1.9v and 3.6v
@m26872 You wrote about the idea of letting the sensor ask my controller when to arm or to disarm : have you figured out what way the node could get that information from the controller ?
Hello !
@Tom71 Had you had the bigger PIR sensor, you could have adapted the delay manually, but it seems this smaller device doesn't offer that possibility. But I think you could wake up the node on a "CHANGE" interrupt instead of only "RISING" as in the example. For this PIR, it would happen approx 8s after last movement detection. Maybe you could add a 12s sleep phase before sending the zero ?
@m26872 I've read somewhere that a short distance between the nrf24l01 and the motion sensor could lead to perturbations, and I wonder if you've tested a bigger separation between them and also got those false trips ? They are very close to each other on your example, which makes me wonder.
Mikael
Hello,
For the temperature, the mcp9700 is cheap and works from 2.3v up to 3.1v. The accuracy is not good out of the box (+-2°c) but it can be improved via calibration.
Here's some reading about it : http://blog.kkessler.com/2012/06/20/mcp9700/
Mikael
Hi,
I'm working on a battery operated node doing motion + temp, and I use Yveaux's Arduino_Vcc library to measure battery voltage.
I've tested the voltage from the 2 AAs and it's 2.99v, but the internal measurement gives 2.22v. I have a 25% difference where we should expect max 10%, shouldn't we ?
I'll try to debug that tomorrow with a dedicated sketch, but maybe someone can easily spot the error in the following code ?
/**
* DESCRIPTION
* Motion Sensor (HC-SR501) + Temp sensor (MCP9700 analog sensor)
* inspired by :
* mysensors PIR example created by Henrik Ekblad : http://www.mysensors.org/build/motion
* Slim Node as a Mini 2AA Battery PIR Motion Sensor : http://forum.mysensors.org/topic/2715/slim-node-as-a-mini-2aa-battery-pir-motion-sensor
* Kevin Kessler's blog for reading MCP9700 temperature sensor : http://blog.kkessler.com/2012/06/20/mcp9700/
*/
#include <MySensor.h>
#include <SPI.h>
#include <Vcc.h>
#define NODE_ID 30
#define MOTION_INPUT_PIN 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define CHILD_ID_MOTION 1
#define CHILD_ID_TEMP 2
#define CHILD_ID_BATT 3
#define DOMOTICZ_OFF_DELAY 10000
#define MINIMUM_SEND_INTERVAL 86400000 // once a day
#define TEMP_SEND_FREQ 300000 // every 5min
#define TEMP_SEND_THRESHOLD 0.3 // do not send temp if variation is below delta
#define VCC_MIN 1.9
#define VCC_MAX 3.3
float lastTemperature = 0;;
float lastVoltage = 0;
int loopCounter = 0;
bool interruptReturn = false; // "false" will make the first loop disregard high output from HC-SR501 (from start-up) and make a battery+temp report instead.
Vcc vcc(1.34); // 2.98/2.22=1.3423 . Can this be ok ???
MySensor gw;
MyMessage msgMotion(CHILD_ID_MOTION, V_TRIPPED);
MyMessage msgTemp(CHILD_ID_TEMP,V_TEMP);
MyMessage msgBattery(CHILD_ID_BATT, V_VOLTAGE);
void setup()
{
delay(100); // to settle power for radio
gw.begin(NULL, NODE_ID);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Motion & Temp Sensor", "1.0");
pinMode(MOTION_INPUT_PIN, 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_MOTION, S_MOTION);
gw.present(CHILD_ID_TEMP, S_TEMP);
gw.present(CHILD_ID_BATT, S_MULTIMETER);
gw.sleep(20000); // Wait until motion sensor warmed-up and output returned low.
}
void loop()
{
int sleeptime = 0;
if (interruptReturn) { // Woke up by rising pin
gw.send(msgMotion.set("1")); // Domoticz will take care of setting the node off after some delay
sleeptime = DOMOTICZ_OFF_DELAY; // sleep until domoticz sets the sensor off on its side
}
else
{
float voltage = vcc.Read_Volts();
float temperature = readMCP9700(4,0);
// send if variation is enough or if delay was reached
if (abs(temperature - lastTemperature) >= TEMP_SEND_THRESHOLD) {
lastTemperature = temperature;
sleeptime = 3000;
loopCounter = 0;
gw.send(msgTemp.set(temperature, 1));
}
// send on first iteration, then if variation is enough or if delay was reached
if (abs(voltage - lastVoltage) >= 0.1) {
sendBatteryReport(voltage);
sleeptime = 3000;
loopCounter = 0;
lastVoltage = voltage;
}
if (loopCounter++ * TEMP_SEND_FREQ >= MINIMUM_SEND_INTERVAL) {
loopCounter = 0;
sleeptime = 3000;
gw.send(msgTemp.set(temperature, 1));
sendBatteryReport(voltage);
}
}
if (sleeptime) {
gw.sleep(sleeptime); // Make sure everything is stable before start to sleep with interrupts. (don't use "gw.wait()" here). Tests shows false trip ~2s after battery report otherwise.
}
interruptReturn = gw.sleep(MOTION_INPUT_PIN-2, RISING, TEMP_SEND_FREQ);
}
void sendBatteryReport(float voltage) {
float perc = 100.0 * (voltage-VCC_MIN) / (VCC_MAX-VCC_MIN);
gw.send(msgBattery.set(voltage, 2));
gw.sendBatteryLevel(static_cast<int>(perc));
}
// this function comes from Kevin Kessler's blog : http://blog.kkessler.com/2012/06/20/mcp9700/
float readMCP9700(int pin,float offset)
{
analogReference(INTERNAL);
for (int n=0;n<5;n++)
analogRead(pin);
int adc=analogRead(pin);
float tSensor=((adc*(1.1/1024.0))-0.5+offset)*100;
float error=244e-6*(125-tSensor)*(tSensor - -40.0) + 2E-12*(tSensor - -40.0)-2.0;
float temp=tSensor-error;
return temp;
}
Regards
Mikael
@AWI it was not clear, but I was thinking of using a mosfet in combination with the water level sensor shown in my first post, which is in fact drawing about 1.4mA when dry, and around 15mA when put in water.
Add those 1.4mA to the those taken by the step up, and it feels like the mosfet would lower that a lot when the node is sleeping (if I read the datasheet correctly, it draws between 25 and 250µA, depending on its operating temperature).
Thanks. That seems indeed a good and simple alternative. And potentially cheap as I've found this one.
Besides, I've read a (very little) bit about mosfets and concluded that a N-Channel where one digital pin feeding 0 or 3.3v to the gate, and the load (3.3v step-up + sensor) could be a nice solution. I read about the IRL540N which could be a relevant mosfet. Well, I would not be surprised my conclusions are wrong. Any thought about that ?
Regards,
Mikael
Hello,
Do you mean I should use water as a conductor between 2 unjoined wires or some other technique ?
I'm affraid relying on water as a conductor would lead to many false positives as my basement is always quite wet (old house on granit with unsufficient drainage), and I've choosen this sensor because it should give a better understanding of how much water there is.
Actually, I've read some posts where people use mosfets and feel it could be an option but that's a unknown field to me, so I'm looking for alternatives or examples.
Regards
Mikael
Hello,
I've bought a water level sensor one year ago, and would now like to set it up on a battery powered sensor in order to detect a flood in my basement.
I'm not sure about the infos I've found about this sensor, but if I'm correct, it can work at 3.3v (not below) and it takes 20mA, which could be ok if I power it on only when needed, which would be about once or twice a day.
Would you have a suggestion / example about which way to handle power on/off for this thing (which would have to be wired to a 3.3v step up to cope with discharge) ?
Regards
Mikael