I can't run the code for DS18S20

Hi,

I have a Arduino Mega 2560 and a DS18D20

I can’t run this code, it gives me compilation error and it says
“OneWire does not name a type” and it points to this

OneWire ds(2);  // on pin 2

The code is from this link.

http://www.elecrow.com/sensor-c-111/temperature-humidity-c-111_112/one-wire-waterproof-temperature-sensor-p-314.html

Please if there is someone who could help me, Thanks.

DS18B20 for Arduino 1.0.zip (8.41 KB)

I don't know what kind of code that is (and I don't care).

Use Arduino 1.0.5. Use the newest OneWire library, http://playground.arduino.cc/Learning/OneWire Do you know how to install a library ? Arduino 1.0.5 is able to import a zip file, use "Add library ..." in the menu.

For the DS18S20 you could use the example the comes with the OneWire library or you could use the Dallas library.

If it is properly connected, and you have a pull-up resistor, it should work.

ok it's working, Thanks

I have a question, Why is the pull-up resistor needed?

Pull-up resistor like this, http://bildr.org/2011/07/ds18b20-arduino/

The output of the DS18B20 is not a normal digital output. It only pulls the output to ground or does nothing. It is a open collector output.

You need a pull-up resistor to make the signal go to 5V. The advantage is that many OneWire devices can share the same signal line.

This wiki may help you.
http://www.elecrow.com/wiki/index.php?title=One_Wire_Waterproof_Temperature_Sensor#Usage

DS18B20_hard_Elecrow.jpg