PDA

View Full Version : cheap ds18b20's, are they legit??



Heckler
- 26th May 2011, 14:55
I bought 10 of these, and the price is un-beatable (if you can wait for delivery from hong kong)

BUT I can't help but wonder if they are genuine or knock-off's.
What do you all think? The price is amazingly low.

They do all work but I'm not sure they all show the exact same temperature... I need to work out code where I could place them all in a line on one wire and read them sequentially using the addressing feature. Right now I have to pick them up with a pair of pliers and put them in the bread board to read them.

Could it be that they are seconds??

http://cgi.ebay.com/10pcs-DS18B20-DS1820-1-Wire-Digital-Thermometer-Dallas-/250615925588?pt=LH_DefaultDomain_0&hash=item3a59df8b54

just wondering...

ScaleRobotics
- 26th May 2011, 15:16
Something sounds a little fishy.

If you buy direct from Maxim, they are 1.85 each by the thousand. Your ebay is 1.29 each.

Here is a interesting story about a fake IC that didn't even work:
http://www.sparkfun.com/news/350

If you read all the links, they eventually found out (sort of) what it was. Nothing close to what was stamped on it.
http://www.sparkfun.com/news/384

cncmachineguy
- 26th May 2011, 17:05
Wow, great story, thanks for sharing Walter :)

Heckler
- 26th May 2011, 19:56
Well,
The DS18B20's I bought DO all work correctly. I have read each one and they all report a reasonably accurate temperature. I am right now writing(copying and modifying) some code to read them all in a row. Thanks to Bruce's code at rentron... http://www.rentron.com/PicBasic/one-wire2.htm

I will report back after I am able to read them all simultaneously. They are very sensitive and so if you handle them it can change their tempurature by a few degrees. But they definately do work and are reasonably accurate.

ScaleRobotics
- 26th May 2011, 20:07
That's good to hear. Maybe someone just bought too many, and now they are trying to get rid of them. Still makes me skeptical though, and free shipping. (I might have to buy some!) Do you have a camera that can take a photo of the front in macro? Not sure we would see anything, but it might be interesting to compare to known samples.

Heckler
- 27th May 2011, 00:09
YEP!! they are all reading very close to each other...
Below is a sequential read of nine sensors that are all in parallel on a bread board:

1 TempC = +25.1250 C
2 TempC = +25.2500 C
3 TempC = +25.1875 C
4 TempC = +25.1250 C
5 TempC = +25.625 C
6 TempC = +25.625 C
7 TempC = +25.625 C
8 TempC = +25.625 C
9 TempC = +25.0 C

I modified Bruces code that is posted on rentron. First I read each serial number and made a note of it as I placed it in line on the bread board. Then I did a For/Next read of each sensor and displayed the temp using debug.

I also sequentially touched each one with a hot soldering iron and watched just that sensor change in value confirming that I, indeed, was reading each sensor.

5549

5550

If anybody is interested in my test code... I would be happy to post it. I used a 16F690 on a Microchip LowPinCount demo board with pickit2. You can see all nine sensors lined up 3 x 3 on the breadboard.

Heckler
- 27th May 2011, 00:17
Also please note the above ebay listing is actually NOT the vendor I purchased from... I bought from this vendor...
http://cgi.ebay.com/10-QTY-DS18B20-Thermometer-Temperature-Sensor-Dalla-IC-/120714291395?pt=LH_DefaultDomain_0&hash=item1c1b21e8c3

I paid $15USD
Now he is selling them for even CHEAPER!!! 10 for $9.80
The vendor ID is cwithk.


Here is the latest read of all nine sensors:
1 TempC = +25.3125 C
2 TempC = +25.4375 C
3 TempC = +25.3750 C
4 TempC = +25.3750 C
5 TempC = +25.2500 C
6 TempC = +25.2500 C
7 TempC = +25.1875 C
8 TempC = +25.2500 C
9 TempC = +25.1875 C

Archangel
- 28th May 2011, 03:56
If anybody is interested in my test code... I would be happy to post it. I used a 16F690 on a Microchip LowPinCount demo board with pickit2. You can see all nine sensors lined up 3 x 3 on the breadboard.

