user60284: ive used one DS1820B sensor in a AVR bread board circuit and it works there, now i tried attaching it to a arduino mega board with the code below and also another library below that.
currently the data pin is connected to pin 10 on the arduino board, but i also tried pin 2 as in this picture:  
https://lastminuteengineers.com/wp-content/uploads/2018/12/Wiring-Multiple-DS18B20-Temperature-Sensors-With-Arduino.png 
i changed: #define ONE_WIRE_BUS 10   accordingly.
So after that i put the chip back onto the bread board and it still works.
I also tried it with the 4.7k resistor on the data line as pullup....still -127.
Any ideas?
#include <SPI.h>
#include <SD.h>
/********************************************************************/
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS 10
/********************************************************************/
// 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 sensors(&oneWire);
/********************************************************************/ 

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 sensors.begin(); 
}


void loop() {

  Serial.print("Temperature is: "); 
 Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?  
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
   delay(1000); 


}

second code:  
#include "DS18B20Events.h"

// Pin for DS18B20
#define ONE_WIRE_BUS 10

/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices  
// (not just Maxim/Dallas temperature ICs) 
OneWire oneWire(ONE_WIRE_BUS);

// Init DallasTemperature
DallasTemperature dallasTemperature(&oneWire);

//Init thermometer with index 0 (default)
DS18B20Events thermometer(0);

// the setup function runs once when you press reset or power the board
void setup() {  
  Serial.begin(9600);
  DS18B20Events::setup(&dallasTemperature); // Link DS18B20Events to DallasTemperature object
  DS18B20Events::setInterval(5000); // Set min interval in milliseconds between 2 measurements. Default 10000 set in setup() method.

  // subscribe to temperature changed event
  thermometer.onChange = temperatureChanged;
}

// the loop function runs over and over again until power down or reset
void loop() {
  thermometer.loop(); // Mandatory to measure temperature and fire an event if needed

  Serial.print(thermometer.getTempC()); // Get last measured tempC if needed.
  Serial.print(" measured ");
  Serial.print((millis() - thermometer.getMillis()) / 1000);
  Serial.println(" seconds ago.");

  delay(1000);
}

void temperatureChanged(uint8_t index, float tempC)
{
  Serial.print(tempC);
  Serial.print(" new tempC at index ");
  Serial.println(index);
}


user57281: 127 error is a connection error, check the wiring:


60284: <p>ive used one DS1820B sensor in a AVR bread board circuit and it works there, now i tried attaching it to a arduino mega board with the code below and also another library below that.</p>

<p>currently the data pin is connected to pin 10 on the arduino board, but i also tried pin 2 as in this picture:  </p>

<p><a href="https://lastminuteengineers.com/wp-content/uploads/2018/12/Wiring-Multiple-DS18B20-Temperature-Sensors-With-Arduino.png" rel="nofollow noreferrer">https://lastminuteengineers.com/wp-content/uploads/2018/12/Wiring-Multiple-DS18B20-Temperature-Sensors-With-Arduino.png</a>  </p>

<p>i changed: #define ONE_WIRE_BUS 10   accordingly.</p>

<p>So after that i put the chip back onto the bread board and it still works.
I also tried it with the 4.7k resistor on the data line as pullup....still -127.</p>

<p>Any ideas?</p>

<pre><code>#include &lt;SPI.h&gt;
#include &lt;SD.h&gt;
/********************************************************************/
// First we include the libraries
#include &lt;OneWire.h&gt;
#include &lt;DallasTemperature.h&gt;
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS 10
/********************************************************************/
// 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 sensors(&amp;oneWire);
/********************************************************************/ 

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 sensors.begin(); 
}


void loop() {

  Serial.print("Temperature is: "); 
 Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?  
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
   delay(1000); 


}
</code></pre>

<p>second code:  </p>

<pre><code>#include "DS18B20Events.h"

// Pin for DS18B20
#define ONE_WIRE_BUS 10

/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices  
// (not just Maxim/Dallas temperature ICs) 
OneWire oneWire(ONE_WIRE_BUS);

// Init DallasTemperature
DallasTemperature dallasTemperature(&amp;oneWire);

//Init thermometer with index 0 (default)
DS18B20Events thermometer(0);

// the setup function runs once when you press reset or power the board
void setup() {  
  Serial.begin(9600);
  DS18B20Events::setup(&amp;dallasTemperature); // Link DS18B20Events to DallasTemperature object
  DS18B20Events::setInterval(5000); // Set min interval in milliseconds between 2 measurements. Default 10000 set in setup() method.

  // subscribe to temperature changed event
  thermometer.onChange = temperatureChanged;
}

// the loop function runs over and over again until power down or reset
void loop() {
  thermometer.loop(); // Mandatory to measure temperature and fire an event if needed

  Serial.print(thermometer.getTempC()); // Get last measured tempC if needed.
  Serial.print(" measured ");
  Serial.print((millis() - thermometer.getMillis()) / 1000);
  Serial.println(" seconds ago.");

  delay(1000);
}

void temperatureChanged(uint8_t index, float tempC)
{
  Serial.print(tempC);
  Serial.print(" new tempC at index ");
  Serial.println(index);
}
</code></pre>
 57281: <p>127 error is a <strong>connection error</strong>, check the wiring:</p>

<p><a href="https://i.stack.imgur.com/UXxjz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UXxjz.jpg" alt=""></a></p>
