I'm working on a project that will essentially control a fan when the temp hits a certain threshold. I'm using the DS18B20 for determining the temperature and it's not being detected by the Dallas Control example, however, it is reading a temperature of -127*. I can attest that it most certainly is not -127* in my living room.
Any ideas? I am using the 4.7k resister between +5 and the data pin and the other two are connected to +5 and GND accordingly. The DS18B20's are from China, via eBay so the configuration could be different from standard devices, is there any way to verify which wire is designated for data, +5V and GND? I have red, black and blue wires, so I assume the blue wire is data, red is +5V and black is GND.
A friend of mine bought some DS18B20 from China - the kind that are sealed and have about a metre of wire on them - and he had the same problem. He took one apart and found that the +5V and data lines were wired the opposite way around from what their diagram showed. Try swapping the data and +5V.
I tried that, and nothing. I am wondering if my Arduino itself is screwed up. I have a relay circuit from sparkfun and it doesn't seem to flip when I set the pin to high/low. I don't have my meter handy at the moment, but perhaps I will test some of the pins tomorrow to see if there is voltage there when they are high.
Anything else to check? Maybe do a hard reset on the Arduino?
Sorry for the delay. I have a 9v adapter, and tried it today but still nothing. The code is as follows, and it is running on an Uno.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 10
// 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);
// arrays to hold device address
DeviceAddress insideThermometer;
void setup(void)
{
 // start serial port
 Serial.begin(9600);
 Serial.println("Dallas Temperature IC Control Library Demo");
 // locate devices on the bus
 Serial.print("Locating devices...");
 sensors.begin();
 Serial.print("Found ");
 Serial.print(sensors.getDeviceCount(), DEC);
 Serial.println(" devices.");
 // report parasite power requirements
 Serial.print("Parasite power is: ");
 if (sensors.isParasitePowerMode()) Serial.println("ON");
 else Serial.println("OFF");
Â
 // assign address manually. the addresses below will beed to be changed
 // to valid device addresses on your bus. device address can be retrieved
 // by using either oneWire.search(deviceAddress) or individually via
 // sensors.getAddress(deviceAddress, index)
 //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
 // Method 1:
 // search for devices on the bus and assign based on an index. ideally,
 // you would do this to initially discover addresses on the bus and then
 // use those addresses and manually assign them (see above) once you know
 // the devices on your bus (and assuming they don't change).
 if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
Â
 // method 2: search()
 // search() looks for the next device. Returns 1 if a new address has been
 // returned. A zero might mean that the bus is shorted, there are no devices,
 // or you have already retrieved all of them. It might be a good idea to
 // check the CRC to make sure you didn't get garbage. The order is
 // deterministic. You will always get the same devices in the same order
 //
 // Must be called before search()
 //oneWire.reset_search();
 // assigns the first address found to insideThermometer
 //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
 // show the addresses we found on the bus
 Serial.print("Device 0 Address: ");
 printAddress(insideThermometer);
 Serial.println();
 // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
 sensors.setResolution(insideThermometer, 9);
 Serial.print("Device 0 Resolution: ");
 Serial.print(sensors.getResolution(insideThermometer), DEC);
 Serial.println();
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
 // method 1 - slower
 //Serial.print("Temp C: ");
 //Serial.print(sensors.getTempC(deviceAddress));
 //Serial.print(" Temp F: ");
 //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit
 // method 2 - faster
 float tempC = sensors.getTempC(deviceAddress);
 Serial.print("Temp C: ");
 Serial.print(tempC);
 Serial.print(" Temp F: ");
 Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
}
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");
Â
 // It responds almost immediately. Let's print out the data
 printTemperature(insideThermometer); // Use a simple function to print out the data
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
 for (uint8_t i = 0; i < 8; i++)
 {
  if (deviceAddress[i] < 16) Serial.print("0");
  Serial.print(deviceAddress[i], HEX);
 }
}
Ok, I figured it out. I hadn't noticed there is a GND on the side with the digital pins. I moved the GND to that pin, and it seems to be working perfectly fine now.
I'm having the same problem (i.e., DS18B20 from China "not detected"). mbaker, did your sensor have the data and 5v wires switched (i.e., red=data, yellow=5v)???
An additional note.... the power and ground pins on the board are confirmed to be what they are supposed to be (5v and GND). I am using the Dallas library sketch "tester" to try to detect and test the sensor setup.
Hi,
DS18B20 info and multiple code examples on the ArduinoInfo.Info WIKI HERE:
I have sold over 3000 of the Waterproof encapsulated DS18B20 sensors like THIS: and I have never seen one where the Vcc was not Red and the Ground Black. The SIGNAL has sometimes been Yellow or Blue.
I had the same problem. Ultimately it dawned on me that the waterproof ds18b20 i got from ebay almost certainly didn't have the pull-up resistor. It works now. I will probably put together a onewire breakout board with a single pull-up for multiple sensors.
I just wish my waterproof ds18b20 wasn't so slow to react. I think the people who assembled it probably didn't use anything to thermally couple the part with the metal shell. If anyone knows a vendor that sells one that reacts a little faster i would appreciate knowing. Short of that i may find some brass tube and make my own. This is just something i am doing for fun but i dream of using an arduino for engine sensors and data logging in a future project.
Timpanogos_Slim:
I just wish my waterproof ds18b20 wasn't so slow to react.
Well, what's slow? I can grab a sensor and see the change the next time round on a one second loop. Anything faster would be stretching the friendship with the reading cycle.