{"id":13894206,"url":"https://github.com/RobTillaart/DS18B20_RT","last_synced_at":"2025-07-17T09:31:11.134Z","repository":{"id":41446229,"uuid":"254717677","full_name":"RobTillaart/DS18B20_RT","owner":"RobTillaart","description":"Arduino library for the DS18B20 sensor - restricted to one sensor per pin.","archived":false,"fork":false,"pushed_at":"2024-10-08T14:59:48.000Z","size":54,"stargazers_count":24,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-19T06:33:14.536Z","etag":null,"topics":["arduino-library","sensor","temperature"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-04-10T19:22:50.000Z","updated_at":"2024-10-08T14:59:36.000Z","dependencies_parsed_at":"2024-04-26T12:31:37.431Z","dependency_job_id":"dd5afaec-1f23-41a1-8dcc-0f03f0c06441","html_url":"https://github.com/RobTillaart/DS18B20_RT","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FDS18B20_RT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FDS18B20_RT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FDS18B20_RT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FDS18B20_RT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/DS18B20_RT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226248197,"owners_count":17595158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino-library","sensor","temperature"],"created_at":"2024-08-06T18:01:26.460Z","updated_at":"2024-11-24T23:30:17.125Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":["C++"],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/DS18B20_RT/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/DS18B20_RT/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DS18B20_RT/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/DS18B20_RT/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DS18B20_RT/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/DS18B20_RT.svg)](https://github.com/RobTillaart/DS18B20_RT/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DS18B20_RT/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/DS18B20_RT.svg?maxAge=3600)](https://github.com/RobTillaart/DS18B20_RT/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/DS18B20.svg)](https://registry.platformio.org/libraries/robtillaart/DS18B20)\n\n\n# DS18B20\n\nArduino library for the DS18B20 sensor - restricted to one sensor per pin.\n\n\n## Arduino Temperature Control Library (ATCL)\n\nThis DS18B20 library is not a full featured library for the DS18B20 family.\nThis library supports only one DS18B20 per Arduino/ MCU pin.\n\nIf you need more functions or control over the DS18B20 family I refer to the library\nof Miles Burton - https://github.com/milesburton/Arduino-Temperature-Control-Library\n\nI'm a great fan of the above library however some time ago I needed to strip it down \nto save a few dozen bytes. I reworked that minimalistic version into a library and I \nadded a number of Arduino examples to help you get started.\n\nEffort has been taken to keep the code, variables and function names compatible with \nATCL library mentioned above. This way you can step over to that one with relatively\nfew problems when you need more functionality like multiple sensors on one pin.\n\nFinally this library will probably make it easier to use a DS18B20 with processing \nboards or IC's with small memory footprint.\n\n\n### Footprint OneWire\n\nThis library depends (is build) upon the **OneWire** library of Paul Stoffregen.\n- https://github.com/PaulStoffregen/OneWire - the reference imho.\n\nIn issue [#31](https://github.com/RobTillaart/DS18B20_RT/issues/31) the footprint of \nthe OneWireNG seems to be smaller when build on platformIO.\n\nSo if you are in need to save some more bytes, you might try [OneWireNG]\n(https://github.com/pstolarz/OneWireNg).\n\n\n### Related\n\nThis library is related to\n- https://github.com/RobTillaart/DS18B20_INT\n- https://github.com/RobTillaart/DS18B20_RT\n- https://github.com/milesburton/Arduino-Temperature-Control-Library\n- https://github.com/milesburton/Arduino-Temperature-Control-Library/issues/244#event-9253126638\n\nDependency\n- https://github.com/PaulStoffregen/OneWire\n- https://github.com/pstolarz/OneWireNg (alternative)\n\n\n## Interface\n\n```cpp\n#include \"DS18B20.h\"\n```\n\n### Constructor\n\nThe DS18B20 library supports only the DS18B20, only one sensor per pin, no parasite \nmode, no Fahrenheit and no alarm functions. The only feature the class supports is \nthe asynchronous reading of the temperature by means of three core functions:\n\n- **DS18B20(OneWire \\* ow, uint8_t resolution = 9)** constructor needs a reference to OneWire object.\nAlso sets the resolution, default to 9 bits.\n- **bool begin(uint8_t retries = 3)** resets oneWire and set resolution default to 9 bit.  \nReturns true if all is OK.\nThere will be a number of retries to connect, default 3.\n- **bool isConnected(uint8_t retries = 3)** resets oneWire checks if a device can be found.  \nReturns true if a device is found.\nThere will be a number of retries to connect, default 3.\n- **bool getAddress(uint8_t \\* buf)** returns true if the sensor is configured (available).\nBuf must be a byte array of at least 8 bytes.\n\n\n### Request Temperature\n\n- **void requestTemperatures()** trigger temperature conversion.\n- **bool isConversionComplete()** check if conversion is complete.\n- **float getTempC(bool checkConnect = true)** returns temperature in Celsius.\n  - -127 = DEVICE_DISCONNECTED (only when checkConnect == true)\n  - -128 = DEVICE_CRC_ERROR\n  - can be faster by setting checkConnect to false. (experimental)\n- **float getTempF()** simple wrapper, returns temperature in Fahrenheit.\n\n\nThis \"async only\" allows the class to be both minimal in size and non-blocking. \nIn fact the class has no support for a synchronous read in one call. \nThis choice will teach people how to work in a non-blocking way from the start.\n\n\n### Offset\n\n- **void setOffset(float offset = 0)** set a (small) offset to calibrate the sensor.\n- **float getOffset()** return the current offset, default 0.\n\nOne additional application of the offset is to **setOffset(273.15)** which \nconverts the default Celsius temperature into **Kelvin**.\n\n\n### Resolution\n\n- **bool setResolution(uint8_t resolution = 9)** resolution = 9..12 (9 is default).\nReturns false if no device is found.\n- **uint8_t getResolution()** return resolution set.\n\n\n### Configuration\n\n- **void setConfig(uint8_t config)** set DS18B20_CLEAR or DS18B20_CRC. \nIf DS18B20_CRC flag is set the library will check the CRC, otherwise it won't.\nNot checking the CRC is a few milliseconds faster.\n- **uint8_t getConfig()** get current configuration \n  - 1 == DS18B20_CRC\n  - 0 == no flag set.\n\n\n## Operation\n\nThis library supports only **one** DS18B20 per Arduino/ MCU pin.\n\n```\n    //  BOTTOM VIEW\n    //\n    //          PIN  MEANING\n    //   /---+\n    //  /  o |  1    GND\n    //  |  o |  2    DATA\n    //  \\  o |  3    VCC\n    //   \\---+\n```\n(always check datasheet)\n\nConnect a pull-up resistor 4.7 KOhm between pin3 and pin2. \nWhen the wires are longer this resistor needs to be smaller.\n\n\n### -127 and 85\n\nTwo specific return values from reading the sensor:\n\n- minus 127 == DEVICE_DISCONNECTED\n- plus 85 is the power on default. \nIf you get this unexpected it may indicate a power problem\n\n\n### Disconnect\n\nDuring tests with **DS18B20_test_disconnect.ino** I noticed:\n- set resolution to 9 bits + disconnected data line ==\u003e sensor blocks and keeps 9 bits resolution.\n- set resolution to 9 bits + disconnected VCC line ==\u003e sensor stops and restarts at 12 bits resolution.\n- set resolution to 9 bits + disconnected GND line ==\u003e sensor keeps running at 9 bits resolution.\n\n\n### Pull up resistor\n\nAn **indicative** table for pull up resistors, (E12 series), to get started.\n\nNote: thicker wires require smaller resistors (typically 1 step in E12 series) \n\n\n|  Length         |   5.0 Volt  |  3.3 Volt  |  Notes  |\n|----------------:|------------:|-----------:|:--------|\n|  10cm (4\")      |    10K0     |    6K8     |  might work without  |\n|  20cm (8\")      |     8K2     |    4K7     |\n|  50cm (20\")     |     4K7     |    3K3     | \n|  100cm (3'4\")   |     3K3     |    2K2     | \n|  200cm (6'8\")   |     2K2     |    1K0     | \n|  500cm (16'8\")  |     1K0     |    \\*      |  \n|  longer         |     \\*      |    \\*      |\n\n\\* = no info, smaller?\n\n\n### Diagnosis notes\n\nIt was noted that the library sometimes give unexpected values, and keep \nsending these values.\n\nThis is due to the fact that by default the CRC is not checked to speed up reading. \nIn fact, default only the two temperature registers are read.\nBy setting ```sensor.setConfig(DS18B20_CRC);``` the whole scratchpad is read\nand the CRC can be checked. \n\n\ntable of known \"strange values\" and actions one could take.\nIt is meant to start some diagnosis.\n\n| value   | possible cause                      | optional action |\n|:--------|:------------------------------------|:----------------|\n|  0.0000 | data line has no pull up            | use pull up     |\n| -0.0625 | data line is constantly pulled HIGH | check GND       |\n| -128    | CRC error                           | wrong pull up, bad sensor ? | \n| -127    | DISCONNECTED                        | check wires     }\n\nIf a value occurs only once in a while, wiring is often the cause, \nor it can be caused by e.g. induction e.g. switching on a motor while \nsensor is read.\n\n\n## Credits\n\nMiles Burton who originally developed the Arduino Temperature Control Library.\nand all people who contributed to that library.\n\n\n## Future\n\n#### Must\n\n- elaborate performance connected state.\n\n#### Should\n\n- investigate performance gain of no CRC.\n  - add performance table in readme.md\n- Extend oneWireSearch with device types\n  - see oneWireScanner.ino (2016 version)\n- should checkConnect be a **config** flag like CRC?\n\n#### Could\n\n\n#### Wont\n\n- unit tests\n  - get it working is too time consuming.\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FDS18B20_RT","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRobTillaart%2FDS18B20_RT","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FDS18B20_RT/lists"}