DS18b20Sensor - DallasTemperature.h: No such file or directory

Hey hey,

I'm trying to use a Ds18b20 waterproof temperature sensor for my project, but am finding it hard to find simple instructions for how to write the code.

At the moment i'm using OneWire.h, and DallasTemperature.h libraries with the final goal of having my temperature in C displayed on an LCD screen. I later plan to connect a heating element that will turn on/off if the temperature is too low/high.

I keep getting an error message when i try to verify my code that says 'fatal error: DallasTemperature.h: No such file or directory'.

I have no idea why this keeps happening, as I have opened an example sketch that uses this same library, and i don't get the same error message when verifying - so i definitely DO have such a file, and it must be in the right place!

Any ideas?

Also, right now i just want to figure out how to connect only one sensor, instead of an array, but all the instructions i can find are for how to hook up several at once which looks a bit complicated. There must be an easier way for just one sensor? I have been looking for ages and cant figure it out!

Thanks for any help or suggestions, i know the answer must be simple but i'm pretty new to this and i must be missing something obvious!

I would copy over my code, but it's totally wrong and i think it would be best if i just start again after i know a bit more about everything!

Arduino Forums Implied Rule #1: ...p...o...s...t... ...y...o...u...r... ...c...o...d...e... (and put them in code tags)

also post the example code, so we can compare...

DallasTemperature.h: No such file or directory'

i definitely DO have such a file, and it must be in the right place!

You may well have the file but it might not be in the right place for the way that it is being #included.

Carefully compare how you are #including it in the example that works and in you program that doesn't and how you are creating the instances of the objects in both programs.

Above all, post your code here (use code tags - </> above the editor window) and the full error message.

Did you miss the bit about the code tags ?

code tags?

I know my code is a mess, but like i said i've tried looking it up a million times and it all seems overly complicated for something that i thought was relatively simple. There are bound to be loads of mistakes, but for the minute i just really want to know how to get my sensor reading to show up on the lcd. that's all! I think once that's done i can sort of figure out the other problems on my own, with trial and error...

ok ok i see code tags -

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

#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress sensor1 = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };  // when ready input correct address using this using tutorial :http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#define goalPin A5    


int goalTemp = 0;           //desired temp to be displayed on LCD
int goalVal = 0;            //initial analog reading of pin A5

#include <LiquidCrystal.h>
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);  // initialize the library with the numbers of the interface pins
char textLine1[]="ActualT-";  //the string to print on the LCD
char textLine2[]="DesiredT-";  //the string to print on the LCD

long dsInterval = 1000;   // **one second between updating sensor reading display - easier to view
long previousMillis = 0;
long goalInterval = 3;         //3ms between A5 readings gathered
long previousGoalMillis = 0;

const int relayPin = 3; //the "s" of relay module attach to, output to relay

void setup()

{
  

pinMode(A5, INPUT);

pinMode(relayPin, OUTPUT); //initialize relay as an output
  
Serial.begin(9600);  // initialize serial communication at 9600 bits per second
lcd.begin(16, 2);  // set up the LCD's number of columns and rows

sensors.begin();
sensors.setResolution(sensor1, 10);



}


}

void loop() 

{
  
  float tempC = sensors.getTempC(deviceAddress);

sensors.requestTemperatures();
Serial.println(tempC);



unsigned long currentMillis = millis();

 if(currentMillis - previousMillis > dsInterval) {   //if enough time has passed
 previousMillis = currentMillis;

  lcd.setCursor(10,0);

  lcd.print(sensorTemp);        //print temp sensor reading on LCD
  
 }
  
  goalVal = analogRead(goalPin);  // read the input on A5; sets required temp
 
  goalTemp = (goalVal * 0.048828125);         // conversion of data to C - 50/1024 = 0.048828125 - max temperature is 50C
 
 unsigned long currentGoalMillis = millis();

 if(currentGoalMillis - previousGoalMillis > goalInterval) {   //if enough time has passed
 previousGoalMillis = currentGoalMillis;
  
  lcd.setCursor(11,1);           

  lcd.print(goalTemp);        //update LCD with new reading for required temp

 }

  

lcd.setCursor(0,0);             // set the cursor to column 0, line 0 - Top line LHC

      lcd.print(textLine1);         // Print message 1 on the LCD
 
      lcd.setCursor(15,0);
   
      lcd.print("C");

      lcd.setCursor(0,1);
     
      lcd.print(textLine2);         // Print message 2
     
      lcd.setCursor(13,1);
   
      lcd.print(".0C");


 if (sensorTemp > goalTemp){ 
      digitalWrite(relayPin,LOW);    //heater off when temp high
    } else {
      digitalWrite(relayPin,HIGH);   //keep heater on
    }


}

