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. temp sensor not reading at all

temp sensor not reading at all

Scheduled Pinned Locked Moved Troubleshooting
6 Posts 3 Posters 68 Views 3 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.
  • markjgabbM Offline
    markjgabbM Offline
    markjgabb
    wrote on last edited by
    #1

    hey guys
    ive tried to modify two of the built in designs to make them work together, but i think ive stuffed up the dallas temprature probe

    the temprature is never updated or sent to the controller

    anyone able to advise what ive missed?
    i only have the one temprature sensor hooked up

    
    // Enable debug prints
    //#define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    
    #include <MySensors.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define COMPARE_TEMP 1
    #define MAX_ATTACHED_DS18B20 16
    #define LIGHT_SENSOR_ANALOG_PIN 0
    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
    
    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;
    bool receivedConfig = false;
    bool metric = true;
    unsigned long SLEEP_TIME = 120000 ; // 120000 Sleep time between reports (in milliseconds)
    int lastLightLevel;
    
    
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_LIGHT 2
    
    // Enable repeater functionality for this node
    //#define MY_REPEATER_FEATURE
    
    // Initialize motion message
    MyMessage temp(CHILD_ID_TEMP,V_TEMP);
    MyMessage light(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    
    
    
    //=========================
    // BATTERY VOLTAGE DIVIDER SETUP
    // 1M, 470K divider across battery and using internal ADC ref of 1.1V
    // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
    // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
    // 3.44/1023 = Volts per bit = 0.003363075
    #define VBAT_PER_BITS 0.003363075  
    #define VMIN 1.9                                  //  Vmin (radio Min Volt)=1.9V (564v)
    #define VMAX 3.0                                  //  Vmax = (2xAA bat)=3.0V (892v)
    int batteryPcnt = 0;                              // Calc value for battery %
    int batLoop = 0;                                  // Loop to help calc average
    int batArray[3];                                  // Array to store value for average calc.
    int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
    //=========================
    
    
    void before()
    {
      // Startup up the OneWire library
      sensors.begin();
    }
    
    
    void setup()
    {
      
      sensors.setWaitForConversion(false);
    
      numSensors = sensors.getDeviceCount();
      
     }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Lounge Node enviroment", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      present(CHILD_ID_TEMP, S_TEMP);
    }
    
    void loop()
    {
    //light sensor
      int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
        Serial.print("Light Level:");
        Serial.println(lightLevel);
        if (lightLevel != lastLightLevel) {
            send(light.set(lightLevel));
            lastLightLevel = lightLevel;
    
    //temprature
    
    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(temp.setSensor(i).set(temperature,1));
          // Save new temperatures for next compare
          lastTemperature[i]=temperature;
        }
    
      }
    
      batM();
      // Sleep until interrupt comes in on motion sensor. Send update every two minute.
      sleep(SLEEP_TIME);
    }
        }
    void batM() //The battery calculations
    {
       delay(500);
       // Battery monitoring reading
       int sensorValue = analogRead(BATTERY_SENSE_PIN);    
       delay(500);
       
       // Calculate the battery in %
       float Vbat  = sensorValue * VBAT_PER_BITS;
       int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
       Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
       
       // Add it to array so we get an average of 3 (3x20min)
       batArray[batLoop] = batteryPcnt;
      
       if (batLoop > 2) {  
         batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
         batteryPcnt = batteryPcnt / 3;
     
       if (batteryPcnt > 100) {
         batteryPcnt=100;
     }
     
         Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
           sendBatteryLevel(batteryPcnt);
           batLoop = 0;
          }
         else 
         {
         batLoop++;
         }
    }
     
    
    mfalkviddM 1 Reply Last reply
    0
    • markjgabbM markjgabb

      hey guys
      ive tried to modify two of the built in designs to make them work together, but i think ive stuffed up the dallas temprature probe

      the temprature is never updated or sent to the controller

      anyone able to advise what ive missed?
      i only have the one temprature sensor hooked up

      
      // Enable debug prints
      //#define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      //#define MY_RADIO_RFM69
      
      #include <MySensors.h>
      #include <DallasTemperature.h>
      #include <OneWire.h>
      
      #define COMPARE_TEMP 1
      #define MAX_ATTACHED_DS18B20 16
      #define LIGHT_SENSOR_ANALOG_PIN 0
      #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
      
      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;
      bool receivedConfig = false;
      bool metric = true;
      unsigned long SLEEP_TIME = 120000 ; // 120000 Sleep time between reports (in milliseconds)
      int lastLightLevel;
      
      
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_LIGHT 2
      
      // Enable repeater functionality for this node
      //#define MY_REPEATER_FEATURE
      
      // Initialize motion message
      MyMessage temp(CHILD_ID_TEMP,V_TEMP);
      MyMessage light(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      
      
      
      //=========================
      // BATTERY VOLTAGE DIVIDER SETUP
      // 1M, 470K divider across battery and using internal ADC ref of 1.1V
      // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
      // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
      // 3.44/1023 = Volts per bit = 0.003363075
      #define VBAT_PER_BITS 0.003363075  
      #define VMIN 1.9                                  //  Vmin (radio Min Volt)=1.9V (564v)
      #define VMAX 3.0                                  //  Vmax = (2xAA bat)=3.0V (892v)
      int batteryPcnt = 0;                              // Calc value for battery %
      int batLoop = 0;                                  // Loop to help calc average
      int batArray[3];                                  // Array to store value for average calc.
      int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
      //=========================
      
      
      void before()
      {
        // Startup up the OneWire library
        sensors.begin();
      }
      
      
      void setup()
      {
        
        sensors.setWaitForConversion(false);
      
        numSensors = sensors.getDeviceCount();
        
       }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Lounge Node enviroment", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        present(CHILD_ID_TEMP, S_TEMP);
      }
      
      void loop()
      {
      //light sensor
        int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
          Serial.print("Light Level:");
          Serial.println(lightLevel);
          if (lightLevel != lastLightLevel) {
              send(light.set(lightLevel));
              lastLightLevel = lightLevel;
      
      //temprature
      
      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(temp.setSensor(i).set(temperature,1));
            // Save new temperatures for next compare
            lastTemperature[i]=temperature;
          }
      
        }
      
        batM();
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        sleep(SLEEP_TIME);
      }
          }
      void batM() //The battery calculations
      {
         delay(500);
         // Battery monitoring reading
         int sensorValue = analogRead(BATTERY_SENSE_PIN);    
         delay(500);
         
         // Calculate the battery in %
         float Vbat  = sensorValue * VBAT_PER_BITS;
         int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
         Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
         
         // Add it to array so we get an average of 3 (3x20min)
         batArray[batLoop] = batteryPcnt;
        
         if (batLoop > 2) {  
           batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
           batteryPcnt = batteryPcnt / 3;
       
         if (batteryPcnt > 100) {
           batteryPcnt=100;
       }
       
           Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
             sendBatteryLevel(batteryPcnt);
             batLoop = 0;
            }
           else 
           {
           batLoop++;
           }
      }
       
      
      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @markjgabb the debug output of the node is likely the best first step for troubleshooting.

      1 Reply Last reply
      0
      • markjgabbM Offline
        markjgabbM Offline
        markjgabb
        wrote on last edited by
        #3

        yeah ive checked that

        this is the parsed log below

        it presents the temp sensor, but never sends the temp data

        https://www.mysensors.org/build/parser?log=2131 TSF%3AMSG%3ASEND%2C3-3-0-0%2Cs%3D255%2Cc%3D3%2Ct%3D11%2Cpt%3D0%2Cl%3D22%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3ALounge Node enviroment 2143 TSF%3AMSG%3ASEND%2C3-3-0-0%2Cs%3D255%2Cc%3D3%2Ct%3D12%2Cpt%3D0%2Cl%3D3%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A1.0 2151 TSF%3AMSG%3ASEND%2C3-3-0-0%2Cs%3D2%2Cc%3D0%2Ct%3D16%2Cpt%3D0%2Cl%3D0%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A 2157 TSF%3AMSG%3ASEND%2C3-3-0-0%2Cs%3D1%2Cc%3D0%2Ct%3D6%2Cpt%3D0%2Cl%3D0%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A 2163 MCO%3AREG%3AREQ 2167 TSF%3AMSG%3ASEND%2C3-3-0-0%2Cs%3D255%2Cc%3D3%2Ct%3D26%2Cpt%3D1%2Cl%3D1%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A2 2173 TSF%3AMSG%3AREAD%2C0-0-3%2Cs%3D255%2Cc%3D3%2Ct%3D27%2Cpt%3D1%2Cl%3D1%2Csg%3D0%3A1 2179 MCO%3APIM%3ANODE REG%3D1 2181 MCO%3ABGN%3ASTP 2183 MCO%3ABGN%3AINIT OK%2CTSP%3D1 Light Level%3A4 2188 TSF%3AMSG%3ASEND%2C3-3-0-0%2Cs%3D2%2Cc%3D1%2Ct%3D23%2Cpt%3D2%2Cl%3D2%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A4 Battery percent%3A 125 %25 3696 MCO%3ASLP%3AMS%3D120000%2CSMS%3D0%2CI1%3D255%2CM1%3D255%2CI2%3D255%2CM2%3D255 3702 TSF%3ATDI%3ATSL 3704 MCO%3ASLP%3AWUP%3D-1 3706 TSF%3ATRI%3ATSB Light Level%3A3 3714 TSF%3AMSG%3ASEND%2C3-3-0-0%2Cs%3D2%2Cc%3D1%2Ct%3D23%2Cpt%3D2%2Cl%3D2%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A3 Battery percent%3A 127 %25 5223 MCO%3ASLP%3AMS%3D120000%2CSMS%3D0%2CI1%3D255%2CM1%3D255%2CI2%3D255%2CM2%3D255 5229 TSF%3ATDI%3ATSL

        1 Reply Last reply
        0
        • markjgabbM Offline
          markjgabbM Offline
          markjgabb
          wrote on last edited by
          #4

          ok think i have partially found the issue, when i re did it for a simpler setup, it seems that im measureing temprature of -127 im not even sure what the means, i assume its an error but not sure what its telling me

          1 Reply Last reply
          0
          • markjgabbM Offline
            markjgabbM Offline
            markjgabb
            wrote on last edited by
            #5

            God I'm an idiot. Must of picked up the wrong resistor.

            10k resistor won't help me much

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xreichardx
              wrote on last edited by
              #6

              If your Dallas DS18B20 was purchased on ebay or amazon or elsewhere other than DigiKey, Mouser, etc, it is likely counterfeit and will not work in parasitic power mode and will give a -127.

              Here's a sketch to help determine of the Ds18B20 is genuine and rule-out shoddy counterfeits:

              https://github.com/cpetrich/counterfeit_DS18B20

              I wasted countless days and days with remote sensors only to find they were counterfeit.

              1 Reply Last reply
              1
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              12

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              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