I would say Please post your code, someone will find it useful, I will archive it as an example in MY Computer, for sometime in the future, I am sure I will not be the only one. BTW I use those demo boards too . . .
If the chips actually work, I doubt they're counterfeits, it would not surprise me if they are old or not RoHS compliant.
Order 2500 at mouser for $2.09 each . . . I am getting even more sure of my opinion about old stock . . . and those You have shown, Look Old too . . . http://www.mouser.com/Search/Refine.aspx?Keyword=DS18B20&Ns=Pricing|0&FS=True (http://www.mouser.com/Search/Refine.aspx?Keyword=DS18B20&Ns=Pricing%7C0&FS=True)

mackrackit
- 28th May 2011, 08:40
I say post your code as an article. Very interesting test project.

ScaleRobotics
- 28th May 2011, 16:09
Yes, very interesting project. I will keep an eye on this thread.

As for whether they are fakes, sounds like they work. The printing on yours vs a known sample I got directly from Maxim look approximately the same to me. Both seem to have letters that are slightly askew. Yours seems to have the S in DALLAS raised maybe slightly more.

Looks to be a good bargain. So I bought some too!

55665567

gadelhas
- 28th May 2011, 20:48
Hi everyone,

I share with you my experience in buying parts on ebay.

I already bought from Hong Kong and China suppliers, 5X LM3914, 5X LM3915, 10X LM358N, 2 X PL2303HX, 10X MC34063, and i never had problems with them and always worked fine.

If someone want, i can post here the suppliers where I bought the components.
In some cases the price in my local shop is 2 or 3 times more then the price of the ebay suppliers.

Heckler
- 28th May 2011, 22:44
mackrackit

I say post your code as an article. Very interesting test project.


I'm not sure how to post my code as an article...
Should I attach them as files or post the code in a code window.

Then, does a moderator change it to an article??
I am ready to post the code, but I'll wait to hear your response.

thanks

ScaleRobotics
- 28th May 2011, 23:46
That's great!

You can either post it here, and we will promote it to an article, or you can start a new wiki article, and when you are ready, we can hit the publish button, so it can be seen by all.

For shorter code, you could just put it in between code tags. If its a bit long, you could just post a clip of it, then attach the whole file as a zip.

Thanks,

Walter

Heckler
- 29th May 2011, 06:14
Ok, so here is the code that will read an individual DS18b20 and output the unique 64 bit serial code. Which include the Family Code, Serial Number and CRC.

This code assumes you are using a PIC16F690, so if you want to use a different micro you may need to modify the initialization to fit your needs.

This information is sent to a Debug window. If you are using a PICkit 2(and probably PICkit3 also) you program the chip, power it up and then goto the Tools Menu and choose UART Tool. This will open up another Terminal window where you choose 2400 baud in the upper left and then click on Connect.

You should then see the various parts of the 64 bit serial code being displayed every 5 seconds. You can simply leave the program running and hot swap sensors onto your breadboard. As each is read and displayed the text will be available to scroll back through. After you change out each sensor, you can then simply copy and past each of the Serial Numbers into the second program which will then be able to read multiple devices that are all connected to the same pin on your microcontroller. In particular, the last line of the debug display is assembled with $ and , to make the code ready to past right into the program.


'************************************************* ***************
'* Name : *
'* Author : Bruce Reynolds modified By Dwight Merkley *
'* Notice : *
'* : *
'* Date : 7/28/2003 *
'* Version : 1.0 *
'* Notes : PIC16f690 *
'************************************************* ***************
Reset:
TrisA = %00011000 'Port A3,A4 inupts rest outputs (A3 cannot output)
TrisB = %00000000 'Port B all outputs
TrisC = %00000000 'Port C all outputs
ansel = 0 'and turn off analog
AnselH = 0 'turn of rest of analogs
CM1CON0 = 0 'turn off comparators
CM2CON0 = 0 'turn off comparators
SSPCON.bit5 = 0 ' disable serial port, pins are I/O
OPTION_REG = %10000000 '1 turn off weak pull ups
INTCON = %00000000
'===========================================
DQ var PortA.4 ' One-wire Data-Pin "DQ" on PortA.4
Busy VAR BIT ' Busy Status-Bit
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code
DEFINE DEBUG_REGG PORTA 'set debug port to porta
DEFINE DEBUG_BIT 0 'use pin a0 of porta for debug
DEFINE DEBUG_BAUD 2400 'set baud rate to 2400
DEFINE DEBUG_MODE 0 'communicate in true mode
'================================================= ====================
portC=0 'turn off LED's on breadboard
Begin:
PAUSE 500 ' Wait .5 second

