Go Down

Topic: DS18B20 problem with wiring (Read 458 times) previous topic - next topic

zahidaoui

Hi all,
I have not been able to get the DS18B20 temperature sensor to work. I followed all the steps that I found in this website http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html. Here is the code that I used in arduino:

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
}


and the main error that I am getting is : 'OneWire' does not name a type
thanks for any help

wildbill

Compiles fine for me in IDE 1.0. It sounds like it isn't finding the library which could be that you don't have it, installed it in the wrong place, or haven't restarted the IDE since you did install it.

zahidaoui

Wow that easy !! thanks man it worked as soon as I restarted my laptop :)

zahidaoui

One more thing.. now that it worked, I uploaded the program, the serial monitor is giving me the following result:

Found '1-Wire' device with address:

0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFFCRC is not valid!

what could the reason be?

wildbill

Check your wiring, paying particular attention to the datasheet - IIRC, it shows the pinout looking from the bottom, which caught me out.

Go Up