DS18B20 temperature sensor, no readings

I’m trying to get temperature measurements out from a DS18B20 sensor. The code I use is taken from this website: http://www.hobbytronics.co.uk/ds18b20-arduino and I have the exact same coupling.

This is the code I use:

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2

// 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(void)
{
// start serial port
Serial.begin(9600);
Serial.println(“Dallas Temperature IC Control Library Demo”);

// Start up the library
sensors.begin();
}

void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperatures…");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println(“DONE”);

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

}

The output I get from this is -127 degrees C. If I remember right the arduino doesn’t even communicate with the sensor when you get this output?

Anyway, does anybody know how whats wrong and how I can fix this?

Thanks in advance!

Describe how you have wired it up. Did you include a pullup resistor?

ylva:
and I have the exact same coupling.

You probably don't, and you are right, -127 tells you the connection is bad. If the sensor gets seriously hot, you have the power the wrong way round.

You might get better tutorial here

Problem fixed.

You were right, it was the wrong coupling.

If anybody else is as confused as I was and ending up at this page: There are different types of DS18B20, some of them have the 4,7kOhm built in and the pins aren't in the same order as on the datasheet.

For how this pin looks and how to couple it look at this page: (in swedish though) http://www.kjell.com/sortiment/el/elektronik/mikrokontroller/arduino/temperatursensor-for-arduino-p87883

or read more here:
http://www.dx.com/p/ds18b20-digital-temperature-sensor-module-for-arduino-55-125-c-135047#.VUxoj_ntmkp