Start_Convert
OWOUT DQ, 1, [$33] ' Issue Read ROM command
'///////////////////////////////////////////////////////////////////////////
' ' READ ROM [$33] [(from Maxim documentation)]
' 'This command can only be used when there is one slave on the bus.
' 'It allows the bus master to read the slave’s 64-bit ROM code without
' 'using the Search ROM procedure. If this command is used when there
' 'is more than one slave present on the bus, a data collision will
' 'occur when all the slaves attempt to respond at the same time.
'///////////////////////////////////////////////////////////////////////////
ID_Loop:
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
debug $0D,$0A 'do a linefeed and carrage return
DEBUG "64bit = ",HEX2 ID[0],HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],HEX2 ID[7],"h",$0D,$0A
DEBUG "Family Code = ",HEX2 ID[0],"h",$0D,$0A
DEBUG "Ser# = ",HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],"h",$0D,$0A
DEBUG "CRC Value = ",HEX2 ID[7],"h",$0D,$0A
debug ">>> the following is complete ID of device <<<",$0D,$0A
debug "[$",HEX2 ID[0],",$",HEX2 ID[1],",$",HEX2 ID[2],",$",HEX2 ID[3],",$",_
HEX2 ID[4],",$",HEX2 ID[5],",$",HEX2 ID[6],",$",HEX2 ID[7],"]",$0D,$0A
PAUSE 5000 ' 5-second pause, replace sensor for next read
GOTO Start_Convert

END



