DS18B20 Device Discovery ######################## :title: DS18B20 Device Discovery :date: 2014-08-19 10:57 :category: Projects :tags: arduino, electronics :slug: ds18b20-device-discovery :related_posts: soil-temperature-monitoring-part-two,soil-temperature-monitoring-part-one :author: Chris Ramsay :status: published :language: en :show_source: True .. contents:: .. PELICAN_BEGIN_SUMMARY A little bit of work stemming from from the soil temperature monitoring project; this is an aside on DS18B20 temperature sensing device address discovery with the Arduino. Being that I am going to have a handful of sensors in the ground and therefore not easily accessible for identification I need to find a way of easily finding out all the device addresses in one fell swoop. .. PELICAN_END_SUMMARY Arduino - Device Address Discovery ---------------------------------- As already discussed in `Soil Temperature Monitoring - Part One`_ connecting the DS18B20 to an Arduino is trivial; ground, positive and data are all that is required, with data to the Arduino digital pin 3. Pull up is achieved with a 4K7. .. image:: https://farm8.staticflickr.com/7616/16819964307_e39b7bddd4_c.jpg :width: 800 :height: 563 :scale: 100 :alt: DS18B20 Basic Circuit *Simple circuit employed for address discovery* Below is a sample of the code I used to discover the sensor addresses. .. code-block:: c :linenos: table #include #define ONE_WIRE_BUS 3 OneWire oneWire(ONE_WIRE_BUS); void setup() { Serial.begin(9600); discover(); } void loop() {} void discover(void) { byte i; byte data[12]; byte addr[8]; Serial.print("Starting...\n\r"); while(oneWire.search(addr)) { Serial.print("\n\r\n\rDevice has address:\n\r"); for( i = 0; i < 8; i++) { Serial.print("0x"); if (addr[i] < 16) { Serial.print('0'); } Serial.print(addr[i], HEX); if (i < 7) { Serial.print(", "); } } if ( OneWire::crc8( addr, 7) != addr[7]) { Serial.print("CRC is not valid!\n\r"); return; } } Serial.println(); Serial.print("Done"); oneWire.reset_search(); return; } This is what it looked like with five sensors attached: .. code-block:: bash Starting... Device has address: 0x28, 0xC8, 0xCC, 0xBF, 0x04, 0x00, 0x00, 0xB6 Device has address: 0x28, 0xBA, 0x17, 0xD0, 0x04, 0x00, 0x00, 0x64 Device has address: 0x28, 0xF5, 0xE4, 0x83, 0x05, 0x00, 0x00, 0x26 Device has address: 0x28, 0xE3, 0x67, 0xCE, 0x04, 0x00, 0x00, 0x9C Device has address: 0x28, 0xE7, 0x17, 0x11, 0x05, 0x00, 0x00, 0x1D Done Now it will just be a process of elimination to find out which sensor matches which address. .. _cloud detection: {filename}/projects/2014-03-04_cloud-detection-part-one.rst .. _Soil Temperature Monitoring - Part One: {filename}/projects/2014-04-10_soil-temperature-monitoring-part-one.rst