Connect the digital temperature sensor DALLAS DS18B20 to arduino


Connect the digital temperature sensor DALLAS DS18B20 to arduino

resistor on 220 Оm

#include 
// DS18B20 pin 2.
OneWire ds(2);
 
void setup() {
  // Start reading port.
  Serial.begin(9600); 
}
 
void loop() {
  byte data[2];
  ds.reset(); 
  ds.write(0xCC);
  ds.write(0x44);
  delay(750);
  ds.reset();
  ds.write(0xCC);
  ds.write(0xBE);
  data[0] = ds.read(); 
  data[1] = ds.read();
  int Temp = (data[1]<<8)+data[0];
  Temp = Temp>>4;
 
  // Output temperature values to the console.
  Serial.print(" T = ");
  Serial.print(Temp);
  Serial.println("'C"); 
}


#arduino
Просмотров: 324

comments powered by HyperComments



Поиск по сайту