and this is the example

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

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
  sensors.setResolution(dogHouseThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop(void)
{ 
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("Inside temperature is: ");
  printTemperature(insideThermometer);
  Serial.print("\n\r");
  Serial.print("Outside temperature is: ");
  printTemperature(outsideThermometer);
  Serial.print("\n\r");
  Serial.print("Dog House temperature is: ");
  printTemperature(dogHouseThermometer);
  Serial.print("\n\r\n\r");
}

the error message is

fatal error: DallasTemperature.h: No such file or directory
compilation terminated.
Error compiling.

It is not likely to be the cause of your problem but your program will not compile for other reasons. Look at the number of braces at the end of the setup() function, for example.

Ok, i've deleted one of the brackets! that was simple enough to put right, but the same error message is still coming up.. What is wrong with the Dallas Temperature thing? It was giving me the same error message earlier for OneWire.h as well... Eventually it stopped, after i fiddled around with loads of bits and pieces... probably why the code it so awful now... but i have no idea why! Where can I find the right information about this kind of thing? I've been watching tutorials and reading about code, but for these specific libraries i'm totally confused! I'm only using this temperature probe because my LM35 wasn't waterproof, but it seems really difficult to just make the ds18b20 do the same thing!

Eventually it stopped, after i fiddled around with loads of bits and pieces...

Have you tried the example since then ?

The example is working fine, still the same error message coming up for my version..

fatal error: DallasTemperature.h: No such file or directory
compilation terminated.
Error compiling.

Let's start with the basics.
Where exactly is the DallasTemperature library installed, what is it's folder name and what files are in the folder ?

Thank you so much! let's definitely start with the basics...

Dallas Temperature is saved in C:\Users\myname\Documents\Arduino\libraries\DallasTemperature

the files inside are three text documents called 'change' 'readme' and 'keywords' there is a cpp and a h file both called DallasTemperature.. There is also a folder full of examples like the one above...

Is that the same place where other libraries that you use, are ?

What folder is your program in ?

Dallas Temperature is saved in C:\Users\myname\Documents\Arduino\libraries\DallasTemperature

the files inside are three text documents called 'change' 'readme' and 'keywords' there is a cpp and a h file both called DallasTemperature.. There is also a folder full of examples like the one above...

Looking good so far. When you go to that libraries location can you right click on properties for the .h and .cpp files and see size? Can you right click and open them with a text editor (Wordpad or Notepad in Windows) and see that they look like code?

What about OneWire?

What version of the ide are you using? What computer OS?

problem solved, after trying it for myself, I figured out that OneWire is a separate library also created by dallas semiconductors, you need to install that library as well, also you have a lot of errors

Anyway, I have cleaned up your code (still has errors)

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

#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress sensor1 = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };  // when ready input correct address using this using tutorial :http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#define goalPin A5    


int goalTemp = 0;           //desired temp to be displayed on LCD
int goalVal = 0;            //initial analog reading of pin A5

#include <LiquidCrystal.h>
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);  // initialize the library with the numbers of the interface pins
char textLine1[]="ActualT-";  //the string to print on the LCD
char textLine2[]="DesiredT-";  //the string to print on the LCD

