Sensor DS18B20 problem

hi, I have problem with my sensor ds18b20 in different ways… I copy the code from internet and I have different outputs from them… so i decided to use this code:

i did everything from there and still don`t work… any help?

and here is the output from another code… why is the output that strange?

What is strange?

Post your code, not a picture of it, and post a schematic, not Fritzing and not a photo of your hardware. Draw it in pencil, if you have to, and take a photo of it or scan it.

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

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

void setup(void)
{
Serial.begin(9600);
Serial.println(“Arduino Digital Temperature // Serial Monitor Version”);
sensors.begin();
}

void loop(void)
{
sensors.requestTemperatures();
Serial.print("Temperature is: ");
Serial.println(sensors.getTempCByIndex(0));
delay(1000);
}

198026460_orig.jpg

After sensors.begin() add these statements:

  Serial.print("Number of sensors = ");
  Serial.println(sensors.getDeviceCount());
  Serial.print("Parasite mode = ");
  Serial.println(sensors.isParasitePowerMode());

The number of sensors should, of course, print as 1. If it prints any other number, you've obviously got a problem. According to your diagram and the photo you posted originally, you have the sensor wired up in parasite power mode so this should print 1. If it prints 0 then something is wrong.

Pete

Your photo for reply #1 shows code for an LM35

AWOL: Your photo for reply #1 shows code for an LM35

yea because that`s the only code that show something else other than 0, and i understand that this sensor have inside an lm35 so i tried it..

Make your mind up. Is it an LM35 or a DS18B20?

Pete

what u see in that photo thats what I know too... I buyed it as an BS18B20, thats for sure. But I sayed that about lm35 just because a friend told me that inside its lm35 and shuld work that library too... just sayin

a friend told me that inside it`s lm35

Based on what? How can your “friend” see inside that thing and determine that it is an LM35? Especially when you paid for a DS18B20.

Try this OneWire ROM address scanner. It should print out the address of your DS18B20.

#include <OneWire.h>

#define ONEWIRE_PIN 2
OneWire  ds(ONEWIRE_PIN);

void setup(void) {
  Serial.begin(9600);
  while(!Serial);
  delay(2000);
  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  
  Serial.print("Looking for 1-Wire devices on pin ");
  Serial.println(ONEWIRE_PIN);
  
  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.println("");
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}

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

This is the output I get for one DS18B20:

Looking for 1-Wire devices on pin 2
0x28, 0x84, 0x77, 0xA5, 0x05, 0x00, 0x00, 0x09



That's it.

If it doesn’t find anything, you haven’t wired the sensor properly (or its dead). If it does work, your sketch should also work but add the code I posted in message #4 to see what the Dallas library is seeing.

Pete

it.s not working, I`m getting error on compilation. And the first that from post 4 compile and says that’s no sensor detected

el_supremo:
Try this OneWire ROM address scanner. It should print out the address of your DS18B20.

#include <OneWire.h>

#define ONEWIRE_PIN 2
OneWire  ds(ONEWIRE_PIN);

void setup(void) {
  Serial.begin(9600);
  while(!Serial);
  delay(2000);
  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
 
  Serial.print(“Looking for 1-Wire devices on pin “);
  Serial.println(ONEWIRE_PIN);
 
  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.println(”");
  }
  Serial.print("\n\r\n\rThat’s it.\r\n");
  ds.reset_search();
  return;
}

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




This is the output I get for one DS18B20:


Looking for 1-Wire devices on pin 2
0x28, 0x84, 0x77, 0xA5, 0x05, 0x00, 0x00, 0x09

That’s it.




If it doesn't find anything, you haven't wired the sensor properly (or its dead). If it does work, your sketch should also work but add the code I posted in message #4 to see what the Dallas library is seeing.

Pete

it.s not working, I`m getting error on compilation.

The only way that the IDE could report an undefined reference to loop() is if you did not copy ALL the code that I posted - it does have a loop function at the end. But there's no way for me to tell because you posted a screen capture image instead of copying and pasting the text itself. Before you post any code, read How to post code properly and post the code in code tags. You can do the same with the error messages from the IDE.

But if the code I posted in #4 reports zero devices, you've got a wiring problem or a dead sensor.

Pete