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. Announcements
  3. 💬 Temperature Sensor

💬 Temperature Sensor

Scheduled Pinned Locked Moved Announcements
171 Posts 40 Posters 54.7k Views 36 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.
  • skywatchS skywatch

    OK I'll do that - seems to be sending battery info every minute still though- strange!

    mfalkviddM Offline
    mfalkviddM Offline
    mfalkvidd
    Mod
    wrote on last edited by mfalkvidd
    #132

    @skywatch could you post the entire sketch also, to check if something fishy has crept in?

    1 Reply Last reply
    0
    • skywatchS Offline
      skywatchS Offline
      skywatch
      wrote on last edited by
      #133

      Here is the sketch, debug will be later today I hope....

      
      
      // Enable debug prints to serial monitor
      //#define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
      #define MY_RF24_PA_LEVEL (RF24_PA_LOW)
      #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
      #define MAX_ATTACHED_DS18B20 3
      #include <SPI.h>
      #include <MySensors.h>
      #include <DallasTemperature.h>
      #include <OneWire.h>
      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
      int batteryPcnt = 0;
      unsigned long SLEEP_TIME = 2 * 60 * 1000; // 2 minutes Sleep time between reads.
      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.
      float lastTemperature[MAX_ATTACHED_DS18B20];
      int numSensors = 0;
      const long interval = 90000;
      unsigned long previousMillis = 0;
      bool receivedConfig = false;
      bool metric = true;
      unsigned int batteryReportFactor = 30*60*1000/SLEEP_TIME; // Only report battery every x SLEEP times (x=15 with current values)
      unsigned int timesSlept = 0;
      // Initialize temperature message
      MyMessage msg(0, V_TEMP);
      
      void before()
      {
        // Startup up the OneWire library
        sensors.begin();
      }
      
      void setup()
      {
        // requestTemperatures() will not block current thread
        sensors.setWaitForConversion(false);
        analogReference(INTERNAL);
      }
      
      void presentation() {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("HW/CH", "0.5");
      
        // 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, S_TEMP);
        }
      }
      
      void loop()
      {
        // get the battery Voltage
        if (timesSlept < batteryReportFactor) {
          timesSlept++;
        } else {
          // get the battery Voltage
          timesSlept = 0;
          int sensorValue = analogRead(BATTERY_SENSE_PIN);
          batteryPcnt = sensorValue / 10;
          sendBatteryLevel(batteryPcnt);
        }
      
        // 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)
        sleep(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
          float temperature = static_cast<float>(static_cast<int>((getControllerConfig().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] != temperature && temperature != -127.00 && temperature != 85.00) {
      #else
          if (temperature != -127.00 && temperature != 85.00) {
      #endif
      
            // Send in the new temperature
            send(msg.setSensor(i).set(temperature, 1));
            // Save new temperatures for next compare
            lastTemperature[i] = temperature;
          }
        }
      
        int8_t sleep(1, FALLING, SLEEP_TIME);
      }```
      
      Thanks!
      mfalkviddM 1 Reply Last reply
      0
      • skywatchS skywatch

        Here is the sketch, debug will be later today I hope....

        
        
        // Enable debug prints to serial monitor
        //#define MY_DEBUG
        
        // Enable and select radio type attached
        #define MY_RADIO_NRF24
        //#define MY_RADIO_RFM69
        #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
        #define MY_RF24_PA_LEVEL (RF24_PA_LOW)
        #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
        #define MAX_ATTACHED_DS18B20 3
        #include <SPI.h>
        #include <MySensors.h>
        #include <DallasTemperature.h>
        #include <OneWire.h>
        int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
        int batteryPcnt = 0;
        unsigned long SLEEP_TIME = 2 * 60 * 1000; // 2 minutes Sleep time between reads.
        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.
        float lastTemperature[MAX_ATTACHED_DS18B20];
        int numSensors = 0;
        const long interval = 90000;
        unsigned long previousMillis = 0;
        bool receivedConfig = false;
        bool metric = true;
        unsigned int batteryReportFactor = 30*60*1000/SLEEP_TIME; // Only report battery every x SLEEP times (x=15 with current values)
        unsigned int timesSlept = 0;
        // Initialize temperature message
        MyMessage msg(0, V_TEMP);
        
        void before()
        {
          // Startup up the OneWire library
          sensors.begin();
        }
        
        void setup()
        {
          // requestTemperatures() will not block current thread
          sensors.setWaitForConversion(false);
          analogReference(INTERNAL);
        }
        
        void presentation() {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("HW/CH", "0.5");
        
          // 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, S_TEMP);
          }
        }
        
        void loop()
        {
          // get the battery Voltage
          if (timesSlept < batteryReportFactor) {
            timesSlept++;
          } else {
            // get the battery Voltage
            timesSlept = 0;
            int sensorValue = analogRead(BATTERY_SENSE_PIN);
            batteryPcnt = sensorValue / 10;
            sendBatteryLevel(batteryPcnt);
          }
        
          // 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)
          sleep(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
            float temperature = static_cast<float>(static_cast<int>((getControllerConfig().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] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
            if (temperature != -127.00 && temperature != 85.00) {
        #endif
        
              // Send in the new temperature
              send(msg.setSensor(i).set(temperature, 1));
              // Save new temperatures for next compare
              lastTemperature[i] = temperature;
            }
          }
        
          int8_t sleep(1, FALLING, SLEEP_TIME);
        }```
        
        Thanks!
        mfalkviddM Offline
        mfalkviddM Offline
        mfalkvidd
        Mod
        wrote on last edited by
        #134

        @skywatch code looks good to me. What type of Arduino are you using?

        1 Reply Last reply
        0
        • skywatchS Offline
          skywatchS Offline
          skywatch
          wrote on last edited by skywatch
          #135

          I am using a pro mini 3.3v 8MHz. I would ideally like to get a 1MHZ bootloader onto it but the last try stopped the temperature sensors sending data (although battery levels were still sent!)..... Hope it helps.

          mfalkviddM 1 Reply Last reply
          0
          • skywatchS skywatch

            I am using a pro mini 3.3v 8MHz. I would ideally like to get a 1MHZ bootloader onto it but the last try stopped the temperature sensors sending data (although battery levels were still sent!)..... Hope it helps.

            mfalkviddM Offline
            mfalkviddM Offline
            mfalkvidd
            Mod
            wrote on last edited by
            #136

            @skywatch could you also print the return value of the sleep function. Maybe that interrupt is triggering it so it returns early?

            1 Reply Last reply
            0
            • skywatchS Offline
              skywatchS Offline
              skywatch
              wrote on last edited by skywatch
              #137

              Sorry for the dealy, I have had a week of plumbing problems at home - yuck! :(

              So, I came back fresh to this and noticed that I had put the interrupt into the code ready for the water leak sensor (apt considering this weeks activities!) - BUT, I had not assigned the pin nor initialised it in the code. So maybe it was floating and giving random triggers?
              I tested by changing from int8_t sleep(1, FALLING, SLEEP_TIME); to int8_t sleep(SLEEP_TIME); but now I get battery level sent every single second! - This is making me crazy......

              The log for the gateway has the following.....

              Sep  3 07:00:37 HAAS rsyslogd-2007: action 'action 17' suspended, next retry is Sun Sep  3 07:02:07 2017 [try http://www.rsyslog.com/e/2007 ]
              Sep  3 06:26:28 HAAS rsyslogd0: action 'action 17' resumed (module 'builtin:ompipe') [try http://www.rsyslog.com/e/0 ]
              Sep  3 06:26:28 HAAS rsyslogd-2359: action 'action 17' resumed (module 'builtin:ompipe') [try http://www.rsyslog.com/e/2359 ]
              

              Not sure what the above is all about. Nor the below....

              7:15:45 HAAS dhcpcd[474]: eth0: Router Advertisement from fe80::3291:8fff:fe06:64bc
              

              But here is sending data every second.....

              Sep  3 12:46:52 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              Sep  3 12:46:53 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              Sep  3 12:46:54 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              Sep  3 12:46:55 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              Sep  3 12:46:56 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              Sep  3 12:46:57 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              Sep  3 12:46:58 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              Sep  3 12:46:59 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              Sep  3 12:47:00 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75
              

              Will try debug on node next....

              1 Reply Last reply
              1
              • skywatchS Offline
                skywatchS Offline
                skywatch
                wrote on last edited by
                #138

                I.m sure it is a bug in 2.2.0-beta as I have the same issues with another node sending data whenever it changes and not sleeping.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dertho
                  wrote on last edited by
                  #139

                  Hi,

                  is there any known problem / bug with version 2.1.* and the Dallas temp sensor? (I found non in the bug tracker and/or forum)

                  I updated several nodes from 1.5 to 2.1.1 and now no temp sensor is working. No temp sensor DS18B20 is found by the node, therefore -127.0 is returned to the controller. I checked the wiring - as illustrated in this manual, everything seems right; incl. the pull-up with 4,7 k. I use the modified version of the Dallas-Library included in the examples package, as stated out in this manual.

                  Thanks,
                  Thomas

                  1 Reply Last reply
                  0
                  • Mohammed ZamanM Offline
                    Mohammed ZamanM Offline
                    Mohammed Zaman
                    wrote on last edited by
                    #140

                    I am not a programmer, but trying to learn by making small projects.
                    I am trying to build a arduino/ESP8266 with temp sensor so that at a particular set temp it sends a single to another arduino/ESP8266 with relay to turn on a cooler/heater. if there is a thread on this, please help me find it.

                    rejoe2R 1 Reply Last reply
                    0
                    • Mohammed ZamanM Mohammed Zaman

                      I am not a programmer, but trying to learn by making small projects.
                      I am trying to build a arduino/ESP8266 with temp sensor so that at a particular set temp it sends a single to another arduino/ESP8266 with relay to turn on a cooler/heater. if there is a thread on this, please help me find it.

                      rejoe2R Offline
                      rejoe2R Offline
                      rejoe2
                      wrote on last edited by
                      #141

                      @Mohammed-Zaman This seems to be possible, you may find more info wrt your topic using "node to node communication" as a keyword for searching the forum.
                      This might be a good starting point: https://forum.mysensors.org/topic/6386/almost-controller-less-mysensors-switch-light-network/8#

                      Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                      1 Reply Last reply
                      1
                      • gohanG Offline
                        gohanG Offline
                        gohan
                        Mod
                        wrote on last edited by
                        #142

                        https://forum.mysensors.org/topic/7810/alternative-passive-mode if you don't want to use a gateway.

                        1 Reply Last reply
                        0
                        • mrwombleM mrwomble

                          Hi there, I'm new to Mysensors and I thought I'd start with a simple DS Temp sensor. However, I'm getting compile errors when I try compile it. Can someone please point me in the right direction?

                          Arduino: 1.6.11 (Windows 7), Board: "Arduino Nano, ATmega328"
                          
                          WARNING: Category 'Sensor' in library DallasTemperature is not valid. Setting to 'Uncategorized'
                          In file included from C:\Users\Admin\Documents\Arduino\Projects\MS Temp sensor node\DallasTemperatureSensor\DallasTemperatureSensor.ino:37:0:
                          
                          C:\Users\Admin\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h: In function 'void loop()':
                          
                          C:\Users\Admin\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h:249:13: error: 'int16_t DallasTemperature::millisToWaitForConversion(uint8_t)' is private
                          
                               int16_t millisToWaitForConversion(uint8_t);
                          
                                       ^
                          
                          DallasTemperatureSensor:85: error: within this context
                          
                             int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                          
                                                                                                               ^
                          
                          Multiple libraries were found for "DallasTemperature.h"
                           Used: C:\Users\Admin\Documents\Arduino\libraries\DallasTemperature
                           Not used: C:\Users\Admin\Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master
                          exit status 1
                          within this context
                          
                          This report would have more information with
                          "Show verbose output during compilation"
                          option enabled in File -> Preferences.
                          
                          S Offline
                          S Offline
                          sjoerd14
                          wrote on last edited by sjoerd14
                          #143

                          regarding error:

                          C:\Users\Admin\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h:249:13: error: 'int16_t DallasTemperature::millisToWaitForConversion(uint8_t)' is private

                          In the latest version of Miles Burton's the function is public and compiling fine.
                          https://github.com/milesburton/Arduino-Temperature-Control-Library

                          You can import the Lib as zip.
                          You have to remove \ archive the lib: ...\libraries\DallasTemperature

                          mfalkviddM 1 Reply Last reply
                          1
                          • S sjoerd14

                            regarding error:

                            C:\Users\Admin\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h:249:13: error: 'int16_t DallasTemperature::millisToWaitForConversion(uint8_t)' is private

                            In the latest version of Miles Burton's the function is public and compiling fine.
                            https://github.com/milesburton/Arduino-Temperature-Control-Library

                            You can import the Lib as zip.
                            You have to remove \ archive the lib: ...\libraries\DallasTemperature

                            mfalkviddM Offline
                            mfalkviddM Offline
                            mfalkvidd
                            Mod
                            wrote on last edited by
                            #144

                            @sjoerd14 yes, thanks to MySensors user David Ducatel. The change is tracked in https://github.com/mysensors/MySensorsArduinoExamples/issues/20 and https://github.com/milesburton/Arduino-Temperature-Control-Library/pull/72 but we're still waiting for an official release of milesburton's library.

                            1 Reply Last reply
                            1
                            • nofoxN Offline
                              nofoxN Offline
                              nofox
                              wrote on last edited by
                              #145

                              Hi, I have few in wall nodes mounted under the light switches. I have two relays and one DS18B20 in each node. When i'm turning light on, switching the relay, the DS18B20 readings jumping about 0.8 degrees celsius up. When I switch off the relay readings back to normal. Anyone have similar problems ? Sensors are away from from node board, relays etc. so it's not about the heat from atmega or relays.

                              1 Reply Last reply
                              0
                              • gohanG Offline
                                gohanG Offline
                                gohan
                                Mod
                                wrote on last edited by
                                #146

                                Is the temperature gradually rising after the relay is activated or it is instantly jumping 0.8°?

                                1 Reply Last reply
                                0
                                • nofoxN Offline
                                  nofoxN Offline
                                  nofox
                                  wrote on last edited by
                                  #147

                                  Jumping 0.8 immediately after switching the relay and sometimes rising very slow during the time when relay is on.

                                  1 Reply Last reply
                                  0
                                  • gohanG Offline
                                    gohanG Offline
                                    gohan
                                    Mod
                                    wrote on last edited by
                                    #148

                                    That makes it quite difficult to figure out the problem. Can you make another node with same setup and see if you get the same results and if you do try unplug the relay and see what happens

                                    1 Reply Last reply
                                    0
                                    • skywatchS Offline
                                      skywatchS Offline
                                      skywatch
                                      wrote on last edited by skywatch
                                      #149

                                      It's probably a voltage drop from the psu when the relay is engaged and drawing current. That will cause the output voltage to dip slightly.

                                      If it is only momentary you can add a beefy capacitor across the power supply, but if the readings change for the whole time the relay is on, you really need to replace the relay with something that uses less power (triac/mosfet??) - Or get a more stable power supply with good regulation.

                                      A final thing might be more noise on the power line with the psu sending more current with the relay on. again a smoothing capacitor would help if this were the case.

                                      You could also try looking into the wiring and see if the relay cables and the ds18b20 cables are far enough apart, some induction might be going on there between the cables. Also, make sure everything goes back to a single ground point. I can't imagine how an earth loop would cause what you describe, but it's always a good thing to do.....

                                      Another thought to think about is matbe the magnetic field from the relap power cables are inducing into the sensor cables.

                                      1 Reply Last reply
                                      0
                                      • ben999B Offline
                                        ben999B Offline
                                        ben999
                                        wrote on last edited by
                                        #150

                                        Hi
                                        Can we talk about redundancy please? What if one or more sensor fail on a one-wire bus? Would it make the whole line unusable?
                                        As part of a central heating MySensorization i would like to have groups of 3 sensors and have some sort of redundancy check.
                                        Would i be allowed to run multiple one-wire busses on a single arduino?
                                        Thanks a lot foryour help

                                        mfalkviddM 1 Reply Last reply
                                        0
                                        • ben999B ben999

                                          Hi
                                          Can we talk about redundancy please? What if one or more sensor fail on a one-wire bus? Would it make the whole line unusable?
                                          As part of a central heating MySensorization i would like to have groups of 3 sensors and have some sort of redundancy check.
                                          Would i be allowed to run multiple one-wire busses on a single arduino?
                                          Thanks a lot foryour help

                                          mfalkviddM Offline
                                          mfalkviddM Offline
                                          mfalkvidd
                                          Mod
                                          wrote on last edited by
                                          #151

                                          @ben999 you can have as many onewire buses as you have digital pins. Just add more of these:

                                          #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                          OneWire oneWire(ONE_WIRE_BUS);
                                          
                                          ben999B 1 Reply Last reply
                                          1
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          10

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 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