Go Down

Topic: DS18B20 problems (Read 2394 times) previous topic - next topic

mrob73

Jul 15, 2012, 11:39 pm Last Edit: Jul 15, 2012, 11:54 pm by mrob73 Reason: 1
I have not been able to get the DS18B20 temperature sensor to work. I would appreciate any help. I have tried everything I could find on here and the playground, as well as google.
Code: [Select]
// 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
}




Whenever I try this to locate the address I get the following error" 'OneWire' " does not name a type

Using this code,
Code: [Select]
//  This Arduino sketch reads DS18B20 "1-Wire" digital
//  temperature sensors.
//  Copyright (c) 2010 Mark McComb, hacktronics LLC
//  License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
//  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

DeviceAddress insideThermometer = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
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, 10);
 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");
}


results in this error "variable or field 'printTemperature' declared void" Someone please advise me how to correct these problems and get this to work

dxw00d

Have you downloaded, and correctly installed, the OneWire and DallasTemperature libraries, as linked on http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html ? Having done that, the sketches compile fine for me.

MarkT

And libraries have to go in your libraries directory...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

mrob73

Thanks guys I finally got it

MarkT

Care to share what your actual problem was - might help other people in the future searching these forums with similar problem...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

mrob73

It actually turned out to be a hardware issue. I replaced the sensor and everything worked the first time

edmundssprogis

I had 4 rough weeks figuring out why I get bad readings from my DS18B20. I followed almost every recommendation I could get from Internet: I played with pull-up resistors, played with timing constants in OneWire.cpp. Some recommended CAT5 cables, some called for magic resistors, etc. I am in a smart house project using Mega Board, a lot of lights and switches attached and my cables are from the alarm systems - simple and unshielded.

At the end of the day, I did a careful study from the data protocol author Maxim (ex Dallas).
https://www.maximintegrated.com/en/app-notes/index.mvp/id/148

Basically my case was solved by adding a 100 Ohm resistor between Arduino data pin and the the date line and  470pF capacitor from the data line to the ground. This RC scheme is what Maxim recommends for medium-length lines with weights up to 200m

And it works perfectly for me and I hope for you too!

Edmunds

Go Up