Waterdicht Temperatuur sensor DS18B20 Digitale temperatuur sensor

beste,

ik ben bezig met een temperatuursensor op mijn arduino uno, maar ik vind dus geen van codes voor deze sensor.
Zouw er iemand mij kunnen helpen met deze codes?

ik vind wel codes voor arduino IDE, waar als ik die intyp heb ik fout meldingen :confused:

toch alvast bedankt

Er lijkt mij toch heel wat over deze sensor te staan op internet.
Welke "codes" heb je geprobeerd en welke "foutmeldingen" krijg je?

beste Jantje,

ik heb deze codes; gebruikt:

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

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS); deze is verkeert hieronder staat de foutmelding
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

void setup(void)
{
Serial.begin(9600); //Begin serial communication
Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
sensors.begin();
}

void loop(void)
{
// Send the command to get temperatures
sensors.requestTemperatures();
Serial.print("Temperature is: ");
Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Update value every 1 sec.
delay(1000);
}

fout melding:
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
sketch_may29a:7: error: 'OneWire' does not name a type
sketch_may29a:9: error: 'DallasTemperature' does not name a type
sketch_may29a.ino: In function 'void setup()':
sketch_may29a:15: error: 'sensors' was not declared in this scope
sketch_may29a.ino: In function 'void loop()':
sketch_may29a:21: error: 'sensors' was not declared in this scope

als u mij kan helpen het zou mij ter zeerste danken

alvast bedankt.

beste, Jantje

sorry voor het gele kleur en het is de verkeerde code dit is de code die ik gebruikte:

#include <OneWire.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
  
}


float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad

  
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
  
  ds.reset_search();
  
  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  
  return TemperatureSum;
  
}

alvast bedankt.

EDIT:code tags toegevoegd

code tags gebruiken is wel noodzakelijk.
En welke foutboodschap krijg je?

Deze code compileert bij mij.

Hij mist de library OneWire. Als het goed is staat bij op die pagina waar je de sketch vandaan hebt ook waar de onewire library staat. Die heb je namelijk nodig. Of google eens op "DS18B20 library arduino" dan vind je die vrijwel zeker. Die library moet je installeren in de libraries folder waar ook jouw sketches staan. Meestal is dat iets van "D:\Documents\Arduino\libraries". Zet deze library NIET in de Arduino IDE installatie folder. Zodra je een upgrade uitvoert, ben je die gelijk weer kwijt.

beste nicoverduin,

Bedankt voor het te laten weten daar zat mijn fout. je hebt me echt geholpen dank u wel!! :smiley:
:smiley: :smiley:

mvg

Graag gedaan.