@rborer said:
Why not broadcast ?
Indeed something like a livestream would be great ! Also for the people somewhere else in the world ( or even closer the Dutch people with transporting / time problems like mine )
@rborer said:
Why not broadcast ?
Indeed something like a livestream would be great ! Also for the people somewhere else in the world ( or even closer the Dutch people with transporting / time problems like mine )
I planned to come over, but my son is sick so I'll had to take care of him ;(
@Yveaux said:
@the-cosmic-gate I don't know the sketch, so I don't know.
Why not just try it?
The sketch would be then:
/**
* 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
* Use this sensor to measure volume and flow of your house watermeter.
* You need to set the correct pulsefactor of your meter (pulses per m3).
* The sensor starts by fetching current volume reading from gateway (VAR 1).
* Reports both volume and flow back to gateway.
*
* Unfortunately millis() won't increment when the Arduino is in
* sleepmode. So we cannot make this sensor sleep if we also want
* to calculate/report flow.
* http://www.mysensors.org/build/pulse_water
*/
#include <SPI.h>
#include <MySensor.h>
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your sensor. (Only 2 and 3 generates interrupt!)
#define SENSOR_INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define PULSE_FACTOR 1000 // Nummber of blinks per m3 of your meter (One rotation/liter)
#define SLEEP_MODE false // flowvalue can only be reported when sleep mode is false.
#define MAX_FLOW 40 // Max flow (l/min) value to report. This filters outliers.
#define CHILD_ID 1 // Id of the sensor child
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
MySensor gw;
MyMessage flowMsg(CHILD_ID,V_FLOW);
MyMessage volumeMsg(CHILD_ID,V_VOLUME);
MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
double ppl = ((double)PULSE_FACTOR)/1 // Pulses per liter
volatile unsigned long pulseCount = 0;
volatile unsigned long lastBlink = 0;
volatile double flow = 0;
boolean pcReceived = false;
unsigned long oldPulseCount = 0;
unsigned long newBlink = 0;
double oldflow = 0;
double volume =0;
double oldvolume =0;
unsigned long lastSend =0;
unsigned long lastPulse =0;
void setup()
{
gw.begin(incomingMessage);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Water Meter", "1.2");
// Register this device as Waterflow sensor
gw.present(CHILD_ID, S_WATER);
pulseCount = oldPulseCount = 0;
// Fetch last known pulse count value from gw
gw.request(CHILD_ID, V_VAR1);
lastSend = lastPulse = millis();
attachInterrupt(SENSOR_INTERRUPT, onPulse, RISING);
}
void loop()
{
gw.process();
unsigned long currentTime = millis();
// Only send values at a maximum frequency or woken up from sleep
if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY))
{
lastSend=currentTime;
if (!pcReceived) {
//Last Pulsecount not yet received from controller, request it again
gw.request(CHILD_ID, V_VAR1);
return;
}
if (!SLEEP_MODE && flow != oldflow) {
oldflow = flow;
Serial.print("l/min:");
Serial.println(flow);
// Check that we dont get unresonable large flow value.
// could hapen when long wraps or false interrupt triggered
if (flow<((unsigned long)MAX_FLOW)) {
gw.send(flowMsg.set(flow, 2)); // Send flow value to gw
}
}
// No Pulse count received in 2min
if(currentTime - lastPulse > 120000){
flow = 0;
}
// Pulse count has changed
if (pulseCount != oldPulseCount) {
oldPulseCount = pulseCount;
Serial.print("pulsecount:");
Serial.println(pulseCount);
gw.send(lastCounterMsg.set(pulseCount)); // Send pulsecount value to gw in VAR1
double volume = ((double)pulseCount/((double)PULSE_FACTOR));
if (volume != oldvolume) {
oldvolume = volume;
Serial.print("volume:");
Serial.println(volume, 3);
gw.send(volumeMsg.set(volume, 3)); // Send volume value to gw
}
}
}
if (SLEEP_MODE) {
gw.sleep(SEND_FREQUENCY);
}
}
void incomingMessage(const MyMessage &message) {
if (message.type==V_VAR1) {
unsigned long gwPulseCount=message.getULong();
pulseCount += gwPulseCount;
Serial.print("Received last pulse count from gw:");
Serial.println(pulseCount);
pcReceived = true;
}
}
void onPulse()
{
if (!SLEEP_MODE)
{
unsigned long newBlink = micros();
unsigned long interval = newBlink-lastBlink;
if (interval!=0)
{
lastPulse = millis();
if (interval<500000L) {
// Sometimes we get interrupt on RISING, 500000 = 0.5sek debounce ( max 120 l/min)
return;
}
flow = (60000000.0 /interval) / ppl;
}
lastBlink = newBlink;
}
pulseCount++;
}
@the-cosmic-gate said:
So the pulse rule must be
double ppl = ((double)PULSE_FACTOR)/1
?
Is this correct when I change this rule as above?
So the pulse rule must be
double ppl = ((double)PULSE_FACTOR)/1
?
@Yveaux said:
@the-cosmic-gate ok, don't worry, I'll believe you
Probably the meter itself generates more pulse during rotation then.
I think so , but with this movie "we" can think about the pulse per L
I will make a movie to show you the meter / pulse detection (led blinks) etc.
So you can see that there are luckily more pulses to measure
@sincze said:
@the-cosmic-gate great stuff on more from the 'local' area. 10 minutes away.. Mmm Teteringen???
hahah almost : Etten-Leur / Hoeven ( i drive a bit faster then normal )
This is the log when i used %blinds in Domoticz
send: 1-1-0-0 s=10,c=2,t=3,pt=0,l=0,sg=0,st=fail:
read: 0-0-1 s=10,c=1,t=29,pt=0,l=0,sg=0:
Servo UP command
send: 1-1-0-0 s=10,c=1,t=3,pt=2,l=2,sg=0,st=ok:100
read: 0-0-1 s=10,c=1,t=30,pt=0,l=0,sg=0:
Servo DOWN command
send: 1-1-0-0 s=10,c=1,t=3,pt=2,l=2,sg=0,st=ok:0
This is the log when set to dimmer %
read: 0-0-1 s=10,c=1,t=29,pt=0,l=0,sg=0:
Servo UP command
send: 1-1-0-0 s=10,c=1,t=3,pt=2,l=2,sg=0,st=ok:100
read: 0-0-1 s=10,c=1,t=30,pt=0,l=0,sg=0:
Servo DOWN command
send: 1-1-0-0 s=10,c=1,t=3,pt=2,l=2,sg=0,st=ok:0
read: 0-0-1 s=10,c=1,t=29,pt=0,l=0,sg=0:
Servo UP command
send: 1-1-0-0 s=10,c=1,t=3,pt=2,l=2,sg=0,st=ok:100
read: 0-0-1 s=10,c=1,t=30,pt=0,l=0,sg=0:
Servo DOWN command
send: 1-1-0-0 s=10,c=1,t=3,pt=2,l=2,sg=0,st=ok:0```
The % bar doesnt function at all , cant use them
only on/off ( 0 - 100% ) works
Busy using / building a sensor like :
The sensor ( inductive) i use :LJ12A3-4-Z/BY as seen on the picture.
I use the standaard water sensor sketch as found mysensors water sensor
When i tested everything it seems to work together with domoticz ( after i changed this bij "hand" to: water).
But how to find out about the pulses , or how to calculate this ?
By default in the sketch it says:
double ppl = ((double)PULSE_FACTOR)/1000; // Pulses per liter
But i want to know if this i right (or not)
And the next thing to think about because this sensors is 10cm from the mysensors gateway : is it possible to connect this to the gateway so i dont have to build/use the extra arduino and radio as used now .
Short: is it possible to combine this watersensor sketch with the gateway sketch and aruindo + RF radio
@Yveaux said:
@the-cosmic-gate great! Hardware designs are always appreciated
Don't forget to register upfront BTW!
Sure, and it's @CM i read .... ( NAC Breda sponsor )
The idea is that some people who designed some open hardeware PCB's like @GertSanders en off course @TheoL can bring or show there hardware .
And people can buy it for example
COOOOOL just 10 min driving for me !And maybe can arrange some people to take some home made (open-hardware) PCB's
Then it should be faster/ easier to order some working/ approved screens for some quick solution, and take some extra time to get this screens team work
@alexsh1 said:
@the-cosmic-gate said:
https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code/tree/master/SWTFT-Shield
You do not need any sketches for now. Did you identify the chip model and number? I would suggest you go on Arduino forum and start reading about it - there are many threads over there depending on your screen make and model. You need to get the correct
pinout diagram and library, which you may need to correct.I did spent a few days trying to make a cheap Aliexpress TFT screen work. It took me hours and hours. That screen was returned and now I have the screen from Itead Studio guys. It works like a charm as all pins are standard, i.e. used by libraries like UTFT.
Additionally, you may want to try this library:
https://forum.arduino.cc/index.php?topic=366304.0There are some example sketches included including a possible screen pinout.
yesterday late in the evening got this lib ( https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code/tree/master/SWTFT-Shield ) running, and displayed the rotation and graphic test ( touch doesn't work :S )
Try to find out the right pin's for this mysensors scene controller
anybody who's got a complete kit for sale ? Want to test build one (single relay is enough)
(or maybe nicer: a 3in1 solution : Motion detection , relais , DHT of other temp sensor)
@mfalkvidd said:
All screens can be used with enough effort. I got a screen working that needed 20 pins, see https://forum.mysensors.org/topic/3438/physical-mood-light-color-and-brightness-selector-based-on-lcd-touchscreen-with-demo-video/
I think the screen in the MySensors store is an ili9341, which should support spi which means you can use 4 pins to connect it. http://www.aliexpress.com/item/2-4-inch-LCD-module-SPI-serial-module-2-4-inch-TFT-module-ILI9341-only-9/32526066165.html might be a better choice since it says which screen it is.
You can move the radio by using softspi, see https://www.mysensors.org/build/ethernet_gateway for instructions on how to do that.
i own one of these 2.4" aliexpress screens and trying to get this work with mysensors.
But at the moment without any result . Could you share the sketch you uses and works ?
Got the screen running using : this test lib: https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code/tree/master/SWTFT-Shield
It seems to be that some pin's must be changed , but on the 2.4 inch display this :
are not direct on this display visible , what are these
@AWI said:
@the-cosmic-gate you should set it to dimmer or "blinds %" in Domoticz. That is how domoticz works. Then look at the serial port of the node if changes come in.
That's exactly what I did but the %slide doesn't do anything.
@mfalkvidd said:
That's already how the sketch works. It presents itself as a dimmer which can be set to any %. What is the result when you set the level to 10%?
In domoticz it presents as a switch. When I change this switch to a dimmer or % blind it doesn't react. When set it back to blind control it works (only on / off)
I installed a digital servo and used the default sketch.
But i want to use some % , to control the blind .
For example when the sun i shining : fully close, and when the sun i shining a bit i want to close the blinds for 10 % .
How to do this in this sketch : default
i just recieved the voltage regulator and tried it without result
The LED light i;'ve got lphilips InStyle
In the spec's i read that i have to use for dimming : phase cutting dimmers , that's something different the PWM i think ;S ?
Is there oneother solution i can try / use ?
@TheoL said:
I fried a ProMini 3.3V while putting 12V on the raw pin. I suggest you add some power regulator and feed the Arduino with no more than 9V. Better safe than sorry.
I'm lucky I can still feed the ProMini throught the FDTI pins, but it's not ideally.
aaai frying one would cost you €5 i already ordered some power regulators to set the input on this raw ports.
But the re-think the design a bit
@sundberg84 said:
@the-cosmic-gate said:
But maybe the arduino input on the RAW ports ?
I think i need some Step Down dc-dc convertor for thisYes - you do. Ardunio can handle 12v on raw (in best cases - clones can fry).
Thnx , thnx the layout would be different. Because the LEDs needs 48v
But maybe the arduino input on the RAW ports ?
I think i need some Step Down dc-dc convertor for this
Want to use this circuit ( https://www.mysensors.org/build/dimmer) for dimming the Philips LED we have above the table. But the 230 adapter they use gives an output at 42 V . Whats the easiest way to use this "sensors" with this Philips LED light ?
i'am back in business after the "big move" and going to try again to get this 4:1 sensor working for a long time uning 2 x AA batteries.
If someone has some new input, please let me know and feel free to change the sketch
@TheoL said:
@the-cosmic-gate Great! And you're also good with a soldering iron. I don't think I could replace an SMD resistor
i didn't solder the SMD just replaced the whole radio much more easy
btw: congratz
problem solved issue : soma bad soldered resistor on the (china) NRF24L01+.
After i replaced the radio on the gateway
send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok: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=ok:Light Lux Sensor
send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
send: 1-1-0-0 s=0,c=0,t=16,pt=0,l=0,sg=0,st=ok:
54612
send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,sg=0,st=ok:54612
send: 1-1-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok: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=ok:Light Lux Sensor
send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
send: 1-1-0-0 s=0,c=0,t=16,pt=0,l=0,sg=0,st=ok:
0```
@TheoL said:
Stupid question. But have you checked if the gateway is up and running?
Gateway log says: ok
Hmm maybe check the soldering etc
0;0;3;0;9;gateway started, id=0, parent=0, distance=0
0;0;3;0;14;Gateway startup complete.
to be honest this is the one and only sensors we connected now so i dont now what the others will tell
fot now i changes the radio already and check the capacitor , but still fails ?
After we moved to oneother different house , is started the mysensors again.The lux sensors give this error ```
send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,st=fail:102
@carlierd said:
I just finished my first motion sensor node and the power consumption in idle is about 75uA. Could be better but not too bad
The only thing is that the range is a little bit low for good detection. It's between 1 and 3 meters ...David.
Hello David
Could you share what and how ?
Thnx
@carlierd said:
@the-cosmic-gate Did you solved your power consumption issue ?
Not yet, this because we moved to oneother house and didn't have the time now .
Also i had to disconnect and reconect all te sensors and domotica in this new house
@Brijesh-Mishra said:
@the-cosmic-gate, greetings to you. Kindly let me know, is there any issue with the component placement in the board. Not sure why it's not working :(.
Thanks
Brijesh
There absolutely nothing wrong, but I want to use the ESP8266 to build in instead of the arduino and 2.4 ghz radio (the ESP8266 is an Arduino incl WiFi) so the PCB can be much smaller I think.
@icebob said:
@the-cosmic-gate sorry, I'm working a big complex sketch, I can't share my code currently.
Big and complex sounds interesting
Could you maybe share us a sneak peak
Could I ask to the smart PCB builder's / designers to make the same 230v PCB but not using an Arduino but one of the ESP8266 versions , the the board could be even smaller and easier to fix in the wholes
@carlierd said:
Hello,
You need to power the motion sensor all time as you want to detect any mouvement and not only every 2 minutes.
Caution, in your sketch, the battery level is sent at the beginning and at the end.
Did you tweak the motion sensor ?? Not tested yet but it seems that modification could (must ?) be done to reduce power consumption (LINK).
Why do you wake-up the arduino every 30 seconds ? For temperature, every 5 or 15 minutes is enough.
Sure i modded the motion sensor as shown in the hyperlink , modded it this way :
I don't know why i wake-up this arduino every 30 seconds, the sketch was fabricated by combine 2 or 3 other sketches to this one ( with help from @AWI )
So if there are some tweaking thing to do, do not hesitate and change the sketch as you think it must be
@icebob what's the sketch you using /testing ?
@carlierd said:
Hello,
Did you measured the current of your circuit ?
What motion sensor are you using ? This component may consume a lot of current. Did you check this post ?If you wake-up the arduino every 30 seconds for measurement it's a problem. Every 5 minutes is the minimum I think. I have connected the Vcc pin of the DHT sensors and the Vcc of the LDR to a digital pin of the arduino and when a measurement is done I set the PIN to the HIGH state.
First measurement of my sensor gives an IDLE current consumption close to 5uA which is really correct according to elements connected to the arduino (RFM69HW, DHT22 and LDR).
David.
Hello David,
I tried to meassure , but didn't have the right stuff to do this good enough.
The parts i use for this "project": DHT-22 (connected to D4), HC-SR501 (connected to D3)and connected to the 3.3V pin post , the VVC is connected to the VVC of the arduino pro mini 8 Mhz /3.3 V .
And use the sketch as above:
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
#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 = 30000UL; // Sleep time between reads (in milliseconds)
int oldBatteryPcnt = 0;
MySensor gw;
DHT dht;
float lastTemp = 0 ;
float lastHum = 0 ;
boolean lastTripped = false ;
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()
{
// use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
analogReference(INTERNAL1V1);
#else
analogReference(INTERNAL);
#endif
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()
{
// get the battery Voltage
int sensorValue = analogRead(BATTERY_SENSE_PIN);
#ifdef DEBUG
Serial.println(sensorValue);
#endif
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
// 3.44/1023 = Volts per bit = 0.003363075
float batteryV = sensorValue * 0.003363075;
int batteryPcnt = sensorValue / 10;
#ifdef DEBUG
Serial.print("Battery Voltage: ");
Serial.print(batteryV);
Serial.println(" V");
Serial.print("Battery percent: ");
Serial.print(batteryPcnt);
Serial.println(" %");
#endif
if (oldBatteryPcnt != batteryPcnt) {
// Power up radio after sleep
gw.sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}
// Read digital motion value
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
if (tripped != lastTripped ) {
Serial.println(tripped);
gw.send(msgMot.set(tripped?"1":"0")); // Send tripped value to gw
}
delay(dht.getMinimumSamplingPeriod());
float temperature = dht.getTemperature();
float humidity = dht.getHumidity();
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);
}
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);
}
if (oldBatteryPcnt != batteryPcnt) {
// Power up radio after sleep
gw.sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
}
So how do you connect the DHT / SR501 to the digital pin, and what's the sketch you're using ?
Running the sketch for 1 Monty (+-), and the AA batteries are dead empty ?
I did all the "possible" mods on the arduino ( cut the LED an V ) , what can i do to make this sketch run langer on this 2AA batteries ?
Something in the sketch , some fine tuning or something else ?
When read the arduino hardware tweaking topics on different forums they dat that running for 1 year ( and more) is possible but how ;-)?
@aproxx said:
For those who wanted to see some pictures of the board:
Small notice: These pictures are of a slightly older design. The newer design has a few minor changes like better component placement and a permanent fuse instead of this resettable fuse. But these pictures should at least give you an idea on how everything looks like, and shows how really small it actually is.
Also, I reinforced the traces of the 230v lines, which I absolutely recommend to do! (Although I do recommend to do it slightly more professional than I did on this prototype :))
I really like this design, but it would be even nicer when this fits a ESP8266 Maybe the PCB could be even smaller . And it works together with link text .
So is there maybe one of the PCB designer guys who can build /draw / design this 230v to ESP8266 PCB ?
Something strange: when I look in the IDE console the battery % is displayed. But using Domoticz there's no battery % display / selectable ? What's wrong , or do I forget something ?
working nice for 2 day's now !
Thnx a lot @AWI !!!
Thnx a lot @AWI
there was 1 verification error,
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN. DHT22);
changed it, to :
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
#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 = 30000UL; // Sleep time between reads (in milliseconds)
int oldBatteryPcnt = 0;
MySensor gw;
DHT dht;
float lastTemp = 0 ;
float lastHum = 0 ;
boolean lastTripped = false ;
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()
{
// use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
analogReference(INTERNAL1V1);
#else
analogReference(INTERNAL);
#endif
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()
{
// get the battery Voltage
int sensorValue = analogRead(BATTERY_SENSE_PIN);
#ifdef DEBUG
Serial.println(sensorValue);
#endif
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
// 3.44/1023 = Volts per bit = 0.003363075
float batteryV = sensorValue * 0.003363075;
int batteryPcnt = sensorValue / 10;
#ifdef DEBUG
Serial.print("Battery Voltage: ");
Serial.print(batteryV);
Serial.println(" V");
Serial.print("Battery percent: ");
Serial.print(batteryPcnt);
Serial.println(" %");
#endif
if (oldBatteryPcnt != batteryPcnt) {
// Power up radio after sleep
gw.sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}
// Read digital motion value
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
if (tripped != lastTripped ) {
Serial.println(tripped);
gw.send(msgMot.set(tripped?"1":"0")); // Send tripped value to gw
}
delay(dht.getMinimumSamplingPeriod());
float temperature = dht.getTemperature();
float humidity = dht.getHumidity();
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);
}
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);
}
if (oldBatteryPcnt != batteryPcnt) {
// Power up radio after sleep
gw.sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
}
uploading now
I'am not getting this clear / working
Could somebody help me to complete this 3in1 incl battery monitoring sketch working? Thnx
@sundberg84 said:
Dont know if im answring the question (or i understand it)...
Do you mean @AWI that if you put the gw.*** together?gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 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);
put all the gw. *** together it will not cause the radio be on during DHT setup and readings like:
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input gw.begin(); // 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);
Now I'am getting confused
The thing i want to do is to make this 3in1 sketch , an 4 in 1 where the 4th is the battery sensors.
When i copy and paste this sketches together, i want to arrange one sketch who can run als long as possible on 2xAA batteries.
So if there are some tricks to make this sketch more battery friendle, so it runs longer on this 2 AA then it try to arrange is.
So As @AWI said i'll removed all the gw.send instructions, which gives me the result that the mysensors function is gone.
Then i tried again and put all the gw.send instructions "together".
But when i read you're reactien @sundberg84 this is not okay, or are there even more options to combine rules to make the sketch more battery friendly ?
Thnx for all the input
So the code "must" be
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
#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)
int oldBatteryPcnt = 0;
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()
{
// use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
analogReference(INTERNAL1V1);
#else
analogReference(INTERNAL);
#endif
gw.begin();
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
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()
{
// get the battery Voltage
int sensorValue = analogRead(BATTERY_SENSE_PIN);
#ifdef DEBUG
Serial.println(sensorValue);
#endif
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
// 3.44/1023 = Volts per bit = 0.003363075
float batteryV = sensorValue * 0.003363075;
int batteryPcnt = sensorValue / 10;
#ifdef DEBUG
Serial.print("Battery Voltage: ");
Serial.print(batteryV);
Serial.println(" V");
Serial.print("Battery percent: ");
Serial.print(batteryPcnt);
Serial.println(" %");
#endif
if (oldBatteryPcnt != batteryPcnt) {
}
// Read digital motion value
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
Serial.println(tripped);
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);
}
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));
gw.send(msgMot.set(tripped?"1":"0"));
gw.sendSketchInfo("Humidity/Motion", "1.0");
gw.sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
Serial.print("H: ");
Serial.println(humidity);
gw.send(msgTemp.set(temperature, 1));
}
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
}
@AWI
If i remove the (gw.send) action, the code would be
#include <MySensor.h>
#include <DHT.h>
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
#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)
int oldBatteryPcnt = 0;
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()
{
// use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
analogReference(INTERNAL1V1);
#else
analogReference(INTERNAL);
#endif
gw.begin();
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Send the Sketch Version Information to the Gateway
SketchInfo("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()
{
// get the battery Voltage
int sensorValue = analogRead(BATTERY_SENSE_PIN);
#ifdef DEBUG
Serial.println(sensorValue);
#endif
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
// 3.44/1023 = Volts per bit = 0.003363075
float batteryV = sensorValue * 0.003363075;
int batteryPcnt = sensorValue / 10;
#ifdef DEBUG
Serial.print("Battery Voltage: ");
Serial.print(batteryV);
Serial.println(" V");
Serial.print("Battery percent: ");
Serial.print(batteryPcnt);
Serial.println(" %");
#endif
if (oldBatteryPcnt != batteryPcnt) {
// Power up radio after sleep
BatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}
// Read digital motion value
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
Serial.println(tripped);
(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);
}
(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;
(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);
}
i would like to test this RGWB also, are the PCB gerber files available ?
I also moded the arduino pro mini 8 Mhz like : http://www.mysensors.org/build/battery
are there more (sketch) mod's possible to make it run as long as possible on 2 x AA
I'am trying to build some 3 in 1 ( motion / temp / hum ) incl. battery monitor .
At the moment i try to combine these sketches , as result
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
#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)
int oldBatteryPcnt = 0;
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()
{
// use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
analogReference(INTERNAL1V1);
#else
analogReference(INTERNAL);
#endif
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()
{
// get the battery Voltage
int sensorValue = analogRead(BATTERY_SENSE_PIN);
#ifdef DEBUG
Serial.println(sensorValue);
#endif
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
// 3.44/1023 = Volts per bit = 0.003363075
float batteryV = sensorValue * 0.003363075;
int batteryPcnt = sensorValue / 10;
#ifdef DEBUG
Serial.print("Battery Voltage: ");
Serial.print(batteryV);
Serial.println(" V");
Serial.print("Battery percent: ");
Serial.print(batteryPcnt);
Serial.println(" %");
#endif
if (oldBatteryPcnt != batteryPcnt) {
// Power up radio after sleep
gw.sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}
// 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);
}
Would this work ? ( sketch verification is okay )