Navigation

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

    HenryWhite

    @HenryWhite

    24
    Reputation
    103
    Posts
    903
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    HenryWhite Follow

    Best posts made by HenryWhite

    • Rechargeable Lithium Ion Sensor Custom PCB

      Hi!
      Since a bunch of people already made a custom MySensors PCB, I decided to get used to Eagle and create my own board to fit my needs 😃
      The key difference compared to other custom PCBs is the Lithium Ion Charging Circuit with micro USB connector. So you can just grab a flat smartphone battery with 1000 mAh or more and stick it under the PCB! This way you never have to worry about changing batteries, and even if your configuration consumes a lot of power, you can quickly recharge your sensor through the micro USB connector of the Li-Ion Charging Module.

      The board is currently only designed to work with the Arduino Pro Mini 3.3V version.

      Version 0.1 is tested, I received the PCBs on 01/26/2016. Everything works fine (good radio range), there is only one little problem with the connection of the battery (but it is fixable; see post 52 in this thread for a fix)

      So here are the specifications and features of my board:

      • designed for cheap 3.3V Arduino Pro mini clones from china, for example this one
      • 5x5cm
      • uses jumper bridge to simply connect and disconnect the battery
      • easy attaching of motion sensor (use 3.3V mod), DHT22 for Temp and Humidity Measurement and one switch (for example button- or reedswitch)
      • small prototyping area on the backside
      • uses TP4056 Li-Ion single cell Micro USB 1A charging circuit with battery protection (disconnects the power automatically if voltage drops below 2.4V
        ------> make sure you get the NEW version of the TP4056 with battery protection circuit!
        remember to charge your li-ion 1-cell rechargeable battery with maximum 1C, so if you want to use a battery below 1000 mAh you need to make modifications to the module or the charging current will be way to high, which could result in an explosion (worst case)
      • I suggest to use the board with a smartphone battery, as they usually are very small and flat and have a high capacity for small money. I will use the galaxy s4 battery because it fits nearly perfect under the board and has 2600 mAh.
      • Now with additional relay, properly connected using 2N2222A transistor, flyback diode, 1kΩ resistor and terminal block for easy attaching of "switchable things" to the relay

      Schematics (Rev 1.0)
      0_1453762885667_schematics_v1.0.png

      Board view (Rev 1.0)
      0_1453762894187_board_v1.0.png
      3D board view (Rev 1.0)
      0_1453762899960_3dview_v1.0.png

      Build files

      Rev 1.0:

      • Now with additional relay, properly connected using 2N2222A transistor, flyback diode, 1kΩ resistor and terminal block for easy attaching of "switchable things" to the relay
      • proper alignment of DHT22

      Eagle files: 0_1453762986505_Sensorboard_v1.0.zip
      Gerber files: 0_1453763061782_Sensorboard_v1.0_Gerber.zip

      Rev 0.3: swapped footprints of DHT22 and prototyping area to prevent false temp measurements when charging the battery; connected TP4056 OUT to arduino's RAW instead of VCC_IN (so the internal voltage regulator is used)
      sensorboard_v0.3.sch
      sensorboard_v0.3.brd

      Rev 0.2: added footprint for 47uF SMD capacitor standard 1210 (i guess many other smd caps will fit too)
      sensorboard_v0.2.sch
      sensorboard_v0.2.brd

      Rev. 0.1
      untitled.sch untitled.brd

      posted in Hardware
      HenryWhite
      HenryWhite
    • Multiple Relays + Motion sketch, fully customizable, optional timer, manual override

      Hi!

      I recently modified the relay example sketch so that it fits my needs; maybe some of you can make use of my little work too.

      Here's what you can do / what the features are:

      • Easily add as much Relays / FETs as you want (or as much as the arduino allows) by entering the according pin numbers in the RELAYS[ ]-Array
      • You can trigger each relay from your controller
      • You can add a motion sensor and specify which (MOTION_ACTIVATED_RELAYS[ ]) of your relays should be triggered through motion and for how long (ON_TIMES[ ])
      • The state of the motion sensor will be reported to your controller
      • When a relay is changed through motion, the change will also be reported to your controller
      • You can send a manual override from your controller, so that the motion will still be reported, but none of the relays will be triggered through motion
      /**
         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
         Version 1.1 - HenryWhite
      
         DESCRIPTION
         Example sketch showing how to control physical relays.
         This example will remember relay state after power failure.
         Optional attachment of motion sensor to control the relays is possible.
         Notes:
            -- The Child-IDs of the attached relays range from 1 up to (1-(NUMBER_OF_RELAYS))
            -- Make sure to adjust the potentiometer for triggertime on your motion sensor as leftmost as possible,
               because the countdown will not start until the motion sensor reports back a "0" (no movement)
      
      */
      
      //----------------------- Library Configuration ---------------------
      //#define MY_DEBUG                          // uncomment to enable debug prints to serial monitor
      //#define MY_REPEATER_FEATURE               // uncomment to enable repeater functionality for this node
      //#define MY_NODE_ID 20                     // uncomment to define static node ID
      
      // Enable and uncomment attached radio type
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      //#define MY_TRANSPORT_WAIT_READY_MS 1      // uncomment this to enter the loop() and setup()-function even when the node cannot be registered to gw
      
      //----------------------- Relay and Motion Sensor Configuration -----------------------
      #define MOTION                                                    // un-comment to enable motion sensing
      #define NUMBER_OF_RELAYS  2                                       // Total number of attached relays. Must be equal to total number of elements in array below!
      const int RELAYS[]                  =     {3,  5};                // digital pins of attached relays
      const int MOTION_ACTIVATED_RELAYS[] =     {1,  0};                // 1 to trigger the relay through motion, 0 to not trigger. Array length must correspond to RELAYS[] array.
      const long ON_TIMES[]               =     {300, 0};               // Specify for each element in MOTION_ACTIVATED_RELAYS, how long the specified relay should be active in seconds.
      #define RELAY_ON          1                                       // GPIO value to write to turn on attached relay
      #define RELAY_OFF         0                                       // GPIO value to write to turn off attached relay
      #define MOTION_PIN        2                                       // The digital input pin of the motion sensor
      #define MOTION_CHILD_ID   0                                       // Set the child id of the motion sensor
      bool ack = 1;                                                     // set this to 1 if you want destination node to send ack back to this node
      
      //----------------------- DO NOT CHANGE -----------------------------
      #include <MySensors.h>
      MyMessage motion_msg(MOTION_CHILD_ID, V_TRIPPED);   // Initialize motion message
      unsigned long trigger_millis[NUMBER_OF_RELAYS];     // Used for the timer
      bool lastTripped = 0;                               // Used to store last motion sensor value
      bool manual_override = 0;                           // if this gets set to 1 (e.g. by a switch or a command from the gateway), motion triggering of relays is deactivated
      MyMessage relay_msg;                                // Initialize relay message
      
      void before()
      {
        int i;
        for (int sensor = 1, i = 0; sensor <= NUMBER_OF_RELAYS; sensor++, i++) {
          // set relay pins to output mode
          pinMode(RELAYS[i], OUTPUT);
          // Restore relay to last known state (using eeprom storage)
          digitalWrite(RELAYS[i], loadState(sensor) ? RELAY_ON : RELAY_OFF);
        }
        // set motion pin to output mode, if MOTION is defined
      #ifdef MOTION
        pinMode(MOTION_PIN, INPUT);
      #endif
      }
      
      void setup()
      {
      #ifdef MOTION
        // give the motion sensor some time to settle
        Serial.println("Starting up. Please wait 8 seconds...");
        delay(8000);
      #endif
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay/Motion", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        for (int sensor = 1; sensor <= NUMBER_OF_RELAYS; sensor++) {
          present(sensor, S_BINARY, "Relay", ack);
        }
      #ifdef MOTION
        present(MOTION_CHILD_ID, S_MOTION, "Motion Sensor", ack);
      #endif
      
      }
      
      void loop()
      {
      #ifdef MOTION
        if (!manual_override) {
          // Read digital motion value
          bool tripped = digitalRead(MOTION_PIN) == HIGH;
      
          if (lastTripped != tripped) {
            Serial.print("New Motion State: ");
            Serial.println(tripped);
            // Send tripped value to gw
            send(motion_msg.set(tripped ? "1" : "0"));
            lastTripped = tripped;
      
            // Change relay states, send new state to gw and store state in eeprom
            if (tripped == 1) {
              for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
                if (MOTION_ACTIVATED_RELAYS[i] == 1) {
                  digitalWrite(RELAYS[i], RELAY_ON);
                  relay_msg_constructor(i + 1, V_STATUS);
                  send(relay_msg.set(RELAY_ON));
                  trigger_millis[i] = millis();
                  Serial.print("Relay ");
                  Serial.print(RELAYS[i]);
                  Serial.println(" turned on");
                  saveState(i, 1);
                }
              }
            }
          }
      
          for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
            if (tripped == 1 and MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
              trigger_millis[i] = millis();
            }
            if ((trigger_millis[i] + ON_TIMES[i] * 1000 < millis()) and MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
              digitalWrite(RELAYS[i], RELAY_OFF);
              relay_msg_constructor(i + 1, V_STATUS);
              send(relay_msg.set(RELAY_OFF));
              Serial.print("Relay ");
              Serial.print(RELAYS[i]);
              Serial.println(" turned off");
              saveState(i, 0);
              trigger_millis[i] = 0;
            }
          }
        }
        else {
          bool tripped = digitalRead(MOTION_PIN) == HIGH;
          if (lastTripped != tripped) {
            Serial.print("New Motion State: ");
            Serial.println(tripped);
            // Send tripped value to gw
            send(motion_msg.set(tripped ? "1" : "0"));
            lastTripped = tripped;
          }
          for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
            if (MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
              trigger_millis[i] = 0;                            // reset running timers
            }
          }
        }
      #endif
      }
      
      void receive(const MyMessage &message)
      {
        // Handle incoming relay commands
        if (message.type == V_STATUS) {
          // Change relay state
          if (RELAYS[message.sensor - 1]) {
            digitalWrite(RELAYS[message.sensor - 1], message.getBool() ? RELAY_ON : RELAY_OFF);
      
            // Store state in eeprom
            saveState(message.sensor - 1, message.getBool());
            // Write some debug info
            Serial.print("Incoming change for sensor:");
            Serial.print(message.sensor);
            Serial.print(", New status: ");
            Serial.println(message.getBool());
          }
        }
      
        // Handle incoming manual override/bypass of motion sensor
        if (message.type == V_ARMED and message.sensor == 0) {
          manual_override = message.getBool();
          Serial.print("Manual Override: ");
          Serial.println(manual_override);
        }
      }
      
      void relay_msg_constructor(int sensor, uint8_t type)
      {
        relay_msg.setSensor(sensor);
        relay_msg.setType(type);
      }
      

      Additional Notes:

      • The Child-IDs of the attached relays range from 1 up to (1-(NUMBER_OF_RELAYS))
      • The default Child-ID for the motion sensor is 0
      • Make sure to adjust the potentiometer for triggertime on your motion sensor as leftmost as possible, because the countdown-timer will not start until the motion sensor reports back a "0" (no movement)
      posted in Development
      HenryWhite
      HenryWhite
    • RE: Which Lab Power Supply?

      Just buy a LTC3780 (link), exchange the pots, hook up a volt/amp display and there you have it: your own lab power supply which can deliver 1V-30V // 0A - 8A, 10A peak.

      Here's mine:
      0_1460195375382_dc166e28-4de7-4a10-b289-1d242d92bd00.jpg

      posted in Hardware
      HenryWhite
      HenryWhite
    • RE: German speaking members

      👍👍

      posted in General Discussion
      HenryWhite
      HenryWhite
    • RE: Multiple Relays + Motion sketch, fully customizable, optional timer, manual override

      @markjgabb said in Multiple Relays + Motion sketch, fully customizable, optional timer, manual override:

      awesome work...this sketch is brilliant....

      what happens if you retrigger motion before timer runs out?
      will it always handle a restart of the timer correctly?

      Yes, the timer will be reset.

      posted in Development
      HenryWhite
      HenryWhite
    • RE: Rechargeable Lithium Ion Sensor Custom PCB

      @mfalkvidd said:

      @HenryWhite said:

      Is there any reason the cap should be placed on the board instead of the nRF itself? If this is the case I could add footprints for a SMD cap under the nRF 👍

      Just to make soldering easier. I soldered 15 caps to 15 nRFs today so I'm a bit fed-up, that's all 🙂

      I think I will add a footprint for a SMD cap under the nRF, there's plenty of unused space anyway 😄

      posted in Hardware
      HenryWhite
      HenryWhite
    • RE: Battery powered smoke sensor

      Here's my try of mysensorizing a cheap smoke detector, including 3D-printed case:

      0_1471278811556_PHOTO_20160701_230656.jpg 0_1471278816749_PHOTO_20160701_230926.jpg 0_1471278818220_PHOTO_20160701_231031.jpg 0_1471278819351_PHOTO_20160815_182427.jpg

      Works flawlessly since 2 months ( I modified 3 smoke detectors at my home)
      The designed node can read and trigger the smoke detector. However, it currently runs in read-only mode because of the power issues when the node is active all the time.
      The next goal is to use the SmartSleep()-function of MySensors 2.0 with my Controller (OpenHAB), to realize reading&triggering of the smoke detector with a node's battery life of at least 6 months.

      If anyone knows details on how to implement the SmartSleep-Function, I would really appreciate some information!

      posted in General Discussion
      HenryWhite
      HenryWhite
    • RE: Is Raspberry a Solid Controller?

      I can only speak from OpenHAB, but the New raspberry 2 should have enough computation power.
      If you want to store the operating system on an sd card, be prepared to buy every few months (or year, depending on writing activity on the card) a new sd card.

      It's way better to install the Controller Software on a hdd or ssd. You can modify the raspberry to use a hard drive instead of the sd card.

      posted in Domoticz
      HenryWhite
      HenryWhite
    • RE: [SOLVED] No Serial prints for loop(), using MySensors 2.1.1

      @korttoma thanks! It works now. 🙂
      Could have saved me hours of troubleshooting if I knew that prior 😕

      posted in Troubleshooting
      HenryWhite
      HenryWhite
    • RE: Rechargeable Lithium Ion Sensor Custom PCB

      @AWI: I will think about it

      @Heizelmann said:

      I think, on Rev 0.2 the download link for the board is wrong, it is the same as for Rev 0.1.

      I think it is also imported that the antenna will not be covered by the shield pcb (see http://forum.mysensors.org/topic/1109/sensor-shield-for-arduino-pro-mini-3-3v-with-boost-up-regulator)

      yeah the link is the same, i will update it. Did you made measurements to compare the range of the nRF when mounted onto the board and mounted sticking out? I'm not sure but I don't think this would make any difference, as there are no routes under the antenna or even a ground fill on the board.

      posted in Hardware
      HenryWhite
      HenryWhite

    Latest posts made by HenryWhite

    • RE: 💬 Relay

      @mfalkvidd when updating the example sketch you could maybe consider my version of the relay sketch which offers some nice additions: https://forum.mysensors.org/topic/6638/multiple-relays-motion-sketch-fully-customizable-optional-timer-manual-override

      posted in Announcements
      HenryWhite
      HenryWhite
    • RE: Mains voltage current sensor?

      @maghac said in Mains voltage current sensor?:

      so I can sense when they're done and alert someone to go empty them.

      If you just want to do that, you could also use a vibration sensor to determine whether the dryer/ washing machine has finished or not.

      posted in Hardware
      HenryWhite
      HenryWhite
    • RE: Multiple Relays + Motion sketch, fully customizable, optional timer, manual override

      @AndreD said in Multiple Relays + Motion sketch, fully customizable, optional timer, manual override:

      How to send the relay to the gateway every 30 seconds?

      Why would you need that?

      posted in Development
      HenryWhite
      HenryWhite
    • RE: 💬 Relay

      @Rene046 you could try my sketch: https://forum.mysensors.org/topic/6638/multiple-relays-motion-sketch-fully-customizable-optional-timer-manual-override

      posted in Announcements
      HenryWhite
      HenryWhite
    • RE: Sensor dht+relay won't send data or present

      @MasMat said in Sensor dht+relay won't send data or present:

      @gohan you mean "delay(500)"? Will that not affect the radio function if it is waiting for a command for the relay for example?

      That's what wait() is for (mysensors specific) , it will not interfere with the radio commumication.

      posted in Troubleshooting
      HenryWhite
      HenryWhite
    • RE: nRF24L01+ and without +. arduino pro micro?

      @slowbo here you can find the documentation: https://www.mysensors.org/download/sensor_api_20
      There's also a list of all available config options.

      posted in Troubleshooting
      HenryWhite
      HenryWhite
    • RE: Multiple Relays + Motion sketch, fully customizable, optional timer, manual override

      @markjgabb said in Multiple Relays + Motion sketch, fully customizable, optional timer, manual override:

      awesome work...this sketch is brilliant....

      what happens if you retrigger motion before timer runs out?
      will it always handle a restart of the timer correctly?

      Yes, the timer will be reset.

      posted in Development
      HenryWhite
      HenryWhite
    • RE: motion sensor and 2 relay code

      I finalized my sketch, you can find it here: https://forum.mysensors.org/topic/6638/multiple-relays-motion-sketch-fully-customizable-optional-timer-manual-override

      posted in Troubleshooting
      HenryWhite
      HenryWhite
    • Multiple Relays + Motion sketch, fully customizable, optional timer, manual override

      Hi!

      I recently modified the relay example sketch so that it fits my needs; maybe some of you can make use of my little work too.

      Here's what you can do / what the features are:

      • Easily add as much Relays / FETs as you want (or as much as the arduino allows) by entering the according pin numbers in the RELAYS[ ]-Array
      • You can trigger each relay from your controller
      • You can add a motion sensor and specify which (MOTION_ACTIVATED_RELAYS[ ]) of your relays should be triggered through motion and for how long (ON_TIMES[ ])
      • The state of the motion sensor will be reported to your controller
      • When a relay is changed through motion, the change will also be reported to your controller
      • You can send a manual override from your controller, so that the motion will still be reported, but none of the relays will be triggered through motion
      /**
         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
         Version 1.1 - HenryWhite
      
         DESCRIPTION
         Example sketch showing how to control physical relays.
         This example will remember relay state after power failure.
         Optional attachment of motion sensor to control the relays is possible.
         Notes:
            -- The Child-IDs of the attached relays range from 1 up to (1-(NUMBER_OF_RELAYS))
            -- Make sure to adjust the potentiometer for triggertime on your motion sensor as leftmost as possible,
               because the countdown will not start until the motion sensor reports back a "0" (no movement)
      
      */
      
      //----------------------- Library Configuration ---------------------
      //#define MY_DEBUG                          // uncomment to enable debug prints to serial monitor
      //#define MY_REPEATER_FEATURE               // uncomment to enable repeater functionality for this node
      //#define MY_NODE_ID 20                     // uncomment to define static node ID
      
      // Enable and uncomment attached radio type
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      //#define MY_TRANSPORT_WAIT_READY_MS 1      // uncomment this to enter the loop() and setup()-function even when the node cannot be registered to gw
      
      //----------------------- Relay and Motion Sensor Configuration -----------------------
      #define MOTION                                                    // un-comment to enable motion sensing
      #define NUMBER_OF_RELAYS  2                                       // Total number of attached relays. Must be equal to total number of elements in array below!
      const int RELAYS[]                  =     {3,  5};                // digital pins of attached relays
      const int MOTION_ACTIVATED_RELAYS[] =     {1,  0};                // 1 to trigger the relay through motion, 0 to not trigger. Array length must correspond to RELAYS[] array.
      const long ON_TIMES[]               =     {300, 0};               // Specify for each element in MOTION_ACTIVATED_RELAYS, how long the specified relay should be active in seconds.
      #define RELAY_ON          1                                       // GPIO value to write to turn on attached relay
      #define RELAY_OFF         0                                       // GPIO value to write to turn off attached relay
      #define MOTION_PIN        2                                       // The digital input pin of the motion sensor
      #define MOTION_CHILD_ID   0                                       // Set the child id of the motion sensor
      bool ack = 1;                                                     // set this to 1 if you want destination node to send ack back to this node
      
      //----------------------- DO NOT CHANGE -----------------------------
      #include <MySensors.h>
      MyMessage motion_msg(MOTION_CHILD_ID, V_TRIPPED);   // Initialize motion message
      unsigned long trigger_millis[NUMBER_OF_RELAYS];     // Used for the timer
      bool lastTripped = 0;                               // Used to store last motion sensor value
      bool manual_override = 0;                           // if this gets set to 1 (e.g. by a switch or a command from the gateway), motion triggering of relays is deactivated
      MyMessage relay_msg;                                // Initialize relay message
      
      void before()
      {
        int i;
        for (int sensor = 1, i = 0; sensor <= NUMBER_OF_RELAYS; sensor++, i++) {
          // set relay pins to output mode
          pinMode(RELAYS[i], OUTPUT);
          // Restore relay to last known state (using eeprom storage)
          digitalWrite(RELAYS[i], loadState(sensor) ? RELAY_ON : RELAY_OFF);
        }
        // set motion pin to output mode, if MOTION is defined
      #ifdef MOTION
        pinMode(MOTION_PIN, INPUT);
      #endif
      }
      
      void setup()
      {
      #ifdef MOTION
        // give the motion sensor some time to settle
        Serial.println("Starting up. Please wait 8 seconds...");
        delay(8000);
      #endif
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay/Motion", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        for (int sensor = 1; sensor <= NUMBER_OF_RELAYS; sensor++) {
          present(sensor, S_BINARY, "Relay", ack);
        }
      #ifdef MOTION
        present(MOTION_CHILD_ID, S_MOTION, "Motion Sensor", ack);
      #endif
      
      }
      
      void loop()
      {
      #ifdef MOTION
        if (!manual_override) {
          // Read digital motion value
          bool tripped = digitalRead(MOTION_PIN) == HIGH;
      
          if (lastTripped != tripped) {
            Serial.print("New Motion State: ");
            Serial.println(tripped);
            // Send tripped value to gw
            send(motion_msg.set(tripped ? "1" : "0"));
            lastTripped = tripped;
      
            // Change relay states, send new state to gw and store state in eeprom
            if (tripped == 1) {
              for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
                if (MOTION_ACTIVATED_RELAYS[i] == 1) {
                  digitalWrite(RELAYS[i], RELAY_ON);
                  relay_msg_constructor(i + 1, V_STATUS);
                  send(relay_msg.set(RELAY_ON));
                  trigger_millis[i] = millis();
                  Serial.print("Relay ");
                  Serial.print(RELAYS[i]);
                  Serial.println(" turned on");
                  saveState(i, 1);
                }
              }
            }
          }
      
          for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
            if (tripped == 1 and MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
              trigger_millis[i] = millis();
            }
            if ((trigger_millis[i] + ON_TIMES[i] * 1000 < millis()) and MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
              digitalWrite(RELAYS[i], RELAY_OFF);
              relay_msg_constructor(i + 1, V_STATUS);
              send(relay_msg.set(RELAY_OFF));
              Serial.print("Relay ");
              Serial.print(RELAYS[i]);
              Serial.println(" turned off");
              saveState(i, 0);
              trigger_millis[i] = 0;
            }
          }
        }
        else {
          bool tripped = digitalRead(MOTION_PIN) == HIGH;
          if (lastTripped != tripped) {
            Serial.print("New Motion State: ");
            Serial.println(tripped);
            // Send tripped value to gw
            send(motion_msg.set(tripped ? "1" : "0"));
            lastTripped = tripped;
          }
          for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
            if (MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
              trigger_millis[i] = 0;                            // reset running timers
            }
          }
        }
      #endif
      }
      
      void receive(const MyMessage &message)
      {
        // Handle incoming relay commands
        if (message.type == V_STATUS) {
          // Change relay state
          if (RELAYS[message.sensor - 1]) {
            digitalWrite(RELAYS[message.sensor - 1], message.getBool() ? RELAY_ON : RELAY_OFF);
      
            // Store state in eeprom
            saveState(message.sensor - 1, message.getBool());
            // Write some debug info
            Serial.print("Incoming change for sensor:");
            Serial.print(message.sensor);
            Serial.print(", New status: ");
            Serial.println(message.getBool());
          }
        }
      
        // Handle incoming manual override/bypass of motion sensor
        if (message.type == V_ARMED and message.sensor == 0) {
          manual_override = message.getBool();
          Serial.print("Manual Override: ");
          Serial.println(manual_override);
        }
      }
      
      void relay_msg_constructor(int sensor, uint8_t type)
      {
        relay_msg.setSensor(sensor);
        relay_msg.setType(type);
      }
      

      Additional Notes:

      • The Child-IDs of the attached relays range from 1 up to (1-(NUMBER_OF_RELAYS))
      • The default Child-ID for the motion sensor is 0
      • Make sure to adjust the potentiometer for triggertime on your motion sensor as leftmost as possible, because the countdown-timer will not start until the motion sensor reports back a "0" (no movement)
      posted in Development
      HenryWhite
      HenryWhite
    • RE: motion sensor and 2 relay code

      @gohan said in motion sensor and 2 relay code:

      Just remove the FOR cycle in the loop function

      It's much easier than that: Just set NUMBER_OF_MOTION_RELAYS to 0

      posted in Troubleshooting
      HenryWhite
      HenryWhite