Need a source for a GENUINE DS18B20 in the waterproof configuration

The data sheet calls for a 4.7k

Did you test to make sure you can read a device serial number?


Double check Vdd &Gnd are not swapped.

No. 4.7k

This may be true. If so, I think it suggests you should never see the 85 if you use the library, but people do. Multiple 85s is really serious. I think the answer is in reply #16.

Here is what I would try. Create a new sketch and code it just like this. Read the link.

/********************************************************************/
// First we include the libraries
#include <OneWire.h> 
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS 2 
/********************************************************************/
// 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);
/********************************************************************/ 
void setup(void) 
{ 
 // start serial port 
 Serial.begin(9600); 
 Serial.println("Dallas Temperature IC Control Library Demo"); 
 // Start up the library 
 sensors.begin(); 
} 
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 temperature readings 
 Serial.println("DONE"); 
/********************************************************************/
 Serial.print("Temperature is: "); 
 Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?  
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
   delay(1000); 
}

This will at least tell you if the sensor alone is working correctly. That done move along and back to your code.

Again as has been stressed a 4.7 K resistor between the Data Out and Vcc.

Ron

The same place as in the example code I quoted.

Well, it's all working. Swapped in the correct resistor, then Plugged in the sample temperature sensor code. Result: The motor runs and responds appropruiately to the throtte, the temp signal is stable/sane, and when it's running, exceeding the temperature levels I set causes the motor to cut its speed appropriately. Then when the temperature drops, the motor goes back to full power.

Thanks everybody!

My code, if anybody is interested, follows.

/********************************************************************/
// First we include the libraries
#include <OneWire.h> 
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS 2 
/********************************************************************/
// 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);
/********************************************************************/ 
// Start adding motor control stuff

int potPin = A0;
int motorPin = 9;
int potValue = 0;
int motorValue = 0;

/********************************************************************/

void setup(void) 
{ 
 // start serial port 
 Serial.begin(9600); 
 Serial.println("Dallas Temperature IC Control Library"); 
 // Start up the library 
 sensors.begin(); 

/********************************************************************/
// Add motor control code

  //TCCR1B = TCCR1B & B11111000 | B00000101; // enable to set for PWM frequency of 30.64 Hz
  //pinMode(5, OUTPUT);  //DPin-5 is output to drive LED2 (yet to test)
  //pinMode(13, OUTPUT);  //DPin-13 is output to drive L (built-in LED og UNO)
  pinMode(9, OUTPUT); //readies pin 9
  pinMode(A0, INPUT); //readies analog in


} 
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 temperature readings 
 Serial.println("DONE"); 
/********************************************************************/
 Serial.print("Temperature is: "); 
 Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
 float myTemp = sensors.getTempCByIndex(0); 
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
   delay(1000);  
/********************************************************************/
// Motor Control
potValue = analogRead(potPin);   
motorValue = map(potValue, 137 , 907, 0, 245);// sets scale to Subaru pedal
  if (motorValue < 0) motorValue = 0; //never drop below zero
  if (motorValue < 4) motorValue = 0; //stop random judders
  if (motorValue > 245) motorValue = 245; //caps top end
if (myTemp>65)  motorValue=motorValue/2; //Cuts motor power whenever temp exceeds value
if (myTemp>75)  motorValue=motorValue/4;
if (myTemp>80)  motorValue=motorValue/8;// in prod do 65,75,80
 analogWrite(motorPin, motorValue);  //Sends PWM signal out
  Serial.println();
 Serial.print("potentiometer = " );     
 Serial.print(potValue);
 Serial.print("t motor = ");  
 Serial.println(motorValue); 
}

Several sensors can be used on the same bus (Arduino pin). Count starts from zero.
sensors.getTempCByIndex(3) would get the temp in Celcius (note the "C") from the fourth sensor.
Fourth as organised by serial number burned into the sensor.
Leo..

I have been working with the DS18B20 for 10+ years. I have worked with both genuine ones and fake ones. The code in the OneWire.h file I do not like. Timing for 1-wire protocol is very touchy. So much so that I've seen OneWire.h code fail on an Arduino that was located outside in 40 degree weather (or low voltage or anything else that can cause the oscillator frequency to shift just a little). The colder temperature changed the timing enough to cause readings to fail. If you are using a tight oscillator that doesn't vary much with temperature, you'll probably be fine. Otherwise (forklift...outside weather) you may find that you still get issues even when using a genuine DS18B20 (Mouser, Digi-Key both have genuine parts). So, I have discovered what I feel is a rock solid alternative solution...and an easy one at that.

Look up DS2484 which is a 1-wire to I2C bridge IC or a DS2482 which is a 8x 1-Wire to I2C bridge. These ICs can be used with ANY 1-wire device. Use of this IC has made my 1-wire communication so much easier and foolproof since timing is all handled by the IC and it has a -40 to 85 degree Celsius operating range. Also note that the query success for fakes ones goes up quite a bit using this IC as well. I've had 100% failure using the OneWire.h library on fake DS18B20s only to see them be successful on the DS2484 IC (I now have a test board that uses this IC just for testing 1-wire devices rather than using the OneWire.h library). So even though Ron_Blain has posted what is considered a solution (that most people use). I feel this additional information is paramount for anyone else since given the temperature variation and fake DS18B20s out there (or any 1-wire device for that matter), this solution is more solid for critical requirements.

As a side note, using faster MCUs like the STM32 family or even a CPLD/FPGA, you can get timing to be much improved such that the DS2484 IC could be skipped. The above is mostly for Atmel based MCUs running the internal (not so accurate) 8MHz oscillator or the external (better) 16MHz can oscillator (but still not great under temperature variations). If you have a custom board that uses a more precise oscillator or have replaced the one on the Arduino board with a more precise one your results may differ.

1 Like

Thank you, I will check that out. Since the price of a malfunctioning sensor is a non-drivable auto, I wanty to implement the most robust solution I can.

You can make your own.

Use a spent brass bullet cartridge, fill with epoxy, insert DS18B20.


BTW, you can disable the wait time needed to read these sensors.

Or get the original ones.
Leo..

Just curious, have you considered the lowly NTC resistor for temperature? Perhaps not as accurate and the DS18B20 but should be very reliable.

I don't check this forum often. But...using this IC will require a change in your code to implement the DS18B20 via the I2C bus (probably someone by this time has already done it, but just in case). If you are a coder, you'll find it fairly easy to do. If you are a coder that downloads all libraries you can and follows example code all the time...this could prove a little difficult.

I have code for the Atmel that manages the I2C to 1-Wire for at least the DS18B20. If you decide this route is definitely the better way to go and if you have any trouble with the code conversion, let me know and I'll dig up the code and post it here.

If you decide to go with STM32 instead, let me know that as well and I'll find that code instead noting though that it will be written for the STM32 IDE (STM32CubeIDE). Note that the Arduino IDE now supports most STM32 MCUs though, so you don't need to use the STM32CubeIDE to use this far superior MCU (even though I'd tell you that STM32CubeIDE makes the Arduino IDE look like something slightly better than notepad). On the other hand though, if you do use the Arduino IDE...the STM32 code I have would require some rework and that would be up to you to do (I'll help with any code I have - but I code professionally and just don't have the time these days to do side coding for free).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.