ds18b20 temperature sensor and arduino
-
23-12-2019 - |
Question
I am currently writing this simple code to check the temp sensor
#include <One Wire . h>
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2
void setup(void) {
Serial.begin(9600);
}
void loop(void)
{
float temperature = getTemp();
Serial.println(temperature);
delay(100); //just here to slow down the output so it is easier to read
}
I m getting "sketch_feb27a:14: error: 'getTemp' was not declared in this scope"
can someone tell me why?
Solution
Here your trying call getTemp(); . But below function is not defined under sketch itself..if you add the activity related to getTemp(); it must work.
float temperature = getTemp();
OTHER TIPS
Either you have not extracted the OneWire library to the correct location, or have made a mistake in the #include line. Include it without spaces
*include<OneWire.h>
If getTemp() is not a part of the library OneWire then obviously you have to make your own getTemp() function
You can use DallasTemperature library.
Use it like this:
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
OneWire dsOneWire(DS_ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dsSensorControler(&dsOneWire);
dsSensorControler.begin();
dsSensorControler.requestTemperatures();
float temp = dsSensorControler.getTempCByIndex(0);
Code from DallasTemperature library sample.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow