Navigation

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

    Best posts made by petewill

    • How To: Make a Simple/Cheap Scene Controller (with video)

      Hi Everyone,

      I recently decided to make a very simple/cheap scene controller with a 1x4 membrane keypad. I normally try to automate as many things as I can but sometimes it's just nice to have some physical buttons. I have this in my bedroom so I can turn on/off lights, fans etc without having to open my eyes. Hopefully this will be of use to someone...

      Fritzing Scene Controller Wiring_bb.png

      $4 Arduino Home Automation Control with MySensors – 08:19
      — Pete B

      /**
       * 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 - PeteWill
       * 
       * DESCRIPTION
       * A simple scene controller for use with MySensors.  8 scenes can be executed.
       * 4 with short button presses and 4 with long button presses (held .5 seconds or more).
       * Watch a how to video here: https://youtu.be/KMGj5Bi7vL0 
       */
      
      #include <Keypad.h>
      #include <SPI.h>
      #include <MySensor.h>
      
      #define NODE_ID 14 // or set to AUTO if you want gw to assign a NODE_ID for you.
      #define SN "Scene Controller"
      #define SV "1.0"
      
      
      #define KEYPAD_CHILD_ID 0
      
      MySensor gw;
      MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON);
      
      const byte ROWS = 4; //four rows
      const byte COLS = 1; //three columns
      char keys[ROWS][COLS] = {
        {'1'},
        {'2'},
        {'3'},
        {'4'}
      };
      
      byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad
      byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad
      
      Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
      byte lastState;
      
      
      void setup() {
        gw.begin(NULL, NODE_ID);
        gw.sendSketchInfo(SN, SV);
        gw.present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER);
        keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
      }
      
      void loop() {
        char key = keypad.getKey();
      }
      
      void keypadEvent(KeypadEvent key) {
        switch (keypad.getState()) {
      
          case PRESSED:
            lastState = 1;
            break;
      
          case HOLD:
            lastState = 2;
            break;
      
          case RELEASED:
            int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller
            if (lastState == 2) {
              keyInt = keyInt + 4; //If button is held, add 4.  If using more than 4 buttons this number will need to be changed
            }
            gw.send(scene.set(keyInt));
            break;
        }
      }
      

      Here is a link for a keypad: http://www.ebay.com/itm/171505110526?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

      Here is another option for a scene controller keypad contributed by @AWI. It has capacitive touch buttons and an interrupt to battery power can be used. Thanks @AWI!
      http://forum.mysensors.org/topic/2001/how-to-make-a-simple-cheap-scene-controller-with-video/14

      posted in My Project
      petewill
      petewill
    • How To - Doorbell Automation Hack

      Hi Everyone,

      I put together this quick how to video for hacking your doorbell to work with MySensors. It's pretty basic and the code is based on the Relay Actuator sketch. It has two main features: controlling if the doorbell rings with an on/off switch and sending a triggered state whenever it's pressed. The silence feature can be useful if a child (or you) is taking a nap. The triggered state can be used for many different things like starting a security camera, sending an alert or text message, playing custom sounds via Sonos or other device, etc. Another note, the doorbell will still function even if your home automation the controller is down for some reason.

      Here are the additional details:
      Arduino Doorbell Home Automation Hack with MySensors – 08:18
      — Pete B

      Fritzing Doorbell Wiring_bb.png

      /*
       * 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 - PeteWill
       *
       * DESCRIPTION
       * This sketch is used to control a doorbell ring with a relay as well as send an
       * alert when the buttons is pressed.  Connect the button to ground and digital
       * pin 3.  The relay controlling the doorbell is conntected to pin 4.
       * 
       * Watch the How To video here: https://youtu.be/nMIcalwpstc
       */
      
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      #define NODE_ID 16 // or set to AUTO if you want gw to assign a NODE_ID for you.
      
      #define DOORBELL_PIN  3      // Arduino Digital I/O pin number for the doorbell button 
      #define RELAY_PIN  4         // Arduino Digital I/O pin number for the relay 
      #define DOORBELL_CHILD_ID 0  //ID of the doorbell
      #define SWITCH_CHILD_ID 1    // Id of the switch that will control doorbell sound
      #define RELAY_ON 1
      #define RELAY_OFF 0
      
      Bounce debouncer = Bounce();
      
      MySensor gw;
      MyMessage switchMsg(SWITCH_CHILD_ID, V_LIGHT);
      MyMessage doorbellMsg(DOORBELL_CHILD_ID, V_TRIPPED);
      
      unsigned int doorbellDelay = 1000; // interval at which to keep the doorbell button sensor triggered (milliseconds). This is used to stop people (kids) from pressing it too often
      unsigned int ringTime = 700; //How long the doorbell relay is on (in milliseconds)
      unsigned long doorbellMillis;  //Used to keep track of the last doorbell button press
      unsigned long doorbellTimer;  //Used to keep track of doorbell ring time
      byte doorbellPreviousVal;  //Used to keep track of doorbell button pressed state
      boolean ringDoorbell;  //Used to initiate the ring doorbell if statement
      boolean doorbellSound; //Used to keep track if the doorbell should sound or be silent.  Value recieved from doorbell on/off switch
      boolean doorbellOff = true;  //Used to keep track of doorbell ring state
      
      void setup()
      {
        gw.begin(incomingMessage, NODE_ID);
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Doorbell Monitor", "1.0");
      
        // Setup the button and activate internal pull-up
        pinMode(DOORBELL_PIN, INPUT_PULLUP);
      
        // After setting up the button, setup debouncer
        debouncer.attach(DOORBELL_PIN);
        debouncer.interval(5);
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(SWITCH_CHILD_ID, S_LIGHT);
        gw.present(DOORBELL_CHILD_ID, S_MOTION);
      
        // Make sure relays are off when starting up
        digitalWrite(RELAY_PIN, RELAY_OFF);
        // Then set relay pins in output mode
        pinMode(RELAY_PIN, OUTPUT);
      
        // Set doorbellSound to last known state (using eeprom storage)
        doorbellSound = gw.loadState(SWITCH_CHILD_ID);
      }
      
      void loop()
      {
        gw.process();
          unsigned long currentMillis = millis();
        //Check to see if doorbell button was pushed.
        if (currentMillis - doorbellMillis > doorbellDelay) //used to stop doorbell from being pressed too frequently
        {
          debouncer.update();
          // Read doorbell button value
          byte doorbellDetect = !debouncer.read();//read, then reverse the value so it will send correct trigger state to controller
      
          if (doorbellDetect != doorbellPreviousVal)
          {
            //Serial.print("doorbellDetect Value: ");
            //Serial.println(doorbellDetect);
            gw.send(doorbellMsg.set(doorbellDetect)); 
            if (doorbellDetect == 1)
            {
              ringDoorbell = true;
              doorbellTimer = currentMillis;
            }
            doorbellMillis = currentMillis;
            doorbellPreviousVal = doorbellDetect;
          }
        }
      
        if (ringDoorbell)
        {
          if (doorbellSound)
          {
            if (doorbellOff)
            {
              digitalWrite(RELAY_PIN, RELAY_ON);
              //Serial.println("Doorbell sounded.");
              doorbellOff = false;
            }
            else
            {
              if (currentMillis - doorbellTimer > ringTime)
              {
                ringDoorbell = false;
                digitalWrite(RELAY_PIN, RELAY_OFF);
                //Serial.println("Doorbell off.");
                doorbellOff = true;
              }
            }
          }
        }
      }
      
        void incomingMessage(const MyMessage & message) {
          // We only expect one type of message from controller. But we better check anyway.
          if (message.isAck()) {
            Serial.println("This is an ack from gateway");
          }
      
          if (message.type == V_LIGHT) {
            // Change relay state
            doorbellSound = message.getBool();
            // Store state in eeprom
            gw.saveState(SWITCH_CHILD_ID, doorbellSound);
      
            // Write some debug info
            Serial.print("Incoming change for sensor:");
            Serial.print(message.sensor);
            Serial.print(", New status: ");
            Serial.println(message.getBool());
          }
        }
      posted in My Project
      petewill
      petewill
    • Video How To - Phoney TV

      Hi Everyone,

      Here is a how to video for building Jim's (@BulldogLowell) awesome PhoneyTV project. We thought it would be the most straight forward to start a new thread so everything can be compiled into the first post but make sure you check out Jim's original work here: http://forum.mysensors.org/topic/85/phoneytv-for-vera-is-here
      You can see all the details of his build (including his cool enclosure) as well as the input from others there.

      Ok, here is the info you need to build this project:

      DIY PhoneyTV with Arduino and MySensors – 12:19
      — Pete B

      0_1472736979528_Fritzing PhoneyTV Wiring.png

      /*
       * PhoneyTV v3.1.1
       *
       * This Sketch illuminates 6 sets of LED's in a random fashion as to mimic the
       * light eminating from a television.  It is intended to make an empty home,
       * or an empty section of a home, appear to be occupied by someone watching
       * TV.  As an alternative to a real television left on, this uses less than 1%
       * of the electrical energy.
       *
       * With the use of the MySensors plugin and gateway, PhoneyTV is intended to
       * be used with a controller (e.g. Vera or Raspberry PI).
       *
       * Sketch does not use any delays to create the random blinking as a way to
       * assure that communication back to the gateway is as unaffected as possible.
       *
       * You can adjust the length of the blink interval and its "twitchyness" by
       * modifying the random number generators, if you prefer more/less 'motion' in
       * in your unit.  The lines are highlighted in the code, play around to create the
       * random effect you like.
       *
       * Sketch takes advantage of available PWM on pins 3, 5 & 6 using the white/blue LEDs
       * to allow fluctuations in the intensity of the light, enhancing the PhoneyTV's
       * realistic light effects.
       *
       * Created 12-APR-2014
       * Free for distrubution
       * Credit should be given to MySensors.org for their base code for relay control
       * and for the radio configuration.  Thanks Guys.
       *
       * 29-May-2014
       * Version 2:  Simplified the code, removing all redundant relay setup from original
       * code.  Added an on/off momentary pushputton option to be set up on pin 2.  Inproved
       * the dark dips for longer duration (can be configured) at intervals.
       *
       * 6-Jun-2015
       * Version 3.1
       * Updated for MySensors V1.4.1
       * Contributed by Jim (BulldogLowell@gmail.com) Inspired by Josh >> Deltanu1142@gmail.com
       *
       * How to video: https://youtu.be/p37qnl8Kjfc
       */
      //
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      //
      #define SKETCH_NAME "PhoneyTV"
      #define SKETCH_VERSION "3.1.1"
      //
      #define RADIO_RESET_DELAY_TIME 20
      //
      #define BUTTON_PIN  2  // Arduino Digital I/O pin number for button 
      #define CHILD_ID 1   // 
      #define RADIO_ID 5  //AUTO
      //
      #define DEBUG_ON
      //
      #ifdef DEBUG_ON
      #define DEBUG_PRINT(x)   Serial.print(x)
      #define DEBUG_PRINTLN(x) Serial.println(x)
      #define SERIAL_START(x)  Serial.begin(x)
      #else
      #define DEBUG_PRINT(x)
      #define DEBUG_PRINTLN(x)
      #define SERIAL_START(x)
      #endif
      //
      MySensor gw;
      MyMessage msg(CHILD_ID, V_LIGHT);
      //
      byte ledPin3 =  3;      // White using PWM
      byte ledPin4 =  4;      // Red
      byte ledPin5 =  5;      // Blue using PWM
      byte ledPin6 =  6;      // Blue using PWM
      byte ledPin7 =  7;      // Green
      byte ledPin8 =  8;      // White (No PWM)
      //
      Bounce debouncer = Bounce();
      byte oldValue = 0;
      boolean state = false;
      boolean oldState = false;
      int dipInterval = 10;
      int darkTime = 250;
      unsigned long currentDipTime;
      unsigned long dipStartTime;
      unsigned long currentMillis;
      byte ledState = LOW;
      unsigned long previousMillis = 0UL;
      byte led = 5;
      unsigned long interval = 2000UL;
      int twitch = 50;
      int dipCount = 0;
      int analogLevel = 100;
      boolean timeToDip = false;
      boolean gotAck=false;
      //
      void setup()
      {
        SERIAL_START(115200);
        pinMode(ledPin3, OUTPUT);
        pinMode(ledPin4, OUTPUT);
        pinMode(ledPin5, OUTPUT);
        pinMode(ledPin6, OUTPUT);
        pinMode(ledPin7, OUTPUT);
        pinMode(ledPin8, OUTPUT);
        pinMode(BUTTON_PIN, INPUT_PULLUP);
        //
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(50);
        //
        gw.begin(incomingMessage, RADIO_ID, true, 0);  // configured as a repeating node!!
        gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        gw.wait(RADIO_RESET_DELAY_TIME);
        gw.present(CHILD_ID, S_LIGHT);
        gw.wait(RADIO_RESET_DELAY_TIME);
        while(!gw.send(msg.set(state), false))
        {
      	gw.wait(RADIO_RESET_DELAY_TIME);
        }
        gw.wait(RADIO_RESET_DELAY_TIME);
        DEBUG_PRINTLN(F("Sensor Presentation Complete"));
      }
      //
      void loop()
      {
        gw.process();
        debouncer.update();
        byte value = debouncer.read();
        if (value != oldValue && value == 0)
        {
      	state = !state;
      	while(!gotAck)
      	{
      	  gw.send(msg.set(state), true);
      	  gw.wait(RADIO_RESET_DELAY_TIME);
      	}
      	gotAck = false;
      	DEBUG_PRINT(F("State Changed to:"));
      	DEBUG_PRINTLN(state? F("PhoneyTV ON") : F("PhoneyTV OFF"));
        }
        oldValue = value;
        if (state)
        {
      	if (timeToDip == false)
      	{
      	  currentMillis = millis();
      	  if (currentMillis - previousMillis > interval)
      	  {
      		previousMillis = currentMillis;
      		interval = random(750, 4001); //Adjusts the interval for more/less frequent random light changes
      		twitch = random(40, 100); // Twitch provides motion effect but can be a bit much if too high
      		dipCount = dipCount++;
      	  }
      	  if (currentMillis - previousMillis < twitch)
      	  {
      		led = random(3, 9);
      		analogLevel = random(50, 255); // set the range of the 3 pwm leds
      		ledState = !ledState;
      		switch (led) //for the three PWM pins
      		{
      		  case 3:
      			pwmWrite();
      			break;
      		  case 5:
      			pwmWrite();
      			break;
      		  case 6:
      			pwmWrite();
      			break;
      		  default:
      			digitalWrite(led, ledState);
      		}
      		if (dipCount > dipInterval)
      		{
      		  timeToDip = true;
      		  dipCount = 0;
      		  dipStartTime = millis();
      		  darkTime = random(50, 150);
      		  dipInterval = random(5, 250); // cycles of flicker
      		}
      	  }
      	}
      	else
      	{
      	  DEBUG_PRINTLN(F("Dip Time"));
      	  currentDipTime = millis();
      	  if (currentDipTime - dipStartTime < darkTime)
      	  {
      		for (int i = 3; i < 9; i++)
      		{
      		  digitalWrite(i, LOW);
      		}
      	  }
      	  else
      	  {
      		timeToDip = false;
      	  }
      	}
        }
        else
        {
      	if (state != oldState)
      	{
      	  for (int i = 3; i < 9; i++)
      	  {
      		digitalWrite(i, LOW);
      	  }
      	}
        }
        oldState = state;
      }
      //
      void incomingMessage(const MyMessage &message)
      {
        if (message.isAck())
        {
      	DEBUG_PRINTLN(F("This is an ack from gateway"));
      	gotAck = true;
        }
        if (message.type == V_LIGHT)
        {
      	state = message.getBool();
      	DEBUG_PRINT(F("Incoming change for sensor... New State = "));
      	DEBUG_PRINTLN(state? F("ON") : F("OFF"));
        }
      }
      //
      void pwmWrite()
      {
        if (ledState == HIGH) 
        {
      	analogWrite(led, analogLevel);
        }
        else 
        {
      	digitalWrite(led, LOW);
        }
      }
      

      Parts List

      • 10 - 100 Ohm 1/2 watt Resistors - http://www.ebay.com/itm/20pcs-1-2W-0-5W-Watt-Metal-Film-Resistor-1-36-47-100-360-470-560-680-820-OHM-/361402983317?var=&hash=item54254be395ⓂmyWupCGR_EGHbEjk3g4ixZg
      • 2 - 150 Ohm 1/2 watt Resistors - http://www.ebay.com/itm/20pcs-1-2W-0-5W-Watt-Metal-Film-Resistor-1-36-47-100-360-470-560-680-820-OHM-/361402983317?var=&hash=item54254be395ⓂmyWupCGR_EGHbEjk3g4ixZg
      • 9cm x 15cm PCB Board - http://www.ebay.com/itm/1x-Double-Side-Protoboard-9cm-x15cm-PCB-Experiment-Matrix-Circuit-Board-WWU-/231693193879?hash=item35f1fd9297:g:cGEAAOSwKIpV~GH8
      • 6 - MOSFET Transistors - http://www.digikey.com/product-detail/en/0/785-1568-5-ND
      • 4 - 1/2 watt super-bright 10mm Red, Green, Blue & White LEDs -
        http://www.ebay.com/itm/25pcs-10mm-0-5W-Red-Yellow-Blue-Green-White-40-Large-Chip-Water-Clear-LED-Leds-/321548049284?hash=item4addc1db84
      • 4.7 uf Capacitor - Assorted Capacitors in the MySensors store http://www.mysensors.org/store/#components
      • Pro Mini (3.3v) - http://www.mysensors.org/store/#arduinos
      • NRF24L01+ Radio - http://www.mysensors.org/store/#radios
      • Cat5/6 cable
      • Old phone charger
      • USB cord
      posted in My Project
      petewill
      petewill
    • Video How To - Monitor your Refrigerator

      2016-12-31 Edit: Updated code to MySensors Version 2.1 and added LEDs for door status (optional).

      Recently we have been having problems with our refrigerator door not fully closing. Usually it's a result of something not pushed fully in and it stops the door from closing. Our fridge is old and doesn't have any built in alarms so I thought I'd "MySensorize" it so we get alerts if the door says open. I also added some Dallas Temp sensors to monitor the temperature. Nothing to advanced or sophisticated but it gets the job done.

      Refrigerator Monitoring with Arduino and MySensors – 09:23
      — Pete B

      Fritzing Fridge Monitoring Wiring

      Parts List

      • 4.7 uf Capacitor - Assorted Capacitors in the MySensors store http://www.mysensors.org/store/#components
      • Pro Mini (3.3v) - http://www.mysensors.org/store/#arduinos
      • NRF24L01+ Radio - http://www.mysensors.org/store/#radios
      • 2x DS18B20 Dallas Temperature Sensors - http://www.mysensors.org/store/#temperature
      • Copper Tape - http://www.ebay.com/itm/5mm-X-30m-1-Roll-EMI-Copper-Foil-Shielding-Tape-Conductive-Self-Adhesive-Barrier-/121621527850?hash=item1c51353d2a:g:EOAAAOSwpDdVK347
      • Female Dupont Cables - http://www.mysensors.org/store/#cables
      • Cat5/6 cable
      • Old USB cable (use the individual wires inside for the Dallas temp sensors)
      • Old phone charger (or some sort of 5v power supply)

      Here is the code to find your Dallas Temp Sensor addresses. I chose to find the addresses and program them in based on recommendations from the DS18B20 datasheet. You could change the Refrigerator Monitoring code to have it automatically find them each time the device is powered up if you prefer.

      #include <OneWire.h>
      #include <DallasTemperature.h>
      
      // Data wire is plugged into port 2 on the Arduino
      #define ONE_WIRE_BUS 3 //Pin where Dallas sensor is connected
      
      // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
      OneWire oneWire(ONE_WIRE_BUS);
      
      // Pass our oneWire reference to Dallas Temperature.
      DallasTemperature dallasTemp(&oneWire);
      
      // arrays to hold device addresses
      DeviceAddress tempAddress[7];
      
      void setup(void)
      {
        // start serial port
        Serial.begin(115200);
      
        // Start up the library
        dallasTemp.begin();
      
        // show the addresses we found on the bus
        for (uint8_t i = 0; i < dallasTemp.getDeviceCount(); i++) {
          if (!dallasTemp.getAddress(tempAddress[i], i))
          {
            Serial.print("Unable to find address for Device ");
            Serial.println(i);
            Serial.println();
          }
          Serial.print("Device ");
          Serial.print(i);
          Serial.print(" Address: ");
          printAddress(tempAddress[i]);
          Serial.println();
        }
      }
      
      void printAddress(DeviceAddress deviceAddress)
      {
        for (uint8_t i = 0; i < 8; i++)
        {
          // zero pad the address if necessary
          //if (deviceAddress[i] < 16) Serial.print("0");
          Serial.print("0x");
          Serial.print(deviceAddress[i], HEX);
          if (i < 7) {
            Serial.print(", ");
          }
        }
      }
      
      
      void loop(void)
      {
      
      }
      

      And here is the code for the Fridge monitoring

      /*
         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 - PeteWill
         2016-12-29 Version 1.1 - PeteWill Updated to MySensors 2.1 and added status LEDs for the doors
      
         DESCRIPTION
         This sketch is used to monitor your refrigerator temperature and door states.
         You will need to find the addresses for your Dallas temp sensors and change them in the dallasAddresses array
      
         Watch the How To video here: https://youtu.be/2vAYAbtQfjs
      */
      
      
      //#include <SPI.h>
      #include <DallasTemperature.h>
      #include <OneWire.h>
      #include <Bounce2.h>
      
      
      //MySensors configuration options
      //#define MY_DEBUG //Uncomment to enable MySensors related debug messages (additional debug options  are below)
      #define MY_RADIO_NRF24 // Enable and select radio type attached
      //#define MY_NODE_ID 1  //Manually set the node ID here. Comment out to auto assign
      #include <MySensors.h>
      
      #define SKETCH_NAME "Refrigerator Monitor"
      #define SKETCH_VERSION "1.1"
      
      #define DWELL_TIME 70 //value used in all wait calls (in milliseconds) this allows for radio to come back to power after a transmission, ideally 0
      
      
      #define ONE_WIRE_BUS 3 // Pin where dallas sensors are connected 
      #define TEMPERATURE_PRECISION 12  //The resolution of the sensor
      
      OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
      DallasTemperature dallasTemp(&oneWire); // Pass our oneWire reference to Dallas Temperature.
      
      //MySensor gw;
      unsigned long tempDelay = 425000;
      float lastTemperature[2];
      unsigned long tempMillis;
      bool metric = false;
      
      // arrays to hold device addresses
      DeviceAddress dallasAddresses[] = {
        {0x28, 0xD0, 0xD3, 0x41, 0x7, 0x0, 0x0, 0xDF}, //Freezer Address -- Modify for your sensors
        {0x28, 0xFF, 0x22, 0xA0, 0x68, 0x14, 0x3, 0x2F} //Fridge Address -- Modify for your sensors
      };
      
      //Set up debouncer (used for door sensors)
      Bounce debouncer[] = {
        Bounce(),
        Bounce()
      };
      
      //Make sure to match the order of doorPins to doorChildren.
      //The pins on your Arduino
      int doorPins[] = {4, 5};
      //The child ID that will be sent to your controller
      int doorChildren[] = {2, 3};
      //Freezer temp will be Child 0 and Fridge temp will be Child 1
      
      //used to keep track of previous values contact sensor values
      uint8_t oldValueContact[] = {1, 1};
      
      uint8_t doorLedPins[] = {6, 7};
      
      // Initialize temperature message
      MyMessage dallasMsg(0, V_TEMP);
      MyMessage doorMsg(0, V_TRIPPED);
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway
        sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        
        // Register all sensors to gw (they will be created as child devices)
        // Present temp sensors to controller
        for (uint8_t i = 0; i < 2; i++) {
          present(i, S_TEMP);
          wait(DWELL_TIME);
        }
        // Present door sensors to controller
        for (uint8_t i = 0; i < 2; i++) {
          present(doorChildren[i], S_DOOR);
          wait(DWELL_TIME);
        }
      }
      
      void setup()
      {
        // Startup OneWire
        dallasTemp.begin();
      
        // set the temp resolution
        for (uint8_t i = 0; i < 2; i++) {
          dallasTemp.setResolution(dallasAddresses[i], TEMPERATURE_PRECISION);
        }
      
      //  // Startup and initialize MySensors library. Set callback for incoming messages.
      //  gw.begin(NULL, NODE_ID);
      //
      //  // Send the sketch version information to the gateway and Controller
      //  gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      
        //Set up door contacts & LEDs
        for (uint8_t i = 0; i < 2; i++) {
      
          // Setup the pins & activate internal pull-up
          pinMode(doorPins[i], INPUT_PULLUP);
      
          // Activate internal pull-up
          //digitalWrite(doorPins[i], HIGH);
      
          // After setting up the button, setup debouncer
          debouncer[i].attach(doorPins[i]);
          debouncer[i].interval(700); //This is set fairly high because when my door was shut hard it caused the other door to bounce slightly and trigger open.
      
          //Set up LEDs
          pinMode(doorLedPins[i], OUTPUT);
          digitalWrite(doorLedPins[i], LOW);
        }
      
      
      }
      
      
      void loop()
      {
        unsigned long currentMillis = millis();
      
        if (currentMillis - tempMillis > tempDelay) {
          // Fetch temperatures from Dallas sensors
          dallasTemp.requestTemperatures();
      
          // Read temperatures and send them to controller
          for (uint8_t i = 0; i < 2; i++) {
      
            // Fetch and round temperature to one decimal
            float temperature = static_cast<float>(static_cast<int>((metric ? dallasTemp.getTempC(dallasAddresses[i]) : dallasTemp.getTempF(dallasAddresses[i])) * 10.)) / 10.;
            // Only send data if temperature has changed and no error
            if (lastTemperature[i] != temperature && temperature != -127.00) {
      
              // Send in the new temperature
              send(dallasMsg.setSensor(i).set(temperature, 1));
              lastTemperature[i] = temperature;
            }
          }
          tempMillis = currentMillis;
        }
      
        for (uint8_t i = 0; i < 2; i++) {
          debouncer[i].update();
          // Get the update value
          uint8_t value = debouncer[i].read();
          if (value != oldValueContact[i]) {
            // Send in the new value
            send(doorMsg.setSensor(doorChildren[i]).set(value == HIGH ? "1" : "0"));
            digitalWrite(doorLedPins[i], value);
            oldValueContact[i] = value;
          }
        }
      
      }
      
      
      
      posted in My Project
      petewill
      petewill
    • Low Voltage Whole House Power Supply

      After using my low voltage whole house power supply for a couple years I finally made a video about it. It's pretty simple and cheap (assuming you can get a free/recycled computer power supply) but has served me well. I use it to power my blinds, lights, motion sensors, etc. all around my house. It uses a computer power supply and provides me with 12v, 5v and 3.3v DC power. Use this at your own risk and make sure to check out the Voltage Drop Calculator and Wire Gauge Calculator sites to make sure your wires are the correct gauge.

      DIY Low Voltage Whole House Power Supply – 09:29
      — Pete B

      Parts list
      Computer Power Supply
      Fuse Block
      Push-on Terminals
      1A Fuses
      Wire - 16 Gauge
      Ground Bar

      posted in My Project
      petewill
      petewill
    • $8 Lamp (Outlet) "Smart Plug" Module

      Hi All,

      I created a second "Smart Plug" and thought I'd make a how to video this time. I have found them very useful for controlling various devices around the house. It's long but hopefully will be good for everyone including those not too familiar with MySensors. I know when I was first starting out I had little to no experience with any of this stuff and it was hard to piece it all together.

      $8 DIY Arduino Smart Outlet Lamp Module – 26:35
      — Pete B

      Here is the parts list (most of this stuff can be obtained from the my sensors store so don't forget to support them!)

      • 1 Gang Outlet Box
      • Outlet
      • Computer power cord or extension cord
      • Old cell phone charger or some other 5v power supply
      • Items from MySensors Store http://www.mysensors.org/store/
      • 22-24 gauge wire or similar (network cord)
      • Female Pin Header Connector Strip
      • Prototype Universal Printed Circuit Board
      • NRF24L01 Radio
      • Arduino Pro Mini
      • Capacitors (10uf and .1uf)
      • 3.3v voltage regulator
      • Female Dupont cables

      Here is a wiring diagram for the 3.3v regulator:
      Voltage Regulator Schematic.png

      0_1467849909161_Fritzing Smart Outlet.png

      Here is the code I used. I made a few customizations but the example "Relay Actuator" code can be used as well.
      https://codebender.cc/sketch:72358

      *edited to add wiring diagram

      posted in My Project
      petewill
      petewill
    • Video How To: Battery Powered Chair Occupancy (Contact) Sensor

      I finally got around to making my first battery powered sensor (after 3+ years 😬 ) and I thought I'd make a video on how I did it. I'm amazed how easy it was and I'm not sure why I didn't do this sooner… I am using the sensor to monitor my dining room chairs so I can better automate the lights in that room (check out the video for more details).

      If my calculations are correct (and it's entirely possible they aren't) this sensor should run for about 3 years on 2 AA Alkaline batteries. Here is my math if anyone is interested (or wants to correct it). NOTE: I had an issue with one of my radios where it was using a couple if mA when sleeping so make sure you check your setup before finalizing the device so your batteries don't drain in a couple of weeks. You should be getting about 6uA when your Pro Mini is sleeping.

      Usage when sleeping =

      • 5.8uA (0.0058mA) when contact sensor is open/disconnected
      • 10uA when contact sensor is closed/connected with a 1M external pullup resistor
      • 100uA when contact sensor is closed/connected with internal pullup resistor

      Usage when transmitting =

      • 16mA with the NRF radio set to LOW

      I'm estimating a total of 10 transmissions per meal (5 times sitting/getting up). Just for good measure I'll say there will be 4 meals a day which would equal 40 transmissions per day. The sensor is also sending a battery level every 4 hours which would give an additional 6 transmissions. So that would give a total of 46 transmissions per day. So, 40/24=1.6667 transmissions per hour with it sleeping the rest of the time.

      Here is the equation to get the average mA:
      Iavg = (mA x time awake) + (mA x time asleep) / ( 1 hour)
      Iavg = (16mA x (1.67 x 2 seconds per transmission) + (.006mA x (1 hour - awake time)) / (7200sec)
      Iavg = (16x3.34) + (.006x7196.66) / 7200 = 53.446 mA per hour
      Iavg = 53.446 mA per hour

      Battery Life = Battery Capacity in Milli amps per hour / Load Current in Mill amps * 0.70
      From http://www.digikey.com/en/resources/conversion-calculators/conversion-calculator-battery-life

      Alkaline batteries should get around 985 days (32 months). AA alkaline batteries typically have a capacity rating of over 2,500 mAh (each).

      Ok, enough of that. Let's get on with the building…

      Build Video
      $4 Battery Powered Chair Occupancy (Contact) Sensor using Arduino and MySensors – 17:53
      — Pete B

      Wiring Diagram
      0_1493422745392_Fritzing Chair Occupancy Sensor.png

      Parts Needed (BOM)
      3.3v Arduino Pro Mini
      NRF24L01+ Radio
      1M Ohm Resistor
      Battery holder (eBay) or Battery holder (3D print)
      Contact Sensor:

      • Reed sensor
        or
      • Copper tape
      • Metal flashing (local home goods store)

      Links/Credits
      Arduino_VCC Library link - https://github.com/Yveaux/Arduino_Vcc
      Gert Sanders Bootloader's - https://www.openhardware.io/view/33/Various-bootloader-files-based-on-Optiboot-62
      MySensors Battery Build Page - https://www.mysensors.org/build/battery

      Code
      NOTE:
      Minimum MySensors Library build of 2.2 is recommended for this sensor

      /**
         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.
      
       *******************************
         NOTE
         Please use MySensors version 2.2.0 or higher to avoid issues with interrupts and sleep
      
         DESCRIPTION
         Low power/battery operated contact switch
         - Send heartbeat (battery & sensor status) every 4 hours
         - Send contact switch status after performing 3 checks to make sure it's not someone shifting in the chair
         - Uses approximately 5.8uA when sleeping
      
         VIDEO
         To watch a video on how to make this sensor go here: https://youtu.be/uz3nBkRKSkk
      */
      #define SKETCH_NAME "Chair Sensor"
      #define SKETCH_VERSION "1.0"
      
      // Enable debug prints to serial monitor
      //#define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_RF24_PA_LEVEL RF24_PA_LOW //Options: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
      #define MY_RF24_CHANNEL  76
      #define MY_NODE_ID 1  //Manually set the node ID here. Comment out to auto assign
      #define MY_TRANSPORT_WAIT_READY_MS 3000 //This will allow the device to function without draining the battery if it can't find the gateway when it first starts up
      #define MY_BAUD_RATE 9600 //Serial monitor will need to be set to 9600 Baud
      
      #include <MySensors.h>
      
      #include <Vcc.h>
      
      #define CONTACT_CHILD_ID 0
      #define CONTACT_PIN  3  // Arduino Digital I/O pin for button/reed switch
      #define CONTACT_CHILD_NAME "Chair Sensor 1" //The name of this specific child device will be sent to the controller
      
      #define DEBOUNCE_DELAY 1200 //DO NOT SET BELOW 1000! Amount of time to sleep between reading the contact sensor (used for debouncing)
      #define BATTERY_DELAY 14400000 //(4 hours) Amount of time in milliseconds to sleep between battery messages (as long as no interrupts occur)
      //#define BATTERY_DELAY 60000
      
      uint8_t oldContactVal = 2; //Used to track last contact value sent.  Starting out of bounds value to force an update when the sensor is first powered on
      uint8_t contactVal[2]; //Used for storing contact debounce values
      uint8_t contactTracker = 0; //Used as a sort of debounce to stop frequent updates when shifting in chair
      int8_t wakeVal = 0; //Used to determine if wake was from timer or interrupt
      
      const float VccMin   = 1.9;           // Minimum expected Vcc level, in Volts. (NRF can only go to 1.9V)
      const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
      const float VccCorrection = 1.0 / 1.0; // Measured Vcc by multimeter divided by reported Vcc
      
      Vcc vcc(VccCorrection);
      
      MyMessage msgContact(CONTACT_CHILD_ID, V_TRIPPED);
      
      void presentation() {
        // Present sketch name & version
        sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      
        // Register binary input sensor to gw (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        present(CONTACT_CHILD_ID, S_MOTION, CONTACT_CHILD_NAME);
      }
      void setup()
      {
        //Set unused pins low to save a little power (http://gammon.com.au/forum/?id=11497)
        for (uint8_t i = 4; i <= 8; i++)
        {
          pinMode (i, INPUT);
          digitalWrite (i, LOW);
        }
      
        // Setup the button and activate internal pullup resistor
        //pinMode(CONTACT_PIN, INPUT_PULLUP); //(Uses 100uA in sleep)
        pinMode(CONTACT_PIN, INPUT);  //Use this with an external pullup resistor (uses 10uA in sleep)
      
        float p = vcc.Read_Perc(VccMin, VccMax);
      #ifdef MY_DEBUG
        Serial.print("Batt Level: ");
        Serial.println(p);
      #endif
        sendBatteryLevel((uint8_t)p); //Send battery level to gateway
      }
      
      
      void loop()
      {
        //Read the value returned by sleep.  If it was a timer send battery info otherwise
        if (wakeVal < 0) {
          //Woke by timer, send battery level and current state of contact sensor
          float p = vcc.Read_Perc(VccMin, VccMax);
      
      #ifdef MY_DEBUG
          float v = vcc.Read_Volts(); //Only using this for debugging so we don't need it taking up resources normally
          Serial.println("Woke by timer.");
          Serial.print("VCC = ");
          Serial.print(v);
          Serial.println(" Volts");
          Serial.print("VCC = ");
          Serial.print(p);
          Serial.println(" %");
      #endif
          sendBatteryLevel((uint8_t)p); //Send battery level to gateway
          send(msgContact.set(oldContactVal ? 0 : 1)); //Send current sensor value
          wakeVal = sleep(digitalPinToInterrupt(CONTACT_PIN), CHANGE, BATTERY_DELAY);  //Go back to sleep
        }
        else {
          //Woke by interrupt, send contact value
          if (contactTracker < 2) {
            contactVal[contactTracker] = digitalRead(CONTACT_PIN);
      #ifdef MY_DEBUG
            Serial.print("contactVal: ");
            Serial.println(contactVal[contactTracker]);
            Serial.print("contactTracker: ");
            Serial.println(contactTracker);
            Serial.println("Sleeping");
      #endif
            contactTracker++; //increment contact tracker
            sleep(DEBOUNCE_DELAY); //sleep until next read
            //wait(DEBOUNCE_DELAY);
          }
          else {
            contactTracker = 0; //Reset contact tracker
            uint8_t readValue = digitalRead(CONTACT_PIN);
      #ifdef MY_DEBUG
            Serial.print("contactVal: ");
            Serial.println(readValue);
      #endif
            if (readValue == contactVal[0] && readValue == contactVal[1]) {
              //All values are the same, send an update
      #ifdef MY_DEBUG
              Serial.println("Values the same");
      #endif
              if (oldContactVal != readValue) {
      #ifdef MY_DEBUG
                Serial.println("Contact changed. Sending to gateway");
      #endif
                send(msgContact.set(readValue == LOW ? 1 : 0));
                oldContactVal = readValue;
              }
            }
            wakeVal = sleep(digitalPinToInterrupt(CONTACT_PIN), CHANGE, BATTERY_DELAY);  //Go back to sleep
          }
        }
      
      }
      
      posted in My Project
      petewill
      petewill
    • Controlling Blinds.com RF Dooya Motors with Arduino and Vera

      I recently figured out how to control my Blinds.com motorized cellular shades (http://www.blinds.com/control/product/productID,97658) with my Vera 3. The blinds have Dooya DV24CE motors (which use a 433 MHz RF for remote control) built into them but I couldn't find any already built RF transmitter that integrated directly with the Vera. I had recently started building Arduino sensors with Henrik's amazing MySensors Arduino Sensor Plugin (http://www.mysensors.org) so I decided to try to build my own. Thanks to many helpful resources on the internet I was able to control my blinds for less than $20 in Arduino parts.

      Here is a link to a YouTube video with an overview of the process: http://youtu.be/EorIqw-9eJw

      Here is a pdf with more info on the process if you are interested in doing it yourself:
      Controlling Blinds.com RF Dooya Motors with Arduino and Vera.pdf

      Arduino Code MySensors Version 2.x:
      https://gist.github.com/petewill/ac31b186291743e046f83497de0ffa87

      And the Arduino Code (OLD CODE):
      BlindsVera.ino

      2020-12-06: Edited to add updated code

      posted in My Project
      petewill
      petewill
    • RE: Read this first - it could SAVE YOU A LOT OF TIME

      Hi Everyone,

      I made a quick video to share some of the things I've learned when troubleshooting issues. I’m not an expert and this is by no means an all-inclusive troubleshooting guide but hopefully it will give you some tips that will help you get to the root of the problem you’re experiencing.

      MySensors Troubleshooting Tips – 13:32
      — Pete B

      posted in Troubleshooting
      petewill
      petewill
    • RE: Why I quit using MySensors for actuators

      I realize this thread is getting old but I'm behind in my reading... 🙂

      I just wanted to say that I have been using actuators (irrigation, lighting, motors, etc) for years and I have had nearly flawless results (at least as good as my z-wave stuff, if not better). I don't want to start any arguments but just wanted to let everyone know that it is possible to use MySensors for actuators in case you haven't tried it. I'm actually pretty surprised that people seem to be having issues with actuators as mine have been working well.
      I did find that modifying the NRF antennas as well as using repeaters has helped in some of the devices that are far away from my gateway.
      Hopefully this doesn't come across the wrong way, just wanted to give some encouragement to not give up 🙂

      posted in General Discussion
      petewill
      petewill
    • Backlit Dimmable LED Mirror with Motion Sensor

      Backlit-Mirror.jpg
      Hi Everyone,

      I have created backlit mirror based on Bruce Lacey's dimmable LED sketch. I have added a motion sensor and some on/off and fade up/down buttons. There is some logic in the code to save the dim level when the buttons are pressed. I have all my motion turn on/off logic in my Vera controller using PLEG. It could be easily adapted to control the on/off functionality in the Arduino code but I like to have my automation logic in one place (my Vera).

      This was a fun project to work on and although it looks pretty ugly from the back my wife loves the way it looks in our master bathroom. I tried to document as best I could but please let me know if you have any questions.

      Here is a list of the parts I used

      • Items from MySensors Store http://www.mysensors.org/store/
        • Female Pin Header Connector Strip
        • Prototype Universal Printed Circuit Boards (PCB)
        • NRF24L01 Radio
        • Arduino Pro Mini
        • FTDI USB to TTL Serial Adapter
        • Capacitors (10uf and .1uf)
        • 3.3v voltage regulator
        • 5v voltage regulator
        • IRLZ44N Logic Level Transistor MOSFET
        • 12v Transformer (power supply)
        • 5 Meter LED Strip (I used 3528)
        • HC-SR501 PIR Motion Sensor Module
      • 22-24 gauge wire or similar (I used Cat5/Cat6 cable)
      • 2 Pole 5mm Pitch PCB Mount Screw Terminal Block

      Here is a video explaining how to build it yourself.
      Arduino Backlit Dimmable LED Mirror with Motion Sensor using MySensors – 14:11
      — Pete B

      Mirror LED Wiring Diagram.png
      Here is the Fritzing (http://fritzing.org/) wiring diagram file if you want to view in more detail: Mirror LED Wiring Diagram.fzz
      https://codebender.cc/sketch:81486

      20150203_201003-web.jpg
      20150203_195706-web.jpg

      posted in My Project
      petewill
      petewill
    • How To: Automate Devices with Existing Buttons

      I recently decided to see if I could automate my oven so I could turn it on/off and set the temperature remotely. The oven is electric and has a massive plug going into the wall (I think it's a 30A, 220V but I never checked). I figured the only way I would be comfortable doing this was to "press" the momentary push buttons in the existing circuitry. I did not want to add existing relays or anything of that nature. I thought it would be easy figure out how to "press" existing buttons with an Arduino but it was surprisingly difficult (for me at least) to find any info on the subject. So, I decided to make a how to video in case anyone else wants to attempt a similar project.

      The video is more generic and covers how to simulate a button press with an Arduino instead of a step by step guide on how to automate an oven. It's not specifically related to MySensors but hopefully it will be useful to someone out there who was like me looking to automate a device with pre-existing buttons.

      Video
      "Press" Buttons with Arduino (How to hack and automate your existing device buttons) – 14:46
      — Pete B

      Wiring
      Here is a wiring diagram for each type of switch: ground side and voltage side.
      0_1519332553056_Button-Hack-N-Channel-and-P-Channel.jpg

      MOSFETs
      I used the Alpha & Omega AO3401A (P-Channel) and AO3400 (N-Channel) MOSFETs for this project. They are very cheap. I got 100pcs of each type for around $3 total. Here is an example of where they can be found (but you may want to do some searching for the best price):
      https://www.aliexpress.com/item/Free-shipping-20pcs-SMD-mosfet-transistor-SOT-23-AO3401/32359403044.html?spm=a2g0s.9042311.0.0.ej97EO

      https://www.aliexpress.com/item/Free-shipping-20pcs-SMD-mosfet-transistor-SOT-23-AO3400/32360580221.html?spm=a2g0s.9042311.0.0.ej97EO

      Basic Demo Code

      #include <Bounce2.h>
      
      #define GND_GATE_PIN 3
      #define VCC_GATE_PIN 5
      #define GND_DETECT_PIN 4
      #define VCC_DETECT_PIN 8
      
      #define BUTTON_PRESS_DELAY 100 //The amount of delay used for a button press
      
      //Track button presses
      uint8_t gndValuePrev = 1;
      uint8_t vccValuePrev = 0;
      
      //LED button on/off tracking
      uint8_t gndLedOn = 0;
      uint8_t vccLedOn = 0;
      
      unsigned long gndMillis;
      unsigned long vccMillis;
      
      // Instantiate a Bounce object
      Bounce gndDebouncer = Bounce();
      Bounce vccDebouncer = Bounce();
      
      
      void setup() {
        Serial.begin(115200);
      
        //Setup the pins
        pinMode(GND_GATE_PIN, OUTPUT);
        pinMode(VCC_GATE_PIN, OUTPUT);
        pinMode(GND_DETECT_PIN, INPUT_PULLUP);
        pinMode(VCC_DETECT_PIN, INPUT);
      
        //Start with all outputs (buttons) not enabled (pressed)
        digitalWrite(GND_GATE_PIN, 0);
        digitalWrite(VCC_GATE_PIN, 1);
      
        // After setting up the buttons, setup debouncers
        gndDebouncer.attach(GND_DETECT_PIN);
        gndDebouncer.interval(50);
        vccDebouncer.attach(VCC_DETECT_PIN);
        vccDebouncer.interval(50);
      
      }
      
      void loop() {
        unsigned long currentMillis = millis(); //Get the current millis (used for timers)
      
        // Update the debouncers
        gndDebouncer.update();
        vccDebouncer.update();
      
        // Get the update value
        uint8_t gndValue = gndDebouncer.read();
        uint8_t vccValue = vccDebouncer.read();
      
        if (gndValue != gndValuePrev)
        {
          if (gndValue == 0)
          {
            Serial.println(F("Ground Button Pressed"));
            if (gndLedOn == 0)
            {
              //Don't echo the button push if it was turned on by the Arduino
              gndMillis = currentMillis + 1000;
              gndLedOn = 1;
            }
          }
          gndValuePrev = gndValue;
        }
        if (vccValue != vccValuePrev)
        {
          if (vccValue == 1)
          {
            Serial.println(F("VCC Button Pressed"));
            if (vccLedOn == 0)
            {
              //Don't echo the button push if it was turned on by the Arduino
              vccMillis = currentMillis + 1000;
              vccLedOn = 1;
            }
      
          }
          vccValuePrev = vccValue;
        }
      
        //Turn on led 1 second after button pressed
        if (gndLedOn == 1 && currentMillis > gndMillis)
        {
          nChannelPress(GND_GATE_PIN);
          gndLedOn = 0;
        }
      
        if (vccLedOn == 1 && currentMillis > vccMillis)
        {
          pChannelPress(VCC_GATE_PIN);
          vccLedOn = 0;
        }
      
      }
      
      void pChannelPress(uint8_t buttonPinName)
      {
        //Simulate a button press
        digitalWrite(buttonPinName, 0); //Ground to enable
        delay(BUTTON_PRESS_DELAY);
        digitalWrite(buttonPinName, 1); //VCC to disable
        delay(BUTTON_PRESS_DELAY);
      }
      
      void nChannelPress(uint8_t buttonPinName)
      {
        //Simulate a button press
        digitalWrite(buttonPinName, 1); //VCC to disable
        delay(BUTTON_PRESS_DELAY);
        digitalWrite(buttonPinName, 0); //Ground to enable
        delay(BUTTON_PRESS_DELAY);
      }
      

      In case you're interested, here is the code for my oven project as well as some pictures.

      0_1519331846902_OvenSensor01.jpg
      1_1519331846902_OvenSensor02.jpg
      2_1519331846902_OvenSensor03.jpg
      3_1519331846902_OvenSensor04.jpg
      4_1519331846902_OvenSensor05.jpg
      5_1519331846903_OvenSensor06.jpg

      Oven Code

      /*
         This will control physical buttons on a device.  In my case, an oven.  It will also read
         button presses and send the status back to the controller.  I used 4.7k resistors on the
         P-Channel MOSFET gate pins to hold them high (off) in case there are issues with the
         Arduino.  These can be omitted if you don't care if your switch floats (which you probably
         do).  I used larger resistors (somewhere around 20-30k) to detect a button press.
         These are connected to the drain side of the button/MOSFET
      
         Uses the bounce2 library to debounce the buttons
      
      */
      
      #define SKETCH_NAME "Oven Control"
      #define SKETCH_VERSION "1.0"
      
      // Enable debug prints to serial monitor
      //#define MY_DEBUG //MySensors debug messages
      //#define LOCAL_DEBUG //Code specific debug messages
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_RF24_PA_LEVEL RF24_PA_HIGH //Options: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
      #define MY_RF24_CHANNEL  76
      //#define MY_NODE_ID 1  //Manually set the node ID here. Comment out to auto assign
      
      #include <MySensors.h>
      #include <Bounce2.h>
      
      
      #ifndef BAUD_RATE
      #define BAUD_RATE 115200
      #endif
      
      #ifdef LOCAL_DEBUG
      #define dbg(...)   Serial.print(__VA_ARGS__)
      #define dbgln(...) Serial.println(__VA_ARGS__)
      #else
      #define dbg(x)
      #define dbgln(x)
      #endif
      
      #define DWELL_TIME 50 //value used in all wait calls (in milliseconds) this allows for radio to come back to power after a transmission, ideally 0
      
      #define CHILD_ID_OVEN 0
      
      #define CANCEL_PIN 3
      #define BAKE_PIN 4
      #define UP_PIN 5
      #define DOWN_PIN 6
      #define OVEN_OFF_PIN 7 //GPIO Pin for detecting when the physical "off" button is pressed at the oven
      #define OVEN_ON_PIN 8 //GPIO Pin for detecting when the physical "on" button is pressed at the oven
      
      #define BUTTON_ON 0  // GPIO value to write for simulating a button press (0 for P-Channel MOSFET)
      #define BUTTON_OFF 1 // GPIO value to write for simulating a button not pressed (1 for P-Channel MOSFET)
      #define PRESSED 1 //The value that is received when the physical butons are pressed (1 for P-Channel MOSFET)
      
      #define HEAT_LOW_LIMIT 170 //The lowest temp the heat can be set to
      #define HEAT_HIGH_LIMIT 550 //The highest temp the heat can be set to
      #define OVEN_ON_TEMP 350 //The default temp that the oven is set to when first turned on
      #define DELAY_OVEN_CHANGE 5000 //The amount of time to wait for additional commands from gateway before applying previous commands (give time for user to fine tune temperature)
      #define BUTTON_PRESS_DELAY 100 //The amount of delay used for a button press
      #define TEMP_INCREMENT 5 //Degrees to increment with each button press
      
      MyMessage msgHeatMode(CHILD_ID_OVEN, V_HVAC_FLOW_STATE);
      MyMessage msgHeatSetpoint(CHILD_ID_OVEN, V_HVAC_SETPOINT_HEAT);
      
      uint16_t heatSetPoint = HEAT_LOW_LIMIT; //The current oven heat set point. Default is HEAT_LOW_LIMIT if no value is received from gateway.
      //uint16_t heatSetPointPrev = HEAT_LOW_LIMIT; //The previous oven heat set point. Default is HEAT_LOW_LIMIT if no value is received from gateway.
      uint8_t ovenStatus = 0; //The current status of the oven 1 = on, 0 = off
      uint8_t ovenStatusPrev = 0; //The previous status of the oven 1 = on, 0 = off
      uint8_t ovenStateCommand = 2; //used to track oven on/off commands from controller
      uint8_t receivedCommand = 0; //Used to get config states from controller at start up
      unsigned long commandDelayMillis; //Used to track delay time before the received commands are applied
      unsigned long sendDelayMillis; //Wait to update the controller with on/off status until the automation is done
      
      // Instantiate a Bounce object
      Bounce onDebouncer = Bounce();
      Bounce offDebouncer = Bounce();
      
      
      void before()
      {
      #ifdef LOCAL_DEBUG
        Serial.begin(BAUD_RATE);
      #endif
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway
        sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_OVEN, S_HEATER);
        wait(DWELL_TIME);
        //metric = getConfig().isMetric; //This has been removed as it will default to metric if connection to the gateway is not established (bad for imperial users)
        //wait(DWELL_TIME);
      }
      
      void setup() {
        //Setup the pins
        pinMode(CANCEL_PIN, OUTPUT);
        pinMode(BAKE_PIN, OUTPUT);
        pinMode(UP_PIN, OUTPUT);
        pinMode(DOWN_PIN, OUTPUT);
        pinMode(OVEN_ON_PIN, INPUT);
        pinMode(OVEN_OFF_PIN, INPUT);
      
        //Start with all outputs (buttons) not enabled (pressed)
        digitalWrite(CANCEL_PIN, BUTTON_OFF);
        digitalWrite(BAKE_PIN, BUTTON_OFF);
        digitalWrite(UP_PIN, BUTTON_OFF);
        digitalWrite(DOWN_PIN, BUTTON_OFF);
      
        // After setting up the buttons, setup debouncers
        onDebouncer.attach(OVEN_ON_PIN);
        onDebouncer.interval(1);
        offDebouncer.attach(OVEN_OFF_PIN);
        offDebouncer.interval(5);
      
        uint8_t reqCounter = 0;
        while (receivedCommand == 0)
        {
          dbgln("Requesting heat setpoint");
          request(CHILD_ID_OVEN, V_HVAC_SETPOINT_HEAT); //Request state from gateway
          wait(500);
          reqCounter++;
          if (reqCounter > 5)
          {
            dbgln("Failed to get heat setpoint!");
            break;
          }
        }
        wait(5000); //Wait for 10 seconds to give time for commands to be received (so the oven doesn't turn on when the microcontroller starts)
        receivedCommand = 0;
      }
      
      void loop() {
        unsigned long currentMillis = millis(); //Get the current millis (used for timers)
      
        // Update the debouncers
        onDebouncer.update();
        offDebouncer.update();
      
      
        // Get the update value
        uint8_t onValue = onDebouncer.read();
        uint8_t offValue = offDebouncer.read();
      
        if (onValue == 1)
        {
          ovenStatus = 1;
          sendDelayMillis = currentMillis;
          dbgln(F("On Pressed"));
        }
        if (offValue == 1)
        {
          ovenStatus = 0;
          sendDelayMillis = currentMillis;
          dbgln(F("Off Pressed"));
        }
      
        if (ovenStatus != ovenStatusPrev && currentMillis - sendDelayMillis > 1000)
        {
          //Send new ovenStatus to gateway
          send(msgHeatMode.set(ovenStatus == 1 ? "HeatOn" : "Off"));
          dbgln(ovenStatus);
          ovenStatusPrev = ovenStatus;
        }
      
      
        if (receivedCommand)
        {
          //Received a command to turn on/off the oven
          if (ovenStateCommand == 0)
          {
            //Turn off the oven right away (no delay necessary)
            buttonPress(CANCEL_PIN);
            receivedCommand = 0;
            ovenStateCommand = 2; //Set to some number other than 1 or 0 to allow oven to be adjusted when the heatSetPoint changed
            ovenStatus = 0;
          }
          else
          {
            //We need to turn on and/or change the temp but we want to wait for all the commands to come in first (DELAY_OVEN_CHANGE time)
            if (currentMillis - DELAY_OVEN_CHANGE > commandDelayMillis)
            {
              if (ovenStateCommand == 1 || ovenStatus == 1)
              {
                //The oven is either on or should be on. Since we are not keeping track of the temperature
                //we need to turn the oven off then back on to ensure we get the correct temp
                buttonPress(CANCEL_PIN);
                //Now, turn it on and adjust the temp to the correct setting
                buttonPress(BAKE_PIN);
                wait(BUTTON_PRESS_DELAY * 2); //wait for the oven to turn on before adjusting temp
                buttonPress(UP_PIN); //Oven starts at 0 so we need to press a button to start at OVEN_ON_TEMP
                wait(BUTTON_PRESS_DELAY * 2);
                uint16_t tempChange = OVEN_ON_TEMP;
                if (heatSetPoint < OVEN_ON_TEMP)
                {
                  //The temp should be adjusted lower (also rounding to nearest TEMP_INCREMENT)
                  while (tempChange > heatSetPoint + (TEMP_INCREMENT / 2))
                  {
                    buttonPress(DOWN_PIN);
                    wait(BUTTON_PRESS_DELAY);
                    dbg(F("Lowered temp to: "));
                    dbgln(tempChange);
                    tempChange -= TEMP_INCREMENT;
                  }
                }
                else
                {
                  //The temp should be adjusted lower (also rounding to nearest TEMP_INCREMENT)
                  while (tempChange < heatSetPoint - (TEMP_INCREMENT / 2))
                  {
                    buttonPress(UP_PIN);
                    wait(BUTTON_PRESS_DELAY * 2);
                    dbg(F("Raised temp to: "));
                    dbgln(tempChange);
                    tempChange += TEMP_INCREMENT;
                  }
                }
                send(msgHeatSetpoint.set(tempChange)); //Send value to gateway
                ovenStatus = 1;
              }
              receivedCommand = 0;
              ovenStateCommand = 2; //Set to some number other than 1 or 0 to allow oven to be adjusted when the heatSetPoint changed
      
            }
          }
        }
      }
      
      void receive(const MyMessage &message)
      {
        dbg(F("msg data: "));
        dbgln(String(message.data));
      
        if (message.isAck()) {
          dbgln(F("Ack from gateway"));
        }
      
        if (message.type == V_HVAC_FLOW_STATE && !message.isAck()) {
      
          //find the mode
          if (String(message.data) == "Off")
          {
            ovenStateCommand = 0;
          }
          else if (String(message.data) == "HeatOn")
          {
            ovenStateCommand = 1;
          }
          else
          {
            dbgln(F("Invalid state received"));
          }
          dbg(F("Oven state: "));
          dbgln(ovenStateCommand);
          commandDelayMillis = millis();
          receivedCommand = 1;
        }
      
      
        if (message.type == V_HVAC_SETPOINT_HEAT && !message.isAck()) {
      
          uint16_t value = atoi(message.data);
          if (value < HEAT_LOW_LIMIT)
          {
            heatSetPoint = HEAT_LOW_LIMIT;
          }
          else if (value > HEAT_HIGH_LIMIT)
          {
            heatSetPoint = HEAT_HIGH_LIMIT;
          }
          else
          {
            heatSetPoint = value;
          }
          dbg(F("Heat setpoint: "));
          dbgln(heatSetPoint);
      
          commandDelayMillis = millis();
          receivedCommand = 1;
        }
      }
      
      void buttonPress(uint8_t buttonPinName)
      {
        //Simulate a button press
        digitalWrite(buttonPinName, BUTTON_ON);
        wait(BUTTON_PRESS_DELAY);
        digitalWrite(buttonPinName, BUTTON_OFF);
        wait(BUTTON_PRESS_DELAY);
      }
      
      posted in My Project
      petewill
      petewill
    • Cheap voice control using AutHomation, AutoVoice and Tasker (Video)

      Hey Everyone,

      This doesn't pertain directly to MySensors but I know that some people out there use Vera like me (this could work for other controllers too as long as they have a plugin for Tasker). I made a 'how to" video on controlling your home with your voice. The control isn't always perfect but it's an easy and cheap solution! Hope it helps someone.

      On a side note, this is the most fun hobby I have had in a long time. I feel like a kid building a fort again 🙂

      Voice Control of Home Automation with Android (How To) – 14:13
      — Pete B

      posted in Vera
      petewill
      petewill
    • RE: What did you build today (Pictures) ?

      My son and I finally finished his first MySensors project- a remote control for his room. He wasn't too interested but you have to start somewhere right...? 🙂
      Question for you all... what are you doing (if anything) to vent the fumes from soldering? I haven't really been worried about it in the past but it makes me nervous with my son doing it with me.
      Anyway, here are the pictures.

      0_1518837057065_IMG_20180216_171013.jpg
      0_1518837070467_IMG_20180216_171125.jpg
      0_1518837089935_IMG_20180216_171709.jpg

      posted in General Discussion
      petewill
      petewill
    • RE: 💬 Rain Gauge

      I am currently upgrading my devices to 2.0 using the 1.6.12 IDE. I'll try to work on this one in the next few days and post an update.

      posted in Announcements
      petewill
      petewill
    • RE: Still not going well for me.

      @Coffeesnob Yeah, I would order a couple of Nanos (or Pro Minis). They are cheap and are always helpful for troubleshooting.
      Here is how I have my devices wired:
      0_1485012164542_upload-fb984670-b18c-497b-9167-e19bfd517a28
      *need to configure these pins in the sketch

      Here is the code you will need to configure the sketch of the Mega. Make sure to put these lines above the #include <MySensors.h> line.
      #define MY_RF24_CE_PIN 49
      #define MY_RF24_CS_PIN 53
      You should not need to change anything in MyConfig.h if you wire as described above.

      The Nano can be wired as described above and no changes need to be made in your sketch or MyConfig.h. This code assumes you are using MySensors 2.x.

      I hope that makes sense.

      As for a MYSController video, I'm not aware of any out there yet. I have it on my list of videos to make but it's not at the top...

      posted in Troubleshooting
      petewill
      petewill
    • RE: 💬 Rain Gauge

      I finally finished with the update and it has been merged to the MySensors github. Here is the link: https://github.com/mysensors/MySensorsArduinoExamples/tree/master/examples/RainGauge
      You will also need to download the updated Time library here: https://github.com/mysensors/MySensorsArduinoExamples/tree/master/libraries/Time

      Let me know if you run into any issues.

      posted in Announcements
      petewill
      petewill
    • RE: Controlling Blinds.com RF Dooya Motors with Arduino and Vera

      @C.r.a.z.y. Yeah, I couldn't get the automatic "sniffers" to work for me either. Hopefully you're able to get it working. Remember, just focus on sending the 1's and 0's pattern. Start your code with that then expand when you get that part working. One thing that may help is to record what you're sending in Audacity again. That way you can compare the waveforms and see what needs to be modified with the code.

      posted in My Project
      petewill
      petewill
    • RE: [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.

      @Nicklas-Starkel I recently updated my Mega sensor (that had been running for months without any issues) to 2.1 and experienced issues with NACKs too. It would work for a little while (half a day or so) then the NACKs would start appearing. A few hours after the NACKs showed up it would then only produce NACKs. I seemed to have finally resolved the issue by switching the 4.7uF capacitor with a 47uF on the NRF radio. It has been running for 3 days without a single NACK. I know it's not the same issue you're having but maybe something to try. By the way, the capacitor is soldered right to the radio pin headers.

      posted in Troubleshooting
      petewill
      petewill
    • RE: Rain Guage

      @BulldogLowell said:

      their four-byte size on arduino make for a huge eeprom storage buffer that we really don't need

      Good to know! I still have a lot to learn about all this stuff. It's definitely fun.

      terrific, glad to see it make its way into the real world!

      Yes, me too! I'm happy to report it's working. It rained 6.4mm last night. SO COOL!

      posted in My Project
      petewill
      petewill
    • Video How To - Monitor your Smoke/Carbon Monoxide Alarm

      Hey Everyone,

      I finally had a chance to make @ServiceXp's awesome Smoke Alarm monitoring project and I thought I'd make a how to video. I am making a separate forum post because my code is a little different to account for detecting Carbon Monoxide. But you should check out his original post (http://forum.mysensors.org/topic/934/mysensoring-a-kidde-smoke-detector-completed) for more details. His method is more universal so if this method doesn't work with your alarm his probably will. Thanks for making this possible @ServiceXp!

      Also, credit goes to http://www.edcheung.com/automa/smoke_det.htm for info on how to use the interconnect feature.

      Ok, here is the additional info:
      How To - Smoke Alarm Monitoring with Arduino and MySensors – 11:01
      — Pete B

      Fritzing Smoke Detector Wiring - Actual.png

      /*
       *  Based on Author: Patrick 'Anticimex' Fallberg Interrupt driven binary switch example with dual interrupts
       *  Code by 'ServiceXP'
       *  Modified by 'PeteWill to add CO detection
       *  For more info on how to use this code check out this video: https://youtu.be/mNsar_e8IsI
       *  
       */
      
      #include <MySensor.h>
      #include <SPI.h>
      
      #define SKETCH_NAME "Smoke Alarm Sensor"
      #define SKETCH_MAJOR_VER "1"
      #define SKETCH_MINOR_VER "1"
      #define NODE_ID 11 //or AUTO to let controller assign
      
      #define SMOKE_CHILD_ID 0
      #define CO_CHILD_ID 1
      
      #define SIREN_SENSE_PIN 3   // Arduino Digital I/O pin for optocoupler for siren
      #define DWELL_TIME 125  // this allows for radio to come back to power after a transmission, ideally 0 
      
      unsigned int SLEEP_TIME         = 32400; // Sleep time between reads (in seconds) 32400 = 9hrs
      byte CYCLE_COUNTER                  = 2;  // This is the number of times we want the Counter to reach before triggering a CO signal to controller (Kidde should be 2).
      byte CYCLE_INTERVAL        = 2; // How long do we want to watch for smoke or CO (in seconds). Kidde should be 2
      
      byte oldValue;
      byte coValue;
      byte smokeValue;
      
      MySensor sensor_node;
      MyMessage msgSmoke(SMOKE_CHILD_ID, V_TRIPPED);
      MyMessage msgCO(CO_CHILD_ID, V_TRIPPED);
      
      void setup()
      {
        sensor_node.begin(NULL, NODE_ID);
        // Setup the Siren Pin HIGH
        pinMode(SIREN_SENSE_PIN, INPUT_PULLUP);
        // Send the sketch version information to the gateway and Controller
        sensor_node.sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER"."SKETCH_MINOR_VER);
        sensor_node.present(SMOKE_CHILD_ID, S_SMOKE);
        sensor_node.present(CO_CHILD_ID, S_SMOKE);
      }
      
      // Loop will iterate on changes on the BUTTON_PINs
      void loop()
      {
        // Check to see if we have a alarm. I always want to check even if we are coming out of sleep for heartbeat.
        AlarmStatus();
        // Sleep until we get a audio power hit on the optocoupler or 9hrs
        sensor_node.sleep(SIREN_SENSE_PIN - 2, CHANGE, SLEEP_TIME * 1000UL);
      }
      
      void AlarmStatus()
      {
      
        // We will check the status now, this could be called by an interrupt or heartbeat
        byte value;
        byte wireValue;
        byte previousWireValue;
        byte siren_low_count   = 0;
        byte siren_high_count   = 0;
        unsigned long startedAt = millis();
      
        Serial.println("Status Check");
        //Read the Pin
        value = digitalRead(SIREN_SENSE_PIN);
        // If Pin returns a 0 (LOW), then we have a Alarm Condition
        if (value == 0)
        {
          //We are going to check signal wire for CYCLE_INTERVAL time
          //This will be used to determine if there is smoke or carbon monoxide
          while (millis() - startedAt < CYCLE_INTERVAL * 1000)
          {
            wireValue = digitalRead(SIREN_SENSE_PIN);
            if (wireValue != previousWireValue)
            {
              if (wireValue == 0)
              {
                siren_low_count++;
                Serial.print("siren_low_count: ");
                Serial.println(siren_low_count);
              }
              else
              {
                siren_high_count++;
                Serial.print("siren_high_count: ");
                Serial.println(siren_high_count);
              }
              previousWireValue = wireValue;
            }
          }
          // Eval siren hit count against our limit. If we are => then CYCLE_COUNTER then there is Carbon Monoxide
          if (siren_high_count >= CYCLE_COUNTER)
          {
            Serial.println("CO Detected");
            //Check to make sure we haven't already sent an update to controller
            if (coValue == 0 )
            {
              //update gateway CO is detected.
              sensor_node.send(msgCO.set("1"));
              Serial.println("CO Detected sent to gateway");
              coValue = 1;
            }
          }
          else
          {
            Serial.println("Smoke Detected");
            //Check to make sure we haven't already sent an update to controller
            if (smokeValue == 0 )
            {
              //update gateway smoke is detected.
              sensor_node.send(msgSmoke.set("1"));
              Serial.println("Smoke Detected sent to gateway");
              smokeValue = 1;
            }
          }
          oldValue = value;
          AlarmStatus(); //run AlarmStatus() until there is no longer an alarm
        }
        //Pin returned a 1 (High) so there is no alarm.
        else
        {
          //If value has changed send update to gateway.
          if (oldValue != value)
          {
            //Send all clear msg to controller
            sensor_node.send(msgSmoke.set("0"));
            sensor_node.wait(DWELL_TIME); //allow the radio to regain power before transmitting again
            sensor_node.send(msgCO.set("0"));
            oldValue = value;
            smokeValue = 0;
            coValue = 0;
            Serial.println("No Alarm");
          }
        }
      }
      posted in My Project
      petewill
      petewill
    • RE: Computer power supply as 12/5/3.3V whole house power supply

      @m26872 said:

      We should ping @petewill then. 😄

      Sorry for the delay! I didn't see this until now.

      I am using a computer power supply for most of my projects. I use both the 12V and 5V but haven't had a need for the 3.3V yet. I have 12V cable runs that are probably 60-70ft and I have had no issues powering my blinds and various LED projects for the last 2+ years. I am using the 5V for motion sensors, irrigation controller, rain gauge, etc all over my house and have also had no issues with them. Depending on the size of your house it is a very cheap way to get good power (in my opinion). I am using an old (free) 220 watt power supply.

      For protection I have fuse blocks between the sensors and the power supply.

      Here is an old, poor quality picture of my setup.

      0_1468849187552_20150210_202501.jpg

      posted in My Project
      petewill
      petewill
    • RE: Computer power supply as 12/5/3.3V whole house power supply

      @csa02221862 Working on it now. Hopefully I'll have it finished within the week.

      posted in My Project
      petewill
      petewill
    • RE: [beta] AliExpress prices in shop

      Great new feature to see price comparisons! Thanks!

      Just a quick buyer beware warning on AliExpress. I orders some Arduino Pro Minis and found they were made with 3.3v regulators when they were supposed to be 5v. I contacted the seller and they said I was wrong. After 4 messages proving I wasn't, I never heard from them again. I couldn't even change my review of the seller because AliExpress doesn't allow it.

      eBay has been so much better. I had an item damaged in shipping and the seller responded right away and offered to send a new one or give a discount on the damaged item.

      posted in Announcements
      petewill
      petewill
    • RE: Laser Christmas Light Control - 433MHZ

      You're almost there! You need to change this line:

      MyMessage msg(RED_CONTROLLER,S_LIGHT);
      

      to this

      MyMessage msg(RED_CONTROLLER,V_LIGHT);
      
      posted in General Discussion
      petewill
      petewill
    • RE: 💬 Bed Occupancy Sensor

      @Oitzu As long as it's consensual 😉

      @Dwalt

      but exactly where are the sensor tapes placed?

      We have them placed under the sheets and mattress pad. When it is under the mattress pad nothing is disturbed when changing the sheets. I don't think it would work under the mattress unless it was really thin. I didn't do any testing on the max depth that it can sense but I would guess it's no more than 1".

      @aproxx

      Have you ever considered adding a weight/pressure sensor underneath the legs of your bed?

      Yes, I actually have all the components to build a weight sensor sitting on my desk. I had originally planned to use them instead of the mpr121. The reason I didn't pursue it very far is I have a really heavy bed, I would have had to develop some custom platform for it to sit on and it costs more. So, to sum it up the capacitive sensor is easier and cheaper so I went with that method instead.

      posted in OpenHardware.io
      petewill
      petewill
    • RE: Controlling Blinds.com RF Dooya Motors with Arduino and Vera

      Here is the updated code for 1.4 if anyone needs it...
      https://codebender.cc/sketch:67780

      posted in My Project
      petewill
      petewill
    • RE: 💬 Rain Gauge

      @itbeyond said in 💬 Rain Gauge:

      I needed this on my irrigation controller also - same problem with a 10cm cable to a push button.

      Interesting. I haven't experienced this behavior with any of my devices yet. I do power most of my sensors with my whole house power supply though so I guess that would explain it.

      I will update the rain gauge page and also add this info to the troubleshooting section. Thanks for your help with this!

      If anyone needs a visual of what @itbeyond described above here is the wiring diagram.

      0_1495740779599_Hardware-Debounce-False-Interrupt-Fix.jpg

      posted in Announcements
      petewill
      petewill
    • RE: Send msg in background

      @zsakul I know this is really late but I was just doing a search and came across your post. Hopefully you have found the solution but if not you need to put "#define MY_TRANSPORT_DONT_CARE_MODE" above #include <MySensors.h> in your code. Also, MY_TRANSPORT_DONT_CARE_MODE has been replaced by MY_TRANSPORT_WAIT_READY_MS 1 in the most recent version.

      posted in General Discussion
      petewill
      petewill
    • RE: 💬 Bed Occupancy Sensor

      @Inso Unless there is another use for a PIR that I'm not aware of, a PIR will detect motion and when I'm sleeping I'm not doing much moving. 🙂 With this sensor it knows when I'm in bed so the lights don't turn on and the blinds don't go up. Hopefully that makes sense.

      posted in OpenHardware.io
      petewill
      petewill
    • RE: Rain Guage

      @BulldogLowell said:

      it looks a lot like a bonehead error in the code!!

      Ok, thanks. I make those constantly...

      I have been testing the code for the last couple of days and I think this is working but another set of eyes would be good. I added functionality to set the "calibrateFactor" to a decimal. I also updated the save/load EEPROM to work with the MySensors standard. It seems to be working in my testing but I'm no programmer.

      I also have two questions:

      1. Is it necessary to save/load "state" to/from EEPROM? It seems that from my testing the state is set when "measure" is calculated in this line: state = (measure >= rainSensorThreshold);. It seems that measure is evaluated when the sensor first loads and rainBucket [] is loaded from EEPROM. Hopefully that makes sense what I'm asking.

      2. I'm still trying to understand interrupts but I'm wondering if changing to "FALLING" would be more appropriate? Maybe it doesn't matter but I thought I'd check. Here is the line I'm referring to: attachInterrupt (1, sensorTipped, FALLING);

      Here is the code if you wanted to take a look:

       /*
       Arduino Tipping Bucket Rain Gauge
       
       April 26, 2015
      
       Version 1.01b for MySensors version 1.4.1
      
       Arduino Tipping Bucket Rain Gauge
      
       Utilizing a tipping bucket sensor, your Vera home automation controller and the MySensors.org
       gateway you can measure and sense local rain.  This sketch will create two devices on your
       Vera controller.  One will display your total precipitation for the last 24, 48, 72, 96 and 120
       hours.  The other, a sensor that changes state if there is recent rain (up to last 120 hours)
       above a threshold.  Both these settings are user definable.
      
       This sketch features the following:
      
       * Allows you to set the rain threshold in mm
       * Allows you to determine the interval window up to 120 hours.
       * Displays the last 24, 48, 72, 96 and 120 hours total rain in Variable1 through Variable5
         of the Rain Sensor device
       * Configuration changes to Sensor device updated every 3 hours.
       * SHould run on any Arduino
       * Will retain Tripped/Not Tripped status and data in a power outage, saving small ammount
         of data to EEPROM (Circular Buffer to maximize life of EEPROM)
       * There is a unique setup requirement necessary in order to properly present the Vera device
         variables.  The details are outlined in the sketch below.
       * LED status indicator
      
       by BulldogLowell@gmail.com for free public use
      
       */
      #include <SPI.h>
      #include <MySensor.h>
      
      //*No longer need the EEPROM.h?
      //#include <EEPROM.h>
      
      #define NODE_ID 24
      #define SN "Rain Gauge"
      #define SV "1.01b"
      
      #define CHILD_ID_RAIN 3 
      #define CHILD_ID_TRIPPED_RAIN 4
      
      #define STATE_LOCATION 0 // location to save state to EEPROM
      #define EEPROM_BUFFER 1  // location of the EEPROM circular buffer
      #define BUFFER_LENGTH 121  // buffer plus the current hour
      //
      MySensor gw;
      //
      MyMessage msgRainRate(CHILD_ID_RAIN, V_RAINRATE);
      MyMessage msgRain(CHILD_ID_RAIN, V_RAIN);
      MyMessage msgRainVAR1(CHILD_ID_RAIN, V_VAR1);
      MyMessage msgRainVAR2(CHILD_ID_RAIN, V_VAR2);
      MyMessage msgRainVAR3(CHILD_ID_RAIN, V_VAR3);
      MyMessage msgRainVAR4(CHILD_ID_RAIN, V_VAR4);
      MyMessage msgRainVAR5(CHILD_ID_RAIN, V_VAR5);
      
      MyMessage msgTripped(CHILD_ID_TRIPPED_RAIN, V_TRIPPED);
      MyMessage msgTrippedVar1(CHILD_ID_TRIPPED_RAIN, V_VAR1);
      MyMessage msgTrippedVar2(CHILD_ID_TRIPPED_RAIN, V_VAR2);
      //
      boolean metric = false;
      //
      int eepromIndex;
      int tipSensorPin = 3; //Do not change (needed for interrupt)
      int ledPin = 5; //PWM capable required
      unsigned long dataMillis;
      unsigned long serialInterval = 10000UL;
      const unsigned long oneHour = 3600000UL;
      unsigned long lastTipTime;
      unsigned long lastBucketInterval;
      unsigned long startMillis;
      
      float rainBucket [120] ; // 5 days of data  //*120 hours = 5 days
      
      float calibrateFactor = .7; //Calibration in milimeters of rain per single tip.  Note: Limit to one decimal place or data may be truncated when saving to eeprom. 
      
      float rainRate = 0;
      volatile int tipBuffer = 0;
      byte rainWindow = 72;         //default rain window in hours
      int rainSensorThreshold = 10; //default rain sensor sensitivity in mm.  Will be overwritten with msgTrippedVar2. 
      byte state = 0;
      byte oldState = -1;
      //
      void setup()
      {
        gw.begin(getVariables, NODE_ID);
      
        pinMode(tipSensorPin, INPUT);
      
      //  attachInterrupt (1, sensorTipped, CHANGE); //* should this be FALLING instead??
        attachInterrupt (1, sensorTipped, FALLING);
        pinMode(ledPin, OUTPUT);
        digitalWrite(ledPin, HIGH);
        digitalWrite(tipSensorPin, HIGH); //ADDED. Activate internal pull-up 
        gw.sendSketchInfo(SN, SV);
        gw.present(CHILD_ID_RAIN, S_RAIN);
        gw.present(CHILD_ID_TRIPPED_RAIN, S_MOTION);
      //  Serial.println(F("Sensor Presentation Complete"));
        
      
        state = gw.loadState(STATE_LOCATION); //retreive prior state from EEPROM
      //  Serial.print("Tripped State (from EEPROM): ");
      //  Serial.println(state);
        
        gw.send(msgTripped.set(state==1?"1":"0"));
        delay(250);                             // recharge the capacitor
        //
        boolean isDataOnEeprom = false;
        for (int i = 0; i < BUFFER_LENGTH; i++)
        {
      
          byte locator = gw.loadState(EEPROM_BUFFER + i); //New code
      
          if (locator == 0xFF)  // found the EEPROM circular buffer index
          {
            eepromIndex = EEPROM_BUFFER + i;
            //Now that we have the buffer index let's populate the rainBucket with data from eeprom
            loadRainArray(eepromIndex); 
            isDataOnEeprom = true;
      //      Serial.print("EEPROM Index ");
      //      Serial.println(eepromIndex);
            break;
          }
        }
      
        // reset the timers
        dataMillis = millis();
        startMillis = millis();
        lastTipTime = millis() - oneHour;  //will this work if millis() starts a 0??
        gw.request(CHILD_ID_TRIPPED_RAIN, V_VAR1); //Get rainWindow from controller (Vera)
        delay(250);
        gw.request(CHILD_ID_TRIPPED_RAIN, V_VAR2); //Get rainSensorThreshold from controller (Vera)
        delay(250);
      //  Serial.println("Radio Done");
      //  analogWrite(ledPin, 20);
      
      }
      //
      void loop()
      {
        gw.process();
        pulseLED();
      
        //
        // let's constantly check to see if the rain in the past rainWindow hours is greater than rainSensorThreshold
        //
      
        float measure = 0; // Check to see if we need to show sensor tripped in this block
      
        for (int i = 0; i < rainWindow; i++)
        {
          measure += rainBucket [i];
      //    Serial.print("measure value (total rainBucket within rainWindow): ");
      //    Serial.println(measure);
        }
        state = (measure >= rainSensorThreshold);
      
        if (state != oldState)
        {
          gw.send(msgTripped.set(state==1?"1":"0"));
          delay(250);
          gw.saveState(STATE_LOCATION, state); //New Code
      //    Serial.print("State Changed. Tripped State: ");
      //    Serial.println(state);
          
          oldState = state;
        }
        //
        // Now lets reset the rainRate to zero if no tips in the last hour
        //
        if (millis() - lastTipTime >= oneHour)// timeout for rain rate
        {
          if (rainRate != 0)
          {
            rainRate = 0;
            gw.send(msgRainRate.set(0));
            delay(250);
          }
        }
      
      ////////////////////////////
      ////Comment back in this block to enable Serial prints
      //  
      //  if ( (millis() - dataMillis) >= serialInterval)
      //  {
      //    for (int i = 24; i <= 120; i = i + 24)
      //    {
      //      updateSerialData(i);
      //    }
      //    dataMillis = millis();
      //  }
      //  
      ////////////////////////////
        
        
        if (tipBuffer > 0)
        {
      //     Serial.println("Sensor Tipped");
          
      
          //******Added calibrateFactor calculations here to account for calibrateFactor being different than 1
          rainBucket [0] += calibrateFactor;
      //    Serial.print("rainBucket [0] value: ");
      //    Serial.println(rainBucket [0]);
          
          if (rainBucket [0] * calibrateFactor > 253) rainBucket[0] = 253; // odd occurance but prevent overflow}}
      
          float dayTotal = 0;
          for (int i = 0; i < 24; i++)
          {
            dayTotal = dayTotal + rainBucket [i];
          }
          
      //    Serial.print("dayTotal value: ");
      //    Serial.println(dayTotal);
          
          gw.send(msgRain.set(dayTotal,1));
          delay(250);
          unsigned long tipDelay = millis() - lastTipTime;
          if (tipDelay <= oneHour)
          {
      
            rainRate = ((oneHour) / tipDelay) * calibrateFactor; //Is my math/logic correct here??
        
            gw.send(msgRainRate.set(rainRate, 1));
      
      //      Serial.print("RainRate= ");
      //      Serial.println(rainRate);
          }
      
          //If this is the first trip in an hour send .1
          else
          {
            gw.send(msgRainRate.set(0.1, 1));
          }
          lastTipTime = millis();
          tipBuffer--;
        }
        if (millis() - startMillis >= oneHour)
        {
      //    Serial.println("One hour elapsed.");
          //EEPROM write last value
          //Converting rainBucket to byte.  Note: limited to one decimal place.
          //Can this math be simplified?? 
          float convertRainBucket = rainBucket[0] * 10;
          if (convertRainBucket  > 253) convertRainBucket = 253; // odd occurance but prevent overflow
          byte eepromRainBucket = (byte)convertRainBucket;
          gw.saveState(eepromIndex, eepromRainBucket);
      
          eepromIndex++;
          if (eepromIndex > EEPROM_BUFFER + BUFFER_LENGTH) eepromIndex = EEPROM_BUFFER;
      //    Serial.print("Writing to EEPROM.  Index: ");
      //    Serial.println(eepromIndex);
          gw.saveState(eepromIndex, 0xFF);
          
          for (int i = BUFFER_LENGTH - 1; i >= 0; i--)//cascade an hour of values
          {
            rainBucket [i + 1] = rainBucket [i];
          }
          rainBucket[0] = 0;
          gw.send(msgRain.set(tipCounter(24),1));// send 24hr tips
          delay(250);
          transmitRainData(); // send all of the 5 buckets of data to controller
          startMillis = millis();
        }
      }
      //
      void sensorTipped()
      {
        static unsigned long last_interrupt_time = 0;
        unsigned long interrupt_time = millis();
        if (interrupt_time - last_interrupt_time > 200)
        {
          tipBuffer++;
        }
        last_interrupt_time = interrupt_time;
      }
      //
      float tipCounter(int hours)
      {
        float tipCount = 0;
        for ( int i = 0; i < hours; i++)
        {
          tipCount = tipCount + rainBucket [i];
        }
        return tipCount;
      }
      //
      void updateSerialData(int x)
      {
        Serial.print(F("Tips last "));
        Serial.print(x);
        Serial.print(F(" hours: "));
        float tipCount = 0;
        for (int i = 0; i < x; i++)
        {
          tipCount = tipCount + rainBucket [i];
        }
        Serial.println(tipCount);
      }
      void loadRainArray(int value)
      {
        for (int i = 0; i < BUFFER_LENGTH - 1; i++)
        {
          value--;
          Serial.print("EEPROM location: ");
          Serial.println(value);
          if (value < EEPROM_BUFFER)
          {
            value = EEPROM_BUFFER + BUFFER_LENGTH;
          }
          float rainValue = gw.loadState(value);
      
          if (rainValue < 255)
          {
            //Convert back to decimal value
            float decimalRainValue = rainValue/10;
            rainBucket[i] = decimalRainValue;
          }
          else
          {
            rainBucket [i] = 0;
          }
      //    Serial.print("rainBucket[ value: ");
      //    Serial.print(i);
      //    Serial.print("] value: ");
      //    Serial.println(rainBucket[i]);
        }
      }
      
      void transmitRainData(void)
      {
        float rainUpdateTotal = 0;
        for (int i = 0; i < 24; i++)
        {
          rainUpdateTotal += rainBucket[i];
        }
        gw.send(msgRainVAR1.set(rainUpdateTotal,1));
        delay(250);
        for (int i = 24; i < 48; i++)
        {
          rainUpdateTotal += rainBucket[i];
        }
        gw.send(msgRainVAR2.set(rainUpdateTotal,1));
        delay(250);
        for (int i = 48; i < 72; i++)
        {
          rainUpdateTotal += rainBucket[i];
        }
        gw.send(msgRainVAR3.set(rainUpdateTotal,1));
      
        delay(250);
        for (int i = 72; i < 96; i++)
        {
          rainUpdateTotal += rainBucket[i];
        }
        gw.send(msgRainVAR4.set(rainUpdateTotal,1));
      
        delay(250);
        for (int i = 96; i < 120; i++)
        {
          rainUpdateTotal += rainBucket[i];
        }
        gw.send(msgRainVAR5.set(rainUpdateTotal,1));
        delay(250);
      }
      
      void getVariables(const MyMessage &message)
      {
        if (message.sensor == CHILD_ID_RAIN)
        {
          // nothing to do here
        }
        else if (message.sensor == CHILD_ID_TRIPPED_RAIN)
        {
          if (message.type == V_VAR1)
          {
            rainWindow = atoi(message.data);
            if (rainWindow > 120)
            {
              rainWindow = 120;
            }
            else if (rainWindow < 6)
            {
              rainWindow = 6;
            }
            if (rainWindow != atoi(message.data))   // if I changed the value back inside the boundries, push that number back to Vera
            {
              gw.send(msgTrippedVar1.set(rainWindow));
            }
          }
          else if (message.type == V_VAR2)
          {
            rainSensorThreshold = atoi(message.data);
            if (rainSensorThreshold > 1000)
            {
              rainSensorThreshold = 1000;
            }
            else if (rainSensorThreshold < 1)
            {
              rainSensorThreshold = 1;
            }
            if (rainSensorThreshold != atoi(message.data))  // if I changed the value back inside the boundries, push that number back to Vera
            {
              gw.send(msgTrippedVar2.set(rainSensorThreshold));
            }
          }
        }
      }
      void pulseLED(void)
      {
        static boolean ledState = true;
        static unsigned long pulseStart = millis();
        if (millis() - pulseStart < 500UL)
        {
          digitalWrite(ledPin, !ledState);
          pulseStart = millis();
        }
      }
      posted in My Project
      petewill
      petewill
    • RE: Antenna 101

      I posted about this earlier but I think it was lost.

      Disclaimer: I am no expert but this seems to be working for me... I have been experimenting with adding a wire to my regular nRF24L01 radio chips. I have the chips with the zig zag patteren. Based on some limited reading the wavelength is of 2.4 GHz is 4.92 inches (http://www.antenna-theory.com/definitions/2p4GHzAntenna.php). I did some rough measurements of the zig zag pattern with micrometer and found that the length is about 1.64 inches. So, based on that I soldered a 3.28 inch piece of CAT5e to the end of the zig zag pattern.

      I had a new node that I installed on Sunday night that wasn't communicating with the gateway at all. I replaced the nRF24L01 with my modified one on Monday night and it has been communicating perfectly all night.

      I should probably note that my new node had the radio zig zag pattern parallel to the ground which may have also caused some of the communication problems. I wasn't able to easily move the orientation because of how it was mounted, so the antenna was a quick test that appears to have solved the problem.

      I have another node in which I have achieved similar results in a totally different part of my house.

      Note: this also seems to be working for other people. See the comments of this blog post:http://harizanov.com/2013/06/nrf24l01-range-testing/

      Based on the above post the PA+SMA antenna still has better range, but the CAT5 hack is much cheaper 🙂

      I'd be interested to hear if this works for anyone else.

      Pete

      posted in Hardware
      petewill
      petewill
    • RE: Send msg in background

      @zsakul Try downloading the latest version from github. The master branch will be updated to version 2.1 very soon and I recommend waiting for that. https://github.com/mysensors/MySensors/tree/master

      Once you have updated you should be able to use MY_TRANSPORT_WAIT_READY_MS in your code. I have it working in my device.

      You could change MY_TRANSPORT_WAIT_READY_MS in the myconfig.h file but if you do it there every node you build will have this setting (which my not be desired).

      posted in General Discussion
      petewill
      petewill
    • RE: Windows GUI/Controller for MySensors

      @samuel235 said:

      Now when i come to update the sketch using FTDI

      I think you are supposed to be uploading the sketches OTA and they won't upload via USB anymore (unless I missed an update, which is possible).

      posted in Controllers
      petewill
      petewill
    • RE: $8 Lamp (Outlet) "Smart Plug" Module

      @DanielD said:

      How you sync the plug with your cellphone?

      I use a Vera for my home automation controller. MySensors has a plugin for Vera so the cellphone app is actually for Vera. I can issue a command through my phone to Vera which will then send the command to the MySensors device.

      Hopefully that makes sense.

      Pete

      posted in My Project
      petewill
      petewill
    • RE: Extending range of regular nRF24L01+

      @sundberg84 said:

      Hihi isnt this "other guy " @petewill ?

      Haha! Well, I've definitely been called worse things than "other guy"... 🙂

      Cool, my video made it on to hackaday! I use this cheap hack all over my house with definite improvement. Like the site says, not the most "technically sound" but it definitely works for me.

      posted in Hardware
      petewill
      petewill
    • RE: Relay on when starting up

      @archiijs can you post a picture of the wiring? My relays have two ways to connect- one keeps the circuit closed and the other open. Also, you mentioned you come home and the lights are on. Can you give more details about that?

      posted in General Discussion
      petewill
      petewill
    • RE: Windows GUI/Controller for MySensors

      @samuel235 are you using a Windows PC to upload your sketches? FTDI recently released drivers that stops FTDI clones from working with the new drivers. This happened to me and my errors looked very similar. The solution for me was to uninstall the drivers and re-install the older ones. I got the info from this post: http://www.eevblog.com/forum/microcontrollers/ftdi-gate-2-0/msg854401/#msg854401

      Also, I had to log in to my computer as an admin to make all these changes. For some reason using a standard account then typing in an admin password at the UAC prompt did not help. Maybe it was a coincidence but tried many times and only after doing it in admin context did I get it to work. Also, make sure you turn off Windows update for drivers. Let me know if you get stuck and I'll do my best to help.

      posted in Controllers
      petewill
      petewill
    • RE: $8 Lamp (Outlet) "Smart Plug" Module

      @sundberg84 said:

      Hi @petewill!
      I made this 🙂 Great video 👍

      I think i get bad reception or something because it works the first 5-6 times and then nothing...

      This could also be a power or a wiring issue. But, the antenna is an easy modification so it wouldn't hurt to try this first. Another test is to move the device closer to your gateway. If it still stops after 5-6 times then it probably isn't communication issues.

      In the end you describe an cat5 wire added as antenna because of bad reception.
      Do you remove the plastic/shielding so its just copper?
      Im afraid to short anything out with a long uncovered antenna if thats the case...

      No, I left the shielding on the wire. Sorry, I should have specified that.

      and if i hear you right its 3,28 inches which should be 33,31200 millimeters on the antenna?

      I think 3.28 inches is 83.312 millimeters (at least that's what google says it is).

      posted in My Project
      petewill
      petewill
    • RE: Safe In-Wall AC to DC Transformers??

      @Cliff-Karlsson
      I haven't tested any of these parts yet but this is what I ordered. I am in the USA so this is spec'd for 120 VAC. If you're using 240 you will need to change the size of the Varistor but everything else should be fine for 240.

      Varistor for 120VAC - http://www.ebay.com/itm/321024816822?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

      73°C Thermal Fuse - http://www.ebay.com/itm/221560426284?_trksid=p2057872.m2749.l2649&var=520415979885&ssPageName=STRK%3AMEBIDX%3AIT

      250V 300mA Slow Blow Fuse - http://www.ebay.com/itm/111433875797?_trksid=p2057872.m2749.l2649&var=410420838583&ssPageName=STRK%3AMEBIDX%3AIT

      HLK-PM01 - http://www.ebay.com/itm/351418782712?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

      posted in Hardware
      petewill
      petewill
    • RE: Distributed Power vs Centralized Nodes

      If you are putting lighting in your house that will replace normal lighting (not accent/supplemental lighting) I highly recommend that you design it so it functions if there is 110/220 going to the switch. If it relies on another power supply to switch it on/off you can have safety issues if your whole house power supply goes out. That being said I have nodes all over my house that are powered from one power supply. These nodes are not critical to my house's function and it really doesn't matter if everything stops working (although it would be inconvenient).

      posted in General Discussion
      petewill
      petewill
    • RE: Firmware does not load MYSController & MYSBootloaderV13pre

      @itbeyond I ran into issues with multiple connections to my Ethernet gateway. My current config is to route my Vera through MYSController. If I do that I'm able to upload new firmware without any issues. Also, check the distance/reception of the sensor. I had one with poor reception that either didn't upload or took 20 minutes. When I changed the radio antenna config it worked in about a minute.

      posted in Controllers
      petewill
      petewill
    • RE: $8 Lamp (Outlet) "Smart Plug" Module

      @hyla I actually recently did a separate video on how I do this with a little more explanation. If you're interested it's here:

      Cheap DIY NRF24L01 Antenna Modification – 02:48
      — Pete B

      In summary, I measured the length of the existing antenna on the PCB then added additional wire to get it up to the required length for the 2.4GHz range (4.92 in).

      posted in My Project
      petewill
      petewill
    • RE: Which Arduino IDE version?

      @Mark-Swift I'm using IDE 1.6.12 and board defs 1.6.14 and my Ethernet gateway has been running for almost a week with no apparent issues. How often are you seeing the crash?

      posted in Development
      petewill
      petewill
    • RE: Are Chinese power supply chargers that dangerous to use ?

      @ahmedadelhosni said:

      @petewill I would be pleased if you could share your experience with phone adapters as you have create a sensor node outlet before using a phone charger. Was it fake or original ? Did you face any problem till now or did you change it later ? Any info will be helpful ofcourse.

      I have used many phone chargers in my projects. They are all original chargers that I picked up from the recycle bin at work. I have never had any issues.

      I started the post for safe in wall transformers to find a good solution because I don't want to use a phone charger in the wall. The HLK was decided as the best solution. It was tested by a third party (you can find the link in the thread) and said to be safe. I personally haven't used on in a project yet (too many projects, not enough time) but I plan to soon.

      Hopefully that helps.

      posted in Hardware
      petewill
      petewill
    • RE: Controlling Blinds.com RF Dooya Motors with Arduino and Vera

      @NeverDie Thanks! It is powered by 8 AA batteries in the battery wand. I actually hardwired mine though. I was able to get power to all my windows fairly easily (although my wife would disagree). So, unfortunately I have no idea how long they last. I feel like I remember people reporting about a year but I can't say where I remember that from.

      posted in My Project
      petewill
      petewill
    • RE: My sensors 2.1.1

      Sorry for the delayed reply. I missed this thread. I am happy to add more info I'm just not sure what is the best way to do that is. First off, @livinlowe which video were you watching? I'll watch it again and see if there is anything I can do to make it more clear. It may require making an updated video...

      posted in Development
      petewill
      petewill
    • RE: NRF24L01+ range of only few meters

      @epierre my notes are in inches so forgive me not converting it here. My thinking was to make a full wavelength antenna using the existing pcb antenna. A full wavelength antenna for 2.4GHz is 4.92 in. I measured the existing pcb antenna on the nRF and it was 1.64 in. So, 4.92 - 1.64 = 3.28 in. (or 8.3312 cm). I'm not claiming to be an expert at all (an other people have said this shouldn't work) but it has worked well for me so I keep doing it. 🙂 Others have reported success too so hopefully it will help you.

      (thanks for your help @mfalkvidd)

      @nunver Have you changed the PA level to MAX in myconfig.h?

      posted in Hardware
      petewill
      petewill
    • RE: Irrigation Controller (up to 16 valves with Shift Registers)

      Hey Everyone,

      I just made a follow up video to this irrigation controller that shows my logic I'm using to save water. It's pretty specific to my environment but hopefully you can use some of the ideas to save water in your environment. I have attached the logic I used in my PLEG device.

      Pete

      PLEG Irrigation.pdf

      Automation to Adjust Irrigation Watering Time Based on Weather – 25:17
      — Pete B

      posted in My Project
      petewill
      petewill
    • RE: MYSBootloader 1.3 pre-release & MYSController 1.0.0beta

      @itbeyond I responded in the other thread.

      posted in Development
      petewill
      petewill
    • RE: NRF24L01+ range of only few meters

      @Igor-Katkov said:

      I think I found my issue. It was the large transceiver see image below, with power amplifier and external antenna.

      I have had issues with my NRF radio like the one you mention here. I'm not sure about range issues but it totally stopped my Z-Wave network from communicating. It was easier for me to just use one of the smaller radios instead of doing further troubleshooting. I know there are some other threads (that I can't think of off the top of my head) where users have found that shielding it has helped. Also, as @Oitzu said, try powering it from a separate 3.3v source instead of from the Uno.

      posted in Hardware
      petewill
      petewill
    • RE: How To - Doorbell Automation Hack

      @drock1985 Nice! Does your doorbell use DC so you can steal power from it? I wish mine did. That would have made things easier for me. Mine uses 16VAC... 😞

      posted in My Project
      petewill
      petewill
    • RE: How to add a serial device to use in node-red

      @hiddenuser I know this is really late but I just ran into this problem and thought I'd post the solution in case any other people run into it. Thanks go to @mfalkvidd for providing the solution. You need to add this line:

      sudo chmod 666 /dev/ttyUSB020
      

      to /etc/rc.local

      Here is a link on how to do that (and for more info): https://www.raspberrypi.org/documentation/linux/usage/rc-local.md

      posted in Node-RED
      petewill
      petewill
    • RE: Suggestions to replace Thermostat?

      @AWI Maybe I will switch to a Dallas DS18B20 sensor then. I don't really need to know the humidity anyway. I have been using DHT sensors around my house for a couple of years (mostly to keep track of the temperature) and they seem to be working fine. I haven't done any scientific tests but they all have around the same temperature. I also have some Dallas sensors which also seem to be fine. Nothing has been off enough for me to notice or question their accuracy. The main reason I switched from a DS18B20 to a DHT22 was because the library was smaller and I needed to trim down the flash memory in my sketch. Now that I am upgrading to MySensors 2.0 I have regained 7kb of memory just from the upgrade (I also upgraded the Arduino IDE).

      posted in Hardware
      petewill
      petewill
    • RE: Backlit Dimmable LED Mirror with Motion Sensor

      @csa02221862 Sorry for the delayed reply. Busy day yesterday. Here is my code that I'm running in my 1.4.1/1.5 environment.

      /***
       * 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.
       * 
       * DESCRIPTION
       * This sketch provides a Dimmable LED Light using PWM and based Henrik Ekblad 
       * <henrik.ekblad@gmail.com> Vera Arduino Sensor project.  
       * Developed by Bruce Lacey, inspired by Hek's MySensor's example sketches.
       * 
       * The circuit uses a MOSFET for Pulse-Wave-Modulation to dim the attached LED or LED strip.  
       * The MOSFET Gate pin is connected to Arduino pin 3 (LED_PIN), the MOSFET Drain pin is connected
       * to the LED negative terminal and the MOSFET Source pin is connected to ground.  
       *
       * This sketch is extensible to support more than one MOSFET/PWM dimmer per circuit.
       *
       * REVISION HISTORY
       * Version 1.0 - February 15, 2014 - Bruce Lacey
       * Version 1.1 - August 13, 2014 - Converted to 1.4 (hek)
       * Version 1.2 - January 22, 2015 - Created a seperate control for the basement LEDs 
       * Version 1.3 - March 7, 2015 - Added coat closet LED
       *
       ***/
      #define SN "Basement LEDs"
      #define SV "1.3"
      
      #include <MySensor.h> 
      #include <SPI.h>
      
      #define NODE_ID AUTO //Change to a number to manually assign a node ID
      
      #define MASTER_WINDOW_LED_CHILD 0
      #define COAT_CLOSET_LED_CHILD 1
      #define UPSTAIRS_RAIL_LED_CHILD 30
      #define BASEMENT_DESK_LED_CHILD 40
      
      #define MASTER_WINDOW_LED_PIN 3      // Arduino pin attached to MOSFET Gate pin
      #define UPSTAIRS_RAIL_LED_PIN 5
      #define BASEMENT_DESK_LED_PIN 6
      #define COAT_CLOSET_LED_PIN 9
      
      #define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
      
      //MySensor gw;
      MySensor gw(4, 10);  //Change CE PIN to free up another PWM pin
      
      static int currentLevelUpstairsRail = 0;
      static int currentLevelBasementDesk = 0;
      static int currentLevelMasterWinLight = 0;
      static int currentLevelCoatCloset = 0;
      
      
      /***
       * Dimmable LED initialization method
       */
      void setup()  
      { 
        Serial.println( SN ); 
        gw.begin( incomingMessage,  NODE_ID);
        
        // Register the LED Dimmable Light with the gateway
        gw.present(UPSTAIRS_RAIL_LED_CHILD, S_DIMMER );
        gw.present(BASEMENT_DESK_LED_CHILD, S_DIMMER ); 
        gw.present(MASTER_WINDOW_LED_CHILD, S_DIMMER );
        gw.present(COAT_CLOSET_LED_CHILD, S_DIMMER );
        
        gw.sendSketchInfo(SN, SV);
      }
      
      /***
       *  Dimmable LED main processing loop 
       */
      void loop() 
      {
        gw.process();
      }
      
      
      
      void incomingMessage(const MyMessage &message) {
        if (message.type == V_LIGHT || message.type == V_DIMMER) {
          
          //  Retrieve the power or dim level from the incoming request message
          int requestedLevel = atoi( message.data );
          
          // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
          requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
          
          // Clip incoming level to valid range of 0 to 100
          requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
          requestedLevel = requestedLevel < 0   ? 0   : requestedLevel;
          
      //    Serial.print( "Changing level to " );
      //    Serial.println( requestedLevel );
      
      
          //fadeToLevel( requestedLevel );//old code
          fadeToLevel( message.sensor, requestedLevel );
          }
      }
      
      
      
      void fadeToLevel(int ledChild, int toLevel ) {
      //    Serial.print( "In the FadeToLevel method.  ChildID: " );
      //    Serial.println( ledChild );
      
        int currentLevel;
        int ledPin;
        
        if(ledChild == UPSTAIRS_RAIL_LED_CHILD){
          currentLevel = currentLevelUpstairsRail;
          ledPin = UPSTAIRS_RAIL_LED_PIN; 
        }
        else if(ledChild == MASTER_WINDOW_LED_CHILD){
          currentLevel = currentLevelMasterWinLight;
          ledPin = MASTER_WINDOW_LED_PIN;
        }
        else if(ledChild == COAT_CLOSET_LED_CHILD){
          currentLevel = currentLevelCoatCloset;
          ledPin = COAT_CLOSET_LED_PIN;
        }
        else{
          currentLevel = currentLevelBasementDesk;
          ledPin = BASEMENT_DESK_LED_PIN;
        }
        
        int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1;
        
        while ( currentLevel != toLevel ) {
          currentLevel += delta;
          analogWrite(ledPin, (int)(currentLevel / 100. * 255) );
          delay( FADE_DELAY );
      //    Serial.println( ledPin );
        }
        
        if(ledChild == UPSTAIRS_RAIL_LED_CHILD){
          currentLevelUpstairsRail = toLevel;
        }
        else if(ledChild == MASTER_WINDOW_LED_CHILD){
          currentLevelMasterWinLight = toLevel;
        }
        else if(ledChild == COAT_CLOSET_LED_CHILD){
          currentLevelCoatCloset = toLevel;
        }
        else{
          currentLevelBasementDesk = toLevel;
        }
          //gw.sendVariable( ledChild, V_LIGHT,  currentLevel > 0 ? 1 : 0 ); 
          //gw.sendVariable( ledChild, V_DIMMER, currentLevel );
          MyMessage dimmerMsg(ledChild,  V_DIMMER);
          gw.send(dimmerMsg.set(currentLevel));
          
        
      }```
      posted in My Project
      petewill
      petewill
    • RE: Still not going well for me.

      @Coffeesnob Sorry for the delayed reply. I was in the mountains the last few days. I'm glad you got it working! There are a lot of different factors at play when designing your own sensors and learning something new can take time but I think you are over the biggest hurdle now.

      @mfalkvidd thanks for updating the documentation. You are awesome!

      posted in Troubleshooting
      petewill
      petewill
    • RE: MyController+Domoticz at same time?

      @mfalkvidd I have run MYSController and Vera both connected to my Ethernet gateway at the same time with no issues. I ran it for days (400,000+ tx/rx entries). I mainly use MYSController for monitoring/troubleshooting as well as testing OTA. Vera is doing all the control for now.

      posted in MyController.org
      petewill
      petewill
    • RE: Irrigation Controller (up to 16 valves with Shift Registers)

      @BulldogLowell Ha! Unfortunately I'm fresh out of those...

      @impertus Both @BulldogLowell and I use Vera as our home automation controller (not open source). My setup looks like: Irrigation Controller <> Ethernet Gateway <> Vera <> Vera Mobile App (usually AutHomationHD). I haven't tested any other controllers with this device but reading up a little in this forum post it appears that some people have got it to work with Domoticz.

      posted in My Project
      petewill
      petewill
    • RE: Uploading to Pro Mini fails with FTDI

      @ben999 I think I understand what you're asking. If so, I do it frequently with my projects. What I do is just unplug the VCC DuPont cable from the FTDI adapter. Here is a picture of what I mean.
      0_1520091743625_IMG_20180303_083811.jpg

      posted in Troubleshooting
      petewill
      petewill
    • RE: Irrigation Controller (up to 16 valves with Shift Registers)

      @Huczas the code has been updated in the 2.0 GitHub branch. The wiring diagram has also been updated. Thanks for the fix!

      posted in My Project
      petewill
      petewill
    • RE: Uploading to Pro Mini fails with FTDI

      @ben999 Sorry for the delay. Work has been crazy lately. I see there are plenty of answers above and I echo them. I try not to upload with two power sources connected. If everything is 5v you are probably safe but I see you're using batteries and I'd not risk it just to be safe. I have used two power sources in the past but I have since changed my ways. I can't remember what stopped me but I believe I was getting strange results. I don't think I ever fried any hardware but why risk it...? 🙂

      If you are still having this issue have you tried with another Pro Mini and different code? Is anything coming out of the serial monitor or is it just blank?

      posted in Troubleshooting
      petewill
      petewill
    • RE: Video How To: Battery Powered Chair Occupancy (Contact) Sensor

      @Nca78 Wow, cool. I never got readings down to 2uA. Maybe my multimeter isn't very good or something else...? The main reason I regularly report the battery is to provide a heartbeat as well as reset the sensor if for some reason it could not communicate with the gateway the first time.

      Edit: I just re-read your post. I now see that you were saying I could save those additional uA by not using the sleep. That is a good idea. I'm still a little torn on the idea because I like the assurance of the heartbeat. I'll have to think about it. Thanks for sharing though!

      posted in My Project
      petewill
      petewill
    • RE: RooDe - A "reliable" PeopleCounter

      @Kai-Bepperling I have been wanting to make something like this for years. I keep getting sidetracked so I have never completed anything. I am excited to try this method at some point. I have a few rooms where this would work much better than the motion sensors I have now. Thank you for posting this.

      posted in My Project
      petewill
      petewill