title: ESP32: dsb1820 temperature sensor giving constant negative 127 reading
body: <p>I am trying to get a temperature reading using a single dsb1820 temperature sensor attached to an esp32 micro controller. The sensor is attached to GPIO-4 of the esp32. I intend to send the temperature reading to a cloud.</p>
  
  <p>The problem i am facing is that the temperature reading always gives the value -127.</p>
  
  <p>I read somewhere online that when the dsb1820 returns -127 it means that the sensor is not connected.</p>
  
  <p>Am I using the wrong pin to connect the sensor?</p>
  
  <p><a href="https://i.stack.imgur.com/J3HRU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J3HRU.jpg" alt="esp32 pinout"></a></p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "OneWire.h"
  #include "DallasTemperature.h"
  #include &lt;WiFi.h&gt;
  #define WIFI_SSID "SSID"
  #define WIFI_PASSWORD "PASSWORD"
  
  OneWire oneWire(4);
  DallasTemperature tempSensor(&amp;oneWire);
  
  void setup(void)
  {
      Serial.begin(115200);
      WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
      Serial.print("Connecting to Wi-Fi");
      while (WiFi.status() != WL_CONNECTED)
      {
          Serial.print(".");
          delay(300);
      }
      Serial.println();
      Serial.print("Connected with IP: ");
      Serial.println(WiFi.localIP());
      Serial.println();
  
      tempSensor.begin();
  }
  
  void loop(void)
  {
      tempSensor.requestTemperaturesByIndex(0);
  
      Serial.print("Temperature: ");
      Serial.print(tempSensor.getTempCByIndex(0));
      Serial.println(" C");
  
      delay(2000);
  }
  </code></pre>