Merry Christmas!!!
You're doing a really great job and I hope to do some cool projects with MySensors!
Best posts made by iahim67
-
RE: Merry X-mas and Happy New 2018
-
RE: Unknown battery drain
@Richard-van-der-Plas - you can use any Arduino Mini or Mini Pro for a battery powered sensor.
It does not matter much if you buy a 5V or a 3V3 Mini Pro version as you will better flash an internal 8MHz bootloader, remove the linear voltage regulator on these boards and the LED or LEDs as well. I use battery powered temperature sensors (with thermistors)since November 2017 and they still work fine -> I use 2xR6 batteries. Things you can do (like I did, after lots of reading on this forum):- important! remove the LDO (the low drop output voltage regulator) equipped on the Arduinos
- remove the LED or LEDs
- flash an 8MHz internal oscillator bootloader (I read in this forum that using 1MHz internal osc. may give you occasional faults, don't know if that is still valid!) - do you know how to do that?
- internal 8MHz could be precise enough to work with your Dallas temperature sensors, I'm not sure without checking the datasheet
- an 8MHz Arduino (ATMega328P in this case) can work down to about 2V4 according to the datasheet, while the radio works down to 1V9
- either use 2 x R6 batteries to power both the Arduino and the radio module
- or use 3 xR6 batteries to power the Arduino BUT (important!) get power for the radio only from two of the R6 batteries or you'll damage it
- I bought battery powered Christmas lights from LIDL and Kaufland, they had very cheap Christmas lights with both 2 and 3 R6 batteries - so I just use the very convenient battery plastic housing equipped with an ON/OFF switch. Or just look for some R6 or AAA battery holders ...
- make sure you connect the Ground of both the Arduino and the Radio to the "-" of the battery string
- NiMH rechargeable batteries have a much higher self discharge rate than alkaline non rechargeable batteries, NiMH would not be a good option to me as I would have to replace them quite often, but may fit your needs:-)
- ATMega328P can measure its internal 1V1 reference and by doing that you can calculate the battery voltage without a resistor divider that would drain a few more uA, use this library:
https://forum.mysensors.org/topic/186/new-library-to-read-arduino-vcc-supply-level-without-resistors-for-battery-powered-sensor-nodes-that-do-not-use-a-voltage-regulator-but-connect-directly-to-the-batteries - you can use thermistors to measure the temperature as they are very cheap and most important - you can power the thermistor from an Arduino pin by making it an OUTPUT and set it HIGH. After reading the temperature set it back to LOW and put the Arduino to sleep. You will conserve even more power this way. Hope it helps ...
- forgot to clarify, you are supposed to connect the "+" of the battery string to the 5V pin header on the Arduino (there are 2 such pins I think), not to the RAW pin header. 5V can be anything between 2V4 and 5V (for an 8MHz Arduino) and goes directly to the ATMega VCC pin while RAW connector goes to the input of the Linear Voltage Regulator you are supposed to remove
- while looking to your code I can see you have many delay() lines which means your Arduino is awake for many seconds, that's just not good enough for a battery powered sensor :-), try to remove these delays as much as possible, use different sensors that do not require delays eventually as the Arduino should be mostly sleeping. Use eventually a
#define DEBUG x
statement (x=1 if you like to have a serial debug output or x=0 if you don't) and only output the Serial.print when needed.Here is an example for a temperature sensor with a thermistor and 2xR6 batteries (not using here the VCC library I mentioned before but something similar):
// Enable debug prints to serial monitor //#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_NODE_ID 10 #define DEBUG 0 #define BATTERY_SENSOR 1 #include <MySensors.h> #define TH1_CHILD_ID 11 #define VOLTAGE_CHILD_ID 12 #define TH_PIN 3 int _nominal_resistor = 4700; int _nominal_temperature = 25; int _b_coefficient = 3950; int _series_resistor = 4877; int _pin = 0; float BatteryMin = 2.4; float BatteryMax = 3.0; MyMessage msgTemp(TH1_CHILD_ID, V_TEMP); MyMessage msgVoltage(VOLTAGE_CHILD_ID, V_VOLTAGE); void setup() { //Serial.begin(115200); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("TH1_Mini_2xR6", "1.0"); present(TH1_CHILD_ID, S_TEMP, "TH1"); present(VOLTAGE_CHILD_ID, S_MULTIMETER, "TH1_Batt_Voltage"); } void loop() { tempReport(); batteryReport(); sleep(180000); } // Measure VCC float getVcc() { #ifndef MY_GATEWAY_ESP8266 // Measure Vcc against 1.1V Vref #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = (_BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1)); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = (_BV(MUX5) | _BV(MUX0)); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = (_BV(MUX3) | _BV(MUX2)); #else ADMUX = (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1)); #endif // Vref settle wait(70); // Do conversion ADCSRA |= _BV(ADSC); while (bit_is_set(ADCSRA, ADSC)) {}; // return Vcc in mV return (float)((1125300UL) / ADC) / 1000; #else return (float)0; #endif } // Send a battery level report to the controller void batteryReport() { // measure the board vcc float volt = getVcc(); // calculate the percentage int percentage = ((volt - BatteryMin) / (BatteryMax - BatteryMin)) * 100; if (percentage > 100) percentage = 100; if (percentage < 0) percentage = 0; #if DEBUG == 1 Serial.print(F("BATT V=")); Serial.print(volt); Serial.print(F(" P=")); Serial.println(percentage); #endif #if BATTERY_SENSOR == 1 // report battery voltage send(msgVoltage.set(volt, 3)); #endif // report battery level percentage sendBatteryLevel(percentage); } void tempReport() { // set TH pin in output mode pinMode(TH_PIN, OUTPUT); // set TH_PIN HIGH digitalWrite(TH_PIN, HIGH); wait(1); // read the voltage across the thermistor float adc = analogRead(_pin); // set TH_PIN LOW digitalWrite(TH_PIN, LOW); // calculate the temperature float reading = (1023 / adc) - 1; reading = _series_resistor / reading; float temperature; temperature = reading / _nominal_resistor; // (R/Ro) temperature = log(temperature); // ln(R/Ro) temperature /= _b_coefficient; // 1/B * ln(R/Ro) temperature += 1.0 / (_nominal_temperature + 273.15); // + (1/To) temperature = 1.0 / temperature; // Invert temperature -= 273.15; // convert to C #if DEBUG == 1 Serial.print(F("THER I=")); Serial.print(TH1_CHILD_ID); Serial.print(F(" V=")); Serial.print(adc); Serial.print(F(" T=")); Serial.println(temperature); #endif send(msgTemp.set(temperature, 1)); }```
-
RE: Garage door status sensors ideas
Hi, maybe you can use the reed switch in a different way, I mean do not use it like contact closed or contact opened as this would cause you overshoot issues.
When the magnet attached to the door slides in front of the reed switch, then you'll have the reed switch closed for a short time at least, most likely, you can test that. You can use the reed just like you would use a motion detector.
I mean connect the reed to pin 3 - interrupt - and put this at the end of your code, so when an interrupt occurs you will know the door has moved (and you can keep track of movement of course so you would know if the door is open or close) ... just an idea ... :sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
-
RE: 💬 Door, Window and Push-button Sensor
Perhaps it would be good to update the example code. I mean the pull-up sequence:
"It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor." - https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/
The following seems to be obsolete:
// Setup the button
pinMode(BUTTON_PIN,INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH);