Lost getting started with Maxim digital thermometer

Hi all:

My first post here, so forgive me if this is previously asked/answered.

I'm trying to get a temperature reading from a DS18S20 temp sensor, and I'm getting stuck somewhere, but I don't have enough information to know what I'm doing.

First of all, I'm not sure I understand how to wire the sensor correctly. I'm trying to use the powered mode, because I can't for the life of me figure out how the parasite mode is supposed to be wired. But if I'm doing powered mode, is this right?

sensor pin 3: 5v, through 4.7K resistor (the other end of which goes between pin 2 and the data wire out to arduino? This part makes no sense to me)
sensor pin 2: the other end of the 4.7k resistor, then to the data wire
sensor pin 3: Ground

Thanks for your help,

-mike

Hi Mike

Here's what you need :

pin 1 goes to Ground
pin 2 goes to input pin and to 4k7. Other side of 4k7 goes to 5v
pin 3 goes to 5v

(edited to show correct pins)

see attached drawing.

Next, you need to get the sensors unique address.

To do this, upload and run the following, which will detect the address and display it in the Serial Monitor :

// This sketch looks for 1-wire devices and
// prints their addresses (serial number) to
// the UART, in a format that is useful in Arduino sketches
// Tutorial: 
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#include <OneWire.h>

OneWire  ds(3);  // Connect your 1-wire device to pin 3

void setup(void) {
  Serial.begin(9600);
  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  
  Serial.print("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr[i] < 16) {
        Serial.print('0');
      }
      Serial.print(addr[i], HEX);
      if (i < 7) {
        Serial.print(", ");
      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}

void loop(void) {
  // nothing to see here
}

After you get the unique address, copy it from the serial monitor and place it into the following code :

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

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

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

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html



//add the unique address to the following line

DeviceAddress insideThermometer = { 0x28, 0xCC, 0xD1, 0xE1, 0x02, 0x00, 0x00, 0xE6 };




//use the next code if you add additional sensors
//DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
//DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 11);
//  sensors.setResolution(outsideThermometer, 10);
//  sensors.setResolution(dogHouseThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop(void)
{ 
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("Inside temperature is: ");
  printTemperature(insideThermometer);
  Serial.print("\n\r");
//  Serial.print("Outside temperature is: ");
//  printTemperature(outsideThermometer);
//  Serial.print("\n\r");
//  Serial.print("Dog House temperature is: ");
//  printTemperature(dogHouseThermometer);
//  Serial.print("\n\r\n\r");
}

DRAWING12.jpg

I had the pin numbers incorrect and have already edited the previous post.

pin 1 goes to Ground
pin 2 goes to input pin and to 4k7. Other side of 4k7 goes to 5v
pin 3 goes to 5v

You will also need to download the libraries from the URL included in the sample code.
.

Also, as you see from the diagram, you can have multiple sensors all on the same input pin.

For each sensor, you need to run the first sample code to get each sensors unique address (with only 1 sensor connected), and add it to the second sample code so your code knows which data coming into the input pin is for which sensor.

Thanks a million, DaveO! Everything worked like a charm, though I did have to tweak one small thing to get the code to work to detect the sensor address.

Where you put:

if (addr < 16) {

and:

Serial.print(addr, HEX);

I think in both cases it needs to be addr
But I'm all set, recording temperatures all over the place (well, not all over the place - actually very consistantly. If they were all over the place that would be a different kind of error :wink: ). Thanks again!

Very weird -- it cut off what I was trying to correct -- maybe you had it right originally and it did the same thing to you.

I was trying to write that it should be:

addr[i]

OK. Looks like the code I pasted into the "quote" box didn't appear as pasted.

Have edited the original reply and moved the code to a "code" box - looks correct now.