Now this next piece of code is used once you copy and past into the "SELECT CASE" portion of the code at the end. You will need to replace the ones that I used with the ones that match the sensors you are reading. Also if you want to read more or less than 9 sensors you need to modify the "for sensor=1 to 9" statement to match your quantity. This code will read any number of OneWire sensors(In my case DS18B20's) and display the value in a debug window.


'************************************************* ***************
'* Name : Temp.BAS *
'* Author : Bruce Reynolds modified by Dwight Merkley *
'* Notice : Copyright (c) 2003 Reynolds Electronics *
'* : All Rights Reserved *
'* Date : 7/28/2003 *
'* Version : 1.0 *
'* Notes : code originates from www.rentron.com (http://www.rentron.com) *
'* : PIC 16F690 *
'************************************************* ***************
Reset:
TrisA = %00011000 'Port A3,A4 inupts rest outputs (A3 cannot output)
TrisB = %00000000 'Port B all outputs
TrisC = %00000000 'Port C all outputs
ansel = 0 'and turn off analog
AnselH = 0 'turn of rest of analogs
CM1CON0 = 0 'turn off comparators
CM2CON0 = 0 'turn off comparators
SSPCON.bit5 = 0 ' disable serial port, pins are I/O
OPTION_REG = %10000000 '1 turn off weak pull ups
INTCON = %00000000
'===========================================
DQ var PortA.4 ' One-wire Data-Pin "DQ" on PortA.4
Busy VAR BIT ' Busy Status-Bit
Raw VAR WORD ' RAW Temperature readings
TempC VAR WORD ' Temp in deg C
TempF VAR WORD ' Temp in deg F
Float VAR WORD ' Holds remainder for + temp C display
Cold_Bit VAR Raw.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Sign VAR BYTE ' +/- sign for temp display
Dummy VAR BYTE ' Dummy for Div32
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code
sensor var byte
hexbyte var byte
col var byte

DEFINE DEBUG_REGG PORTA 'set debug port to porta
DEFINE DEBUG_BIT 0 'use pin a0 of porta for debug
DEFINE DEBUG_BAUD 2400 'set baud rate to 2400
DEFINE DEBUG_MODE 0 'communicate in true mode

'-------------------------------------------------------------------------------
'these constants are available to program the sensor for 9,10,11,12 bit resolution
'DS18B20_9bit CON %00011111 ; 93.75ms, 0.5°C
'DS18B20_10bit CON %00111111 ; 187.5ms, 0.25°C <-- My favorite
'DS18B20_11bit CON %01011111 ; 375ms, 0.125°C
'DS18B20_12bit CON %01111111 ; 750ms, 0.0625°C (default)
' use the statement below in your program to set the resolution
'OWOUT comm_pin, 1, [$CC, $4E, 0, 0, DS18B20_9bit] 'set resolution of sensor
'================================================= ================
'============ Main Program loop ==================================
'================================================= ================
portC=0 'turn off LED's on breadboard
'-----------------------------------------------------------------
Begin:
PAUSE 500 ' Wait .5 [1/2] seconds
Main
for sensor=1 to 9 'I am reading 9 DS18b20 sensors... change this to match how many sensors you are reading
portC=sensor 'use the 4 breadboard led's to count binary as each sensor is read
for hexbyte=0 to 7 'each sensor address is 8 bytes
gosub getid 'go look up each sensors address
id[hexbyte]=col 'load the ID array with the retrieved address byte
next hexbyte 'go get the rest of the address bytes
gosub readsensor 'now go read the current sensor
gosub DisplayTemp 'now display the temp of the current sensor
next sensor 'now go read another sensor
portC=0 'done with all 9 sensors... turn off led's
debug $0D,$0A 'reset terminal cursor to home, upper left
end 'end here... use reset button to read them again.
'============= subroutines ========================
ReadSensor:
OWOUT DQ, 1, [$55,str id\8,$44] 'instructs sensors to match[$55] this[ID] rom code and
'initiates[$44] temperature conversion on matching sensor
CkAgn:
OWIN DQ, 4, [busy] ' Check for still busy converting
IF busy = 0 THEN ckagn ' Still busy?, then loop
owout dq,1,[$55,str id\8,$BE] 'instructs sensors to match[$55] this[ID] and start sending back scratchpad[$BE]
OWIN DQ, 2, [Raw.LOWBYTE,Raw.HIGHBYTE]' Read two temperature bytes, then end communications
return
'-------------------------------------------------------------
DisplayTemp: ' +32.0 to +257 F
IF Cold_Bit = 1 THEN Cold ' If Cold_Bit = 1, it's below "0" deg C
Sign = "+"
Dummy = 625 * Raw ' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
TempC = (Raw & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((Raw.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
debug dec sensor," TempC = ",Sign,DEC TempC,".",DEC Float," C ",$0D,$0A
' debug "Raw ", IBIN16 Raw," Dec=",dec (Raw>>3),$0D,$0A 'display the raw value
RETURN
''------------------------------------------------------------
Cold: ' arrive here if temp is below zero C
Sign = "-" ' Display - symbol for negative temp
Dummy = 625 * ~Raw+1' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
debug dec sensor," TempC = ",Sign,DEC TempC DIG 4,DEC TempC DIG 3_
,".",DEC3 TempC," C ",$0D,$0A
' debug "Raw", IBIN16 Raw," Dec ",(Raw>>3),$0D,$0A
RETURN
'================================================= ============
'below is a list of the addresses of each of the 9 sensors I am reading
'these must match the sensors you are trying to read...
'use "Read Rom" program to determine the addresses of each of these sensors
GetID:
Select Case sensor
Case 1 :LOOKUP hexbyte,[$28,$1E,$F5,$24,$03,$00,$00,$B8], col
Case 2 :LOOKUP hexbyte,[$28,$4E,$F4,$24,$03,$00,$00,$5B], col
Case 3 :LOOKUP hexbyte,[$28,$35,$FC,$24,$03,$00,$00,$05], col
Case 4 :LOOKUP hexbyte,[$28,$4D,$2C,$25,$03,$00,$00,$ED], col
Case 5 :LOOKUP hexbyte,[$28,$45,$F8,$24,$03,$00,$00,$82], col
Case 6 :LOOKUP hexbyte,[$28,$FC,$FC,$24,$03,$00,$00,$0C], col
Case 7: LOOKUP hexbyte,[$28,$BB,$02,$25,$03,$00,$00,$77], col
Case 8 :LOOKUP hexbyte,[$28,$32,$24,$25,$03,$00,$00,$6F], col
Case 9 :LOOKUP hexbyte,[$28,$4C,$A5,$24,$03,$00,$00,$6D], col
end select
return


Please note... the basis for the above programs came from Bruce Reynolds' website www.rentron.com (http://www.rentron.com).
http://www.rentron.com/PicBasic/PBP1-wire.htm
http://www.rentron.com/PicBasic/one-wire2.htm
http://www.rentron.com/PicBasic/one-wire3.htm

I simply took his working code and modified it to work with a debug window instead of an LCD and made it work with 9 temperature sensors. Bruce's code originally read two temp sensors and two 1-wire switches. As always take a look at the data sheet for what ever sensor or switch you are using and you can get a better idea of what is possible.

The third page link above actually has code that accuratly displays C and F as well as the raw 64 bit data.

It should be quite easy to modify this to work with most any PIC micro you might have available. Simply look through the code and you will se I used PortA.4 as the 1-wire connect pin.

I thought about combining these two programs into one and using one more PIC pin to tell the software to either run the first section of code to read an individual sensor or GOTO the second section to read multiple sensors. (have fun) Also if you don't have a PICkit you should be able to use any other programmer and an LCD, with some minor changes.

Again, Thanks to Bruce for providing the basis of this code.

Enjoy!!

P.S. I use MicroCodeStudio as my IDE but I would assume that you can just copy and pase this code into your own IDE. (Integrated Development Enviornment) I have also attached the two programs to this post. When I looked at the post I could see that some of the formatting is lost.

Don't forget to use a pull-up resistor on the 1-wire data line. Maxim recomends a 4.7K but I used a 10K.

For some reason I was unable to upload the native file using extension of .pbp, so I changed it to .txt. You should be able to open it up in a text editor and copy/paste into your IDE or possibly just change the extension back to .pbp

Archangel
- 29th May 2011, 08:57
OK Great, Thank You,
I already have Bruce's original code and now have yours, and appreciate both. I like your little program that checks the address of the ic's, I think that's what tripped me up before, I was trying to read them on several pins and it created conflicts, I see what you did, good thinking.
I believe Mackrackit is correct, this would make for a great article.

So in closing Thank You Heckler, and Thank You Bruce !

ScaleRobotics
- 29th May 2011, 14:50
Nicely done! Here is the link for the wiki. I put it under projects and temperature. http://www.picbasic.co.uk/forum/content.php?r=374

mackrackit
- 29th May 2011, 15:23
Some how the system put it under Home in the wiki,.

I moved it to
http://www.picbasic.co.uk/forum/content.php?r=374-How-to-read-a-one-wire-DS18B20-temperature-sensor-or-nine-of-them

EDIT..
Now the link Walter gave goes to the correct place???
weird...

ScaleRobotics
- 29th May 2011, 15:35
Er, I don't think it was the system ..... I think it was due to the exclusion of coffee this morning....

Thanks Dave

Heckler
- 29th May 2011, 16:43
Thanks guys... for creating the article.

Question. Is it (would it be) possible for me to continue to edit and improve the article now that it is posted?

Just thinking I might add a simple schematic, clarify a point or improve in other ways.

Second Question. I remember seeing a post about the fact that when you post code into a code window you loose the IDE colors for remarks, PBP commands, ect. ect.
Did that ever get resolved? Is there a way to keep the formatting colors... this would make code much easier to follow.


Thanks
dwight

ScaleRobotics
- 29th May 2011, 16:55
No problem Dwight,

I have added contributor to your profile. You should be able to edit your wiki project now. Let us know if there are any issues.

Also, if anyone else would like to add their project to the wiki or project area, just inform a moderator, and we will give you permissions.

Walter

mvs_sarma
- 15th June 2011, 09:22
they purchase resale stuff very cheap, and push them at nominal margin.

we , perhaps , need not doubt the quality of the item.

blume007
- 24th March 2014, 14:30
Hey guys and gals,

Although coming from the AVR world, I've found this thread and would like to contribute a little. I've been also a bit worried when buying a pack of 10 DS18B20s from China (aliexpress.com) but after checking most of them, I did have the luck all work just fine. There is a tiny offset among each, but considering the datasheet says about 0.5 deg.C precision, it seems to be quite all right.

Here is what I get from 6 in breadboard neighboring thermometers:
[0] P=1 24.1
[1] P=1 23.9
[2] P=1 24.1
[3] P=1 24.1
[4] P=1 24.1
[5] P=1 24.3
------------------
[] is channel/pin index, P stands for presence indicator and finally, there is the temperature.

Considering the absolute value of 24 deg.C I am not really sure whether we have such T in the office.. and don't have a any other calibrated thermometer and thus I have nothing to compare to. However, comparing to AD's TMP36 T->U converter these are way easier to use. Additionally, I got 10 of them for the price of 2 here in CZ :)

mvs_sarma
- 25th March 2014, 05:36
encouraging to be back with our site after a long gap

Good that you got 10 and are happy.
i checked ebay to day. some sellers offer 10 at little less than 10$.
However, no point in searching for same , as you bought already. all the best