Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Multi-Sensor Button+dallas problem

Multi-Sensor Button+dallas problem

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 3 Posters 2.5k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Thib.T Offline
    Thib.T Offline
    Thib.
    wrote on last edited by
    #1

    Hi,
    I made a multisensor node with latest library :
    2x Relay + 2x Dallas+ Sonar Distance + 2x Button

    The node is working but :

    • If i include sleep() or wait() in dallas sketch the node become slow and button is very slow to transfer data (more than 15sec)
    • If i remove sleep() or wait() its better but dallas send to many informations

    Is it possible to send dallas information every minute without a wait ?
    For the moment my solution is to convert FLOAT temperature to INT.

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <Bounce2.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    #include <NewPing.h>
    
    //-------------------RELAY-----------------------------//
    #define RELAY_1  A1  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define RELAY_2  A2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 2 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
    //-------------------DALLAS----------------------------//
    #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
    #define MAX_ATTACHED_DS18B20 2
    //unsigned long WAIT_TIME = 5000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
    int lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    bool receivedConfig = false;
    bool metric = true;
    // Initialize temperature message
    MyMessage msg(0,V_TEMP);
    
    //-------------------SONAR----------------------------//
    #define CHILD_ID 5
    #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MAX_DISTANCE 1000 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    MyMessage msg1(CHILD_ID, V_DISTANCE);
    int lastDist;
    
    //-------------------BUTTON----------------------------//
    #define CHILD_ID_6 6
    #define CHILD_ID_7 7
    #define BUTTON_PIN_6  4  // Arduino Digital I/O pin for button/reed switch
    #define BUTTON_PIN_7  8  // Arduino Digital I/O pin for button/reed switch
    Bounce debouncer1 = Bounce(); 
    Bounce debouncer2 = Bounce();  
    int oldValue1=-1;
    int oldValue2=-1;
    MyMessage msg6(CHILD_ID_6,V_TRIPPED);
    MyMessage msg7(CHILD_ID_7,V_TRIPPED);
    
    //=======================BEFORE==========================================//
    void before() { 
        //-------------------DALLAS----------------------------//
        //Startup up the OneWire library
        sensors.begin();
    
        //-------------------RELAY-----------------------------//
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to OFF
        digitalWrite(pin, RELAY_OFF);
      }
     }
    
    //=======================SETUP============================================//
    void setup() {
        //-------------------DALLAS----------------------------//
        //requestTemperatures() will not block current thread
        sensors.setWaitForConversion(false);
    
        //-------------------SONAR----------------------------//
        metric = getConfig().isMetric;
    
        //-------------------BUTTON----------------------------//
        // Setup the button
        pinMode(BUTTON_PIN_6,INPUT);
        pinMode(BUTTON_PIN_7,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_6,HIGH);
        digitalWrite(BUTTON_PIN_7,HIGH);
        // After setting up the button, setup debouncer
        debouncer1.attach(BUTTON_PIN_6);
        debouncer1.interval(5);
        debouncer2.attach(BUTTON_PIN_7);
        debouncer2.interval(5); 
    }
    
    //=======================PRESENTATION======================================//
    void presentation()  
    {   
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Poele", "1.0");
        
      //-------------------RELAY-----------------------------//
      // Register all sensors to gw (they will be created as child devices)
      present(1, S_BINARY);
      present(2, S_BINARY);
    
      //-------------------DALLAS----------------------------//
      // Fetch the number of attached temperature sensors  
      numSensors = sensors.getDeviceCount();
      //Present all sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
      present(i+3, S_TEMP);
      }
      
      //-------------------SONAR----------------------------//
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_DISTANCE);
    
      //-------------------BUTTON----------------------------//
      present(CHILD_ID_6, S_DOOR);  
      present(CHILD_ID_7, S_DOOR); 
    }
    
    
    //=======================LOOP==============================================//
    void loop() 
    {
          //-------------------BUTTON----------------------------//
          debouncer1.update();
          // Get the update value
          int value1 = debouncer1.read();
          if (value1 != oldValue1) {
          // Send in the new value
          send(msg6.set(value1==HIGH ? 1 : 0));
          oldValue1 = value1;
          }
          debouncer2.update();
          // Get the update value
          int value2 = debouncer2.read();
          if (value2 != oldValue2) {
          // Send in the new value
          send(msg7.set(value2==HIGH ? 1 : 0));
          oldValue2 = value2;
          }
        
          //-------------------SONAR----------------------------// 
          int dist = metric?sonar.ping_cm():sonar.ping_in();
          Serial.print("Ping: ");
          Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
          Serial.println(metric?" cm":" in");
    
          if (dist != lastDist && dist != lastDist+1 && dist != lastDist-1) {
            send(msg1.set(dist));
            lastDist = dist;
           }
         
     
         //-------------------DALLAS----------------------------// 
         // Fetch temperatures from Dallas sensors
         sensors.requestTemperatures();
         
         // query conversion time and sleep until conversion completed
         int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
         
         // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
         wait(conversionTime);
         
         // Read temperatures and send them to controller 
         for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
        
         // Fetch and round temperature to one decimal
         int temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
         
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[i+3] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
        #endif
     
          send(msg.setSensor(i+3).set(temperature,1));
         // Save new temperatures for next compare
          lastTemperature[i+3]=temperature;
          } 
          }
        
          
    
    }
    
    //=======================RECEIVE==============================================//
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_STATUS) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    }``` 
    
    Thanks
    mfalkviddM Boots33B 2 Replies Last reply
    0
    • Thib.T Thib.

      Hi,
      I made a multisensor node with latest library :
      2x Relay + 2x Dallas+ Sonar Distance + 2x Button

      The node is working but :

      • If i include sleep() or wait() in dallas sketch the node become slow and button is very slow to transfer data (more than 15sec)
      • If i remove sleep() or wait() its better but dallas send to many informations

      Is it possible to send dallas information every minute without a wait ?
      For the moment my solution is to convert FLOAT temperature to INT.

      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enable repeater functionality for this node
      #define MY_REPEATER_FEATURE
      
      #include <SPI.h>
      #include <MySensors.h>  
      #include <Bounce2.h>
      #include <DallasTemperature.h>
      #include <OneWire.h>
      #include <NewPing.h>
      
      //-------------------RELAY-----------------------------//
      #define RELAY_1  A1  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define RELAY_2  A2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 2 // Total number of attached relays
      #define RELAY_ON 0  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
      
      //-------------------DALLAS----------------------------//
      #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
      #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
      #define MAX_ATTACHED_DS18B20 2
      //unsigned long WAIT_TIME = 5000; // Sleep time between reads (in milliseconds)
      OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
      DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
      int lastTemperature[MAX_ATTACHED_DS18B20];
      int numSensors=0;
      bool receivedConfig = false;
      bool metric = true;
      // Initialize temperature message
      MyMessage msg(0,V_TEMP);
      
      //-------------------SONAR----------------------------//
      #define CHILD_ID 5
      #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
      #define MAX_DISTANCE 1000 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
      NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      MyMessage msg1(CHILD_ID, V_DISTANCE);
      int lastDist;
      
      //-------------------BUTTON----------------------------//
      #define CHILD_ID_6 6
      #define CHILD_ID_7 7
      #define BUTTON_PIN_6  4  // Arduino Digital I/O pin for button/reed switch
      #define BUTTON_PIN_7  8  // Arduino Digital I/O pin for button/reed switch
      Bounce debouncer1 = Bounce(); 
      Bounce debouncer2 = Bounce();  
      int oldValue1=-1;
      int oldValue2=-1;
      MyMessage msg6(CHILD_ID_6,V_TRIPPED);
      MyMessage msg7(CHILD_ID_7,V_TRIPPED);
      
      //=======================BEFORE==========================================//
      void before() { 
          //-------------------DALLAS----------------------------//
          //Startup up the OneWire library
          sensors.begin();
      
          //-------------------RELAY-----------------------------//
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);   
          // Set relay to OFF
          digitalWrite(pin, RELAY_OFF);
        }
       }
      
      //=======================SETUP============================================//
      void setup() {
          //-------------------DALLAS----------------------------//
          //requestTemperatures() will not block current thread
          sensors.setWaitForConversion(false);
      
          //-------------------SONAR----------------------------//
          metric = getConfig().isMetric;
      
          //-------------------BUTTON----------------------------//
          // Setup the button
          pinMode(BUTTON_PIN_6,INPUT);
          pinMode(BUTTON_PIN_7,INPUT);
          // Activate internal pull-up
          digitalWrite(BUTTON_PIN_6,HIGH);
          digitalWrite(BUTTON_PIN_7,HIGH);
          // After setting up the button, setup debouncer
          debouncer1.attach(BUTTON_PIN_6);
          debouncer1.interval(5);
          debouncer2.attach(BUTTON_PIN_7);
          debouncer2.interval(5); 
      }
      
      //=======================PRESENTATION======================================//
      void presentation()  
      {   
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Poele", "1.0");
          
        //-------------------RELAY-----------------------------//
        // Register all sensors to gw (they will be created as child devices)
        present(1, S_BINARY);
        present(2, S_BINARY);
      
        //-------------------DALLAS----------------------------//
        // Fetch the number of attached temperature sensors  
        numSensors = sensors.getDeviceCount();
        //Present all sensors to controller
        for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
        present(i+3, S_TEMP);
        }
        
        //-------------------SONAR----------------------------//
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID, S_DISTANCE);
      
        //-------------------BUTTON----------------------------//
        present(CHILD_ID_6, S_DOOR);  
        present(CHILD_ID_7, S_DOOR); 
      }
      
      
      //=======================LOOP==============================================//
      void loop() 
      {
            //-------------------BUTTON----------------------------//
            debouncer1.update();
            // Get the update value
            int value1 = debouncer1.read();
            if (value1 != oldValue1) {
            // Send in the new value
            send(msg6.set(value1==HIGH ? 1 : 0));
            oldValue1 = value1;
            }
            debouncer2.update();
            // Get the update value
            int value2 = debouncer2.read();
            if (value2 != oldValue2) {
            // Send in the new value
            send(msg7.set(value2==HIGH ? 1 : 0));
            oldValue2 = value2;
            }
          
            //-------------------SONAR----------------------------// 
            int dist = metric?sonar.ping_cm():sonar.ping_in();
            Serial.print("Ping: ");
            Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
            Serial.println(metric?" cm":" in");
      
            if (dist != lastDist && dist != lastDist+1 && dist != lastDist-1) {
              send(msg1.set(dist));
              lastDist = dist;
             }
           
       
           //-------------------DALLAS----------------------------// 
           // Fetch temperatures from Dallas sensors
           sensors.requestTemperatures();
           
           // query conversion time and sleep until conversion completed
           int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
           
           // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
           wait(conversionTime);
           
           // Read temperatures and send them to controller 
           for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
          
           // Fetch and round temperature to one decimal
           int temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
           
          // Only send data if temperature has changed and no error
          #if COMPARE_TEMP == 1
          if (lastTemperature[i+3] != temperature && temperature != -127.00 && temperature != 85.00) {
          #else
          if (temperature != -127.00 && temperature != 85.00) {
          #endif
       
            send(msg.setSensor(i+3).set(temperature,1));
           // Save new temperatures for next compare
            lastTemperature[i+3]=temperature;
            } 
            }
          
            
      
      }
      
      //=======================RECEIVE==============================================//
      void receive(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_STATUS) {
           // Change relay state
           digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
           // Store state in eeprom
           saveState(message.sensor, message.getBool());
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      }``` 
      
      Thanks
      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @Thib. you should be able to use something like the lastSend variable used in the UV meter example

      1 Reply Last reply
      0
      • Thib.T Thib.

        Hi,
        I made a multisensor node with latest library :
        2x Relay + 2x Dallas+ Sonar Distance + 2x Button

        The node is working but :

        • If i include sleep() or wait() in dallas sketch the node become slow and button is very slow to transfer data (more than 15sec)
        • If i remove sleep() or wait() its better but dallas send to many informations

        Is it possible to send dallas information every minute without a wait ?
        For the moment my solution is to convert FLOAT temperature to INT.

        // Enable debug prints to serial monitor
        #define MY_DEBUG 
        
        // Enable and select radio type attached
        #define MY_RADIO_NRF24
        //#define MY_RADIO_RFM69
        
        // Enable repeater functionality for this node
        #define MY_REPEATER_FEATURE
        
        #include <SPI.h>
        #include <MySensors.h>  
        #include <Bounce2.h>
        #include <DallasTemperature.h>
        #include <OneWire.h>
        #include <NewPing.h>
        
        //-------------------RELAY-----------------------------//
        #define RELAY_1  A1  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
        #define RELAY_2  A2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
        #define NUMBER_OF_RELAYS 2 // Total number of attached relays
        #define RELAY_ON 0  // GPIO value to write to turn on attached relay
        #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
        
        //-------------------DALLAS----------------------------//
        #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
        #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
        #define MAX_ATTACHED_DS18B20 2
        //unsigned long WAIT_TIME = 5000; // Sleep time between reads (in milliseconds)
        OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
        DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
        int lastTemperature[MAX_ATTACHED_DS18B20];
        int numSensors=0;
        bool receivedConfig = false;
        bool metric = true;
        // Initialize temperature message
        MyMessage msg(0,V_TEMP);
        
        //-------------------SONAR----------------------------//
        #define CHILD_ID 5
        #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
        #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
        #define MAX_DISTANCE 1000 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
        NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
        MyMessage msg1(CHILD_ID, V_DISTANCE);
        int lastDist;
        
        //-------------------BUTTON----------------------------//
        #define CHILD_ID_6 6
        #define CHILD_ID_7 7
        #define BUTTON_PIN_6  4  // Arduino Digital I/O pin for button/reed switch
        #define BUTTON_PIN_7  8  // Arduino Digital I/O pin for button/reed switch
        Bounce debouncer1 = Bounce(); 
        Bounce debouncer2 = Bounce();  
        int oldValue1=-1;
        int oldValue2=-1;
        MyMessage msg6(CHILD_ID_6,V_TRIPPED);
        MyMessage msg7(CHILD_ID_7,V_TRIPPED);
        
        //=======================BEFORE==========================================//
        void before() { 
            //-------------------DALLAS----------------------------//
            //Startup up the OneWire library
            sensors.begin();
        
            //-------------------RELAY-----------------------------//
            for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
            // Then set relay pins in output mode
            pinMode(pin, OUTPUT);   
            // Set relay to OFF
            digitalWrite(pin, RELAY_OFF);
          }
         }
        
        //=======================SETUP============================================//
        void setup() {
            //-------------------DALLAS----------------------------//
            //requestTemperatures() will not block current thread
            sensors.setWaitForConversion(false);
        
            //-------------------SONAR----------------------------//
            metric = getConfig().isMetric;
        
            //-------------------BUTTON----------------------------//
            // Setup the button
            pinMode(BUTTON_PIN_6,INPUT);
            pinMode(BUTTON_PIN_7,INPUT);
            // Activate internal pull-up
            digitalWrite(BUTTON_PIN_6,HIGH);
            digitalWrite(BUTTON_PIN_7,HIGH);
            // After setting up the button, setup debouncer
            debouncer1.attach(BUTTON_PIN_6);
            debouncer1.interval(5);
            debouncer2.attach(BUTTON_PIN_7);
            debouncer2.interval(5); 
        }
        
        //=======================PRESENTATION======================================//
        void presentation()  
        {   
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Poele", "1.0");
            
          //-------------------RELAY-----------------------------//
          // Register all sensors to gw (they will be created as child devices)
          present(1, S_BINARY);
          present(2, S_BINARY);
        
          //-------------------DALLAS----------------------------//
          // Fetch the number of attached temperature sensors  
          numSensors = sensors.getDeviceCount();
          //Present all sensors to controller
          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
          present(i+3, S_TEMP);
          }
          
          //-------------------SONAR----------------------------//
          // Register all sensors to gw (they will be created as child devices)
          present(CHILD_ID, S_DISTANCE);
        
          //-------------------BUTTON----------------------------//
          present(CHILD_ID_6, S_DOOR);  
          present(CHILD_ID_7, S_DOOR); 
        }
        
        
        //=======================LOOP==============================================//
        void loop() 
        {
              //-------------------BUTTON----------------------------//
              debouncer1.update();
              // Get the update value
              int value1 = debouncer1.read();
              if (value1 != oldValue1) {
              // Send in the new value
              send(msg6.set(value1==HIGH ? 1 : 0));
              oldValue1 = value1;
              }
              debouncer2.update();
              // Get the update value
              int value2 = debouncer2.read();
              if (value2 != oldValue2) {
              // Send in the new value
              send(msg7.set(value2==HIGH ? 1 : 0));
              oldValue2 = value2;
              }
            
              //-------------------SONAR----------------------------// 
              int dist = metric?sonar.ping_cm():sonar.ping_in();
              Serial.print("Ping: ");
              Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
              Serial.println(metric?" cm":" in");
        
              if (dist != lastDist && dist != lastDist+1 && dist != lastDist-1) {
                send(msg1.set(dist));
                lastDist = dist;
               }
             
         
             //-------------------DALLAS----------------------------// 
             // Fetch temperatures from Dallas sensors
             sensors.requestTemperatures();
             
             // query conversion time and sleep until conversion completed
             int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
             
             // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
             wait(conversionTime);
             
             // Read temperatures and send them to controller 
             for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
            
             // Fetch and round temperature to one decimal
             int temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
             
            // Only send data if temperature has changed and no error
            #if COMPARE_TEMP == 1
            if (lastTemperature[i+3] != temperature && temperature != -127.00 && temperature != 85.00) {
            #else
            if (temperature != -127.00 && temperature != 85.00) {
            #endif
         
              send(msg.setSensor(i+3).set(temperature,1));
             // Save new temperatures for next compare
              lastTemperature[i+3]=temperature;
              } 
              }
            
              
        
        }
        
        //=======================RECEIVE==============================================//
        void receive(const MyMessage &message) {
          // We only expect one type of message from controller. But we better check anyway.
          if (message.type==V_STATUS) {
             // Change relay state
             digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
             // Store state in eeprom
             saveState(message.sensor, message.getBool());
             // Write some debug info
             Serial.print("Incoming change for sensor:");
             Serial.print(message.sensor);
             Serial.print(", New status: ");
             Serial.println(message.getBool());
           } 
        }``` 
        
        Thanks
        Boots33B Offline
        Boots33B Offline
        Boots33
        Hero Member
        wrote on last edited by
        #3

        @Thib. When you are using devices like the ultrasonic distance sensor it is best to use non blocking delays . do a google search for "Arduino non blocking delay" to get more info.

        The basic code will look something like below

        unsigned long previousMillis = 0;        // will store last time temperature was updated
        const long interval = 60000;           // interval at which to update the temperature (milliseconds)
        
        void setup() {
         
        }
        
        void loop() {
          
          unsigned long currentMillis = millis();   // get the current time
          if (currentMillis - previousMillis >= interval) {
           
          /*---------------------Put your code to send temp here----------------------------  */
            
            previousMillis = currentMillis;         // save the last time you sent the temperature
          }
        }
        
        Thib.T 1 Reply Last reply
        0
        • Thib.T Offline
          Thib.T Offline
          Thib.
          wrote on last edited by
          #4

          Thanks for your answers, i will try it

          1 Reply Last reply
          0
          • Boots33B Boots33

            @Thib. When you are using devices like the ultrasonic distance sensor it is best to use non blocking delays . do a google search for "Arduino non blocking delay" to get more info.

            The basic code will look something like below

            unsigned long previousMillis = 0;        // will store last time temperature was updated
            const long interval = 60000;           // interval at which to update the temperature (milliseconds)
            
            void setup() {
             
            }
            
            void loop() {
              
              unsigned long currentMillis = millis();   // get the current time
              if (currentMillis - previousMillis >= interval) {
               
              /*---------------------Put your code to send temp here----------------------------  */
                
                previousMillis = currentMillis;         // save the last time you sent the temperature
              }
            }
            
            Thib.T Offline
            Thib.T Offline
            Thib.
            wrote on last edited by
            #5

            @Boots33 , Thanks i have compiled your example and its working good !

            1 Reply Last reply
            0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            21

            Online

            12.0k

            Users

            11.2k

            Topics

            113.4k

            Posts


            Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular