Ich habe mir in der Bucht vollgenden DS18B20 bestellt: Link.
Möchte diesen nun an einem Arduino Uno R3 betreiben. Schwarz = GND, Rot = 5V, Weiß = 4,7k -> Pin 12.
Libary
Bekomme aber kein Ergebniss. Getestet habe ich das Sketch mit der Serial Ausgabe.
Bekomme dort aber nur "No more Adress".
#include <OneWire.h>
/*****************************************************************************
* Sketch: DS18B20_SEA.pde
* Author: A. Kriwanek
* Version: 1.0 01.04.2011/19:50
* based on OneWire Library 2.0 from http://www.pjrc.com/teensy/td_libs_OneWire.html
* and the provided example sketch.
* (Authors: Jim Studt, Tom Pollard, "RJL20", Robin James, Paul Stoffregen)
*
* Digital Pin 12 for 1Wire bus
* Pull Up Resistor 4k7 between Digital Pin 12 and +5V
* Temperature sensor(s) Dallas 18B20 for testing
*
* This sketch searches for Dallas 1Wire temperature sensors. If a sensor is found,
* the hardware id, the data from the sensors scratchpad and the actual temperature
* is transmitted via the serial interface.
*
*
* This sketch is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*****************************************************************************/
OneWire ds(12); // Make instance named ds on Arduino digital pin 12
void setup(void) {
Serial.begin(9600); // Start serial interface with 9600 Baud
}
void loop(void) {
byte i;
byte present = 0;
byte data[12];
byte addr[8];
float Temp;
if ( !ds.search(addr)) {
// No more Dallas chips present:
Serial.print("No more addresses.\n");
ds.reset_search();
delay(250);
return;
}
// Output 64 Bit hardware id of Dallas Chip:
Serial.print("R=");
for( i = 0; i < 8; i++) {
Serial.print(addr[i], HEX);
Serial.print(" ");
}
// Check for invalid CRC in address:
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}
if ( addr[0] != 0x28) {
// Check for family code which is not DS18B20:
Serial.print("Device is not a DS18B20 family device.\n");
return;
}
// The DallasTemperature library can do all this work for you!
ds.reset();
ds.select(addr);
ds.write(0x44,0); // start conversion, with parasite power off
delay(1000); // maybe 750ms is enough, maybe not
// Check whether chip is present:
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print("P="); // Present = 1
Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes of data
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print( OneWire::crc8( data, 8), HEX);
// Calculate temperature. data[1] High Byte, data[0] Low Byte.
Temp = ((data[1] << 8) + data[0] ) * 0.0625; // 12Bit = 0,0625 C per Bit
Serial.print( " T=");
Serial.print( Temp, 2);
Serial.print( " C");
Serial.println();
}