long dsInterval = 1000;   // **one second between updating sensor reading display - easier to view
long previousMillis = 0;
long goalInterval = 3;         //3ms between A5 readings gathered
long previousGoalMillis = 0;

const int relayPin = 3; //the "s" of relay module attach to, output to relay

void setup()
{
  pinMode(A5, INPUT);
  pinMode(relayPin, OUTPUT); //initialize relay as an output
  
  Serial.begin(9600);  // initialize serial communication at 9600 bits per second
  lcd.begin(16, 2);  // set up the LCD's number of columns and rows
  sensors.begin();
  
  sensors.setResolution(sensor1, 10);
}

void loop() 
{
  float tempC = sensors.getTempC(deviceAddress);

  sensors.requestTemperatures();
  Serial.println(tempC);

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > dsInterval)   //if enough time has passed
  {
    previousMillis = currentMillis;
    lcd.setCursor(10,0);
    lcd.print(sensorTemp);        //print temp sensor reading on LCD
  }
  
  goalVal = analogRead(goalPin);  // read the input on A5; sets required temp
  goalTemp = (goalVal * 0.048828125);         // conversion of data to C - 50/1024 = 0.048828125 - max temperature is 50C
 
  unsigned long currentGoalMillis = millis();

  if(currentGoalMillis - previousGoalMillis > goalInterval)   //if enough time has passed
  {
    previousGoalMillis = currentGoalMillis;
    lcd.setCursor(11,1);           
    lcd.print(goalTemp);        //update LCD with new reading for required temp
  }

  lcd.setCursor(0,0);             // set the cursor to column 0, line 0 - Top line LHC
  lcd.print(textLine1);         // Print message 1 on the LCD
  lcd.setCursor(15,0);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print(textLine2);         // Print message 2
  lcd.setCursor(13,1);
  lcd.print(".0C");

  if (sensorTemp > goalTemp)
    digitalWrite(relayPin,LOW);    //heater off when temp high
  else
    digitalWrite(relayPin,HIGH);   //keep heater on
}

Missing library - Arduino Playground - OneWire

omg it's amazing! i had my other libraries saved C:\Program Files (x86)\Arduino\libraries and not where OneWire and DallasTemperature were automatically downloading to... I know it's a stupid mistake but it looked right and i could honestly have spent decades trying to figure that out on my own!

Thank you so much for helping!! And for cleaning up my code!! I realized i had a few undeclared functions and i've sorted that out - i had just been changing names and copying and pasting stuff all day and everything got into a dreadful mess...

God i'm so happy that's over! Thank you all so much, one day i hope i can help out someone else who is totally confused about something to return the favour to the universe!

i had my other libraries saved C:\Program Files (x86)\Arduino\libraries and not where OneWire and DallasTemperature were automatically downloading to..

So, have you got your user contributed libraries, ie not the ones that do not come with the IDE, all in the same (correct) libraries folder now and if so, where exactly ?

i just cut and pasted the ones i'd downloaded into the same folder as the ones that come with the software... It has stopped the error message coming up, and now that i've sorted a few other things out, ide is letting me verify.. i just have to wire everything up now and see if it works in real life...

i just cut and pasted the ones i'd downloaded into the same folder as the ones that come with the software...

As you have found, that will work but they are not in the official location for user contributed libraries, which is the libraries folder of the folder where your programs are stored, the so called "sketches" folder.

What you have done works so why should you worry ? Well, if you update the IDE your programs using the user contributed libraries will no longer compile. If you put them in the right place now and continue to use the same "sketches" folder to hold your programs when you update the IDE then the compiler will find and use them even though the IDE has been updated.

i just cut and pasted the ones i'd downloaded into the same folder as the ones that come with the software...

This is not correct. There should be two different locations. One for the libraries packaged with the ide, and another for the user added libraries. The two locations helps keep the user added libraries intact when the ide is upgraded to a new version.The ide should be able to link them from both locations.

Your first posting in regards to the library location was correct. If they are not being linked to your skethes from that location that is a problem to be corrected.

The user added libraries should be in the same location as your saved programs. Where are they located?