DS18B20 wire length

Hi,
Just a question what will be the max wire length for a temp. sensor DS18B20.
Is the precision important for the cable length?
I mean low resolution longer cable .

Thanks for any help,

ilioSS

20 meter should not be a problem, but you need to use a lower resistor, not 4K7 but e.g. 2K2.

I don't know the max length possible , this good page claims 100mtr

Rob,

Thanks, this will do for outdoor measurements.
As rule of thumb this also for BMP and SHT digital sensors?

Rob can you have a look on my post in storage?
I still look for a logging file system which give every dau a CSV file with a header line.
The daily file is no problem. Only the header is a problem.

What I do is open and close the datafile on date string from clock but only the first file contains the header.

        char filename[12];//char filebname[]="                ";
        sprintf(filename,"%02d-%02d-%02d.csv",dd,mm,yy);
        Serial.println(filename);
          dataFile=SD.open(filename,FILE_WRITE);
          if ( q==0)
        {
          delay(20);
        dataFile.println("DATE        ,TIME        ,Temp        ,Humid       ,Dauwp       ,temp,luchtdr. ");
        delay(50);
          Serial.println("DATE        ,TIME        ,Temp        ,Humid       ,Dauwp       ,temp,luchtdr. ");    
        delay(10);  
                           if (dataFile)       {// 00/00/00,00:00:00,23.52,53.67,11.31,12.56, Temp    ,
                                          q=1;
                                           dataFile.close();
                                           
                                               }  
 else        
                 {
                    Serial.println("error opening datalog.csv"); // if the file isn't open, pop up an error:
                    
                 } 
             }

 else     
                                        {
   
                                        dataFile.print(ReadTimeDate());
                                        dataFile.print(",");
                                        dataFile.print(tC,2);
                                        dataFile.print(",");
                                        dataFile.print(rhTrue,2);
                                        dataFile.print(",");
                                        dataFile.print(Dauwpunt,2);
                                        dataFile.print(",");
                                        dataFile.print(b.t,1);
                                        dataFile.print(" ,");
                                        dataFile.println(b.ppa);
                                        dataFile.close();   
                                        }  
       
	
        if(uur==23){
                    if(minu==59){
                                 if(sec==58){
                                             z=1;
                                            }
                                }
                   }

Also the windows is Always making file on 2000- year and date not the date the file is made?

Kind regards,
IlioSS

there is a logic flaw in your code,
if q==0 and you fail to open the datafile , you still try writing to the datafile (header)
furthermore, if you use the IDE, please press CTRL-T to auto format your code (readability).

I think 1 wire is less error prone than I2C, but it expect it will not differ much (both are digital signals.
I2C can be downgraded to a lower speed e.g. 100KHz or even 50 KHz.

use shielded cable e..g. CAT 5 to minimize noise.

Hi Rob,

First of all best whishes for the new year.

Thanks for the relpy.
The test for q==0 is for the first line in the file for the header. After this first test q=1
This means the header is only once written in the file.
This all works.
The problem is in the second consecutive file. Up-until now I can't realize the header.
However the file is closed midnight and a new file is made. So I have every day a file which is according my whish.
Is it possible that this can be solved in the SD and/or clock library?
To be honest I do not understand how the file will be closed at midnight and a new file is opened.
The windows time stamp must be done in windows . This I will look after but has no priority.

BTW you mention to use the ctrl-t feature. What is this doing exactely?
I find my way in C++ with the help of C++ for dummy,s.

KInd regards,

ilioSS

I would open and close the file after every write action (open for append)

in pseudo code

filename = ... //date
if  exists filename  F = open for append()
else 
{
   F = create new file open for write
   write header
}

F.write log;
F.close

Every time a file gets a non existing name a header will be written.
This even works when another part of the code would eliminate the file from disk.
The file itself is the flag to see if a header needs to be written.

Hi Rob,

So trying to have my file equipend every day with a header is not so easy.
Thanks for your reply. I looked in to it bud no succes.
Now I have a solution witch looks to work.
I check if the day iffer from yesterday and meke e new file with header. (dd!=ddold)
If day is same as (dd=ddold) make the file again open en write.

[/

  if(dd!=ddold)  //  datum veranderd dus nieuwe file met header
  {

    delay(50); 
    char filename[12];
    sprintf(filename,"%02d-%02d-%02d.csv",dd,mm,yy);
    dataFile=SD.open(filename,FILE_WRITE);
    ddold=dd;  
    dataFile.println("DATE        ,TIME        ,Temp        ,Humid       ,Dauwp       ,temp,luchtdr. ");
    delay(10);
    dataFile.close();

  }

  else{
    char filename[12];
    sprintf(filename,"%02d-%02d-%02d.csv",dd,mm,yy);
    dataFile=SD.open(filename,FILE_WRITE);

    dataFile.print(ReadTimeDate());
    dataFile.print(",");
    dataFile.print(tC,2);
    dataFile.print(",");
    dataFile.print(rhTrue,2);
    dataFile.print(",");
    dataFile.print(Dauwpunt,2);
    dataFile.print(",");
    dataFile.print(b.t,1);
    dataFile.print(" ,");
    dataFile.println(b.ppa);
    dataFile.close();   
  }


}   

code]

I wait till the day changes at midnight.
Tomorrow a new file with header I hope.
By for now.

Greets,
ilioSS

that should work!

Hi Rob,
It works.
Finnaly after many months I have it working.

Thanks for giving your ideers as well.

ilioSS

You're welcome.

It is good to try things yourself first, but it is also good to ask if you don't know.
There will be new questions enough in new projects to come :wink:

But... you never check if the file open function failed.