{"id":18837047,"url":"https://github.com/xreef/dht12_sensor_library","last_synced_at":"2025-04-14T06:21:49.358Z","repository":{"id":104293967,"uuid":"106580531","full_name":"xreef/DHT12_sensor_library","owner":"xreef","description":"DHT12 complete library (Original DHT clone library with same command and some addiction). I2c and OneWire support, connection schema of Arduino UNO, esp32 and esp8266 with examples.","archived":false,"fork":false,"pushed_at":"2022-04-07T05:47:43.000Z","size":2562,"stargazers_count":24,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T20:07:23.366Z","etag":null,"topics":["arduino","arduino-library","dht12","esp32","esp8266","library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xreef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2017-10-11T16:31:39.000Z","updated_at":"2023-11-08T23:48:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"101003c9-d148-4789-a5f7-d64be104bfd6","html_url":"https://github.com/xreef/DHT12_sensor_library","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FDHT12_sensor_library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FDHT12_sensor_library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FDHT12_sensor_library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FDHT12_sensor_library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xreef","download_url":"https://codeload.github.com/xreef/DHT12_sensor_library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830900,"owners_count":21168367,"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","arduino-library","dht12","esp32","esp8266","library"],"created_at":"2024-11-08T02:33:31.697Z","updated_at":"2025-04-14T06:21:49.343Z","avatar_url":"https://github.com/xreef.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cdiv\u003e\n\u003ca href=\"https://www.mischianti.org/forums/forum/mischiantis-libraries/dht12-complete-library-adafruit-dht-clone/\"\u003e\u003cimg\n  src=\"https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumEnglish.png\" alt=\"Support forum DHT12 English\"\n   align=\"right\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n\u003ca href=\"https://www.mischianti.org/it/forums/forum/le-librerie-di-mischianti/dht12-libreria-clone-delladafruit-dht/\"\u003e\u003cimg\n  src=\"https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumItaliano.png\" alt=\"Forum supporto DHT12 italiano\"\n  align=\"right\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\nAdditional information and document update here on my site: [DHT12 Article](https://www.mischianti.org/2019/01/01/dht12-library-en/).\n\nHere a comparison of the major competitor of the sensor: \n[Temperature humidity sensors comparison (Specifications) Part 1](https://www.mischianti.org/2019/07/01/temperature-humidity-sensors-comparison-settings-part-1/)\n\n[Temperature humidity sensors comparison (Code configuration) Part 2](https://www.mischianti.org/2019/07/08/temperature-humidity-sensors-comparison-code-configuration-part-2/).\n\n[Temperature humidity sensors comparison (Data) Part 3](https://www.mischianti.org/2019/07/16/temperature-humidity-sensors-comparison-data-part-3/).\n\n![](https://www.mischianti.org/wp-content/uploads/2019/02/BreadBoardArduinoWeather-768x432.jpg)\n\nThis is an Arduino and esp8266 library for the DHT12 series of very low cost temperature/humidity sensors (less than 1$) that work with i2c or one wire connection.\n\nAI read that sometime seems that need calibration, but I have tree of this and get value very similar to DHT22. If you have calibration this problem, open issue on github and I add implementation.\n\n06/04/2022: v1.0.2 Fix package size\n\nTutorial: \n\nTo download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT12. Check that the DHT folder contains `DHT12.cpp` and `DHT12.h`. Place the DHT library folder your `\u003carduinosketchfolder\u003e/libraries/` folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.\n\n# Reef complete DHT12 Humidity \u0026 Temperature\n\nThis libray try to emulate the behaivor of standard *DHT library sensors* (and copy a lot of code), and I add the code to manage i2c olso in the same manner.\n\nThe method is the same of *DHT library sensor*, with some adding like *dew point* function.\n\nTo use with i2c (default address and default SDA SCL pin) the constructor is:\n```cpp\nDHT12 dht12;\n```\nand take the default value for SDA SCL pin. (It's possible to redefine with specified contructor for esp8266, needed for ESP-01).\nor\n```cpp\nDHT12 dht12(uint8_t addressOrPin)\n```\n`addressOrPin -\u003e address`\nto change address.\n\nTo use one wire:\n```cpp\nDHT12 dht12(uint8_t addressOrPin, true)\n```\n`addressOrPin -\u003e pin`\nboolean value is the selection of oneWire or i2c mode.\n\nYou can use It with \"implicit\", \"simple read\" or \"fullread\":\n**Implicit**, *only the first read doing a true read of the sensor, the other read that become in 2secs. interval are the stored value of first read*.\n```cpp\n\t\t// The read of sensor have 2secs of elapsed time, unless you pass force parameter\n\t\t// Read temperature as Celsius (the default)\n\t\tfloat t12 = dht12.readTemperature();\n\t\t// Read temperature as Fahrenheit (isFahrenheit = true)\n\t\tfloat f12 = dht12.readTemperature(true);\n\t\t// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)\n\t\tfloat h12 = dht12.readHumidity();\n\t\t\n\t\t\n\t\t// Compute heat index in Fahrenheit (the default)\n\t\tfloat hif12 = dht12.computeHeatIndex(f12, h12);\n\t\t// Compute heat index in Celsius (isFahreheit = false)\n\t\tfloat hic12 = dht12.computeHeatIndex(t12, h12, false);\n\t\t// Compute dew point in Fahrenheit (the default)\n\t\tfloat dpf12 = dht12.dewPoint(f12, h12);\n\t\t// Compute dew point in Celsius (isFahreheit = false)\n\t\tfloat dpc12 = dht12.dewPoint(t12, h12, false);\n\n```\n**Simple read** to get a status of read.\n```cpp\n\t\t// The read of sensor have 2secs of elapsed time, unless you pass force parameter\n\t\tbool chk = dht12.read(); // true read is ok, false read problem\n\n\t\t// Read temperature as Celsius (the default)\n\t\tfloat t12 = dht12.readTemperature();\n\t\t// Read temperature as Fahrenheit (isFahrenheit = true)\n\t\tfloat f12 = dht12.readTemperature(true);\n\t\t// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)\n\t\tfloat h12 = dht12.readHumidity();\n\t\t\n\t\t// Compute heat index in Fahrenheit (the default)\n\t\tfloat hif12 = dht12.computeHeatIndex(f12, h12);\n\t\t// Compute heat index in Celsius (isFahreheit = false)\n\t\tfloat hic12 = dht12.computeHeatIndex(t12, h12, false);\n\t\t// Compute dew point in Fahrenheit (the default)\n\t\tfloat dpf12 = dht12.dewPoint(f12, h12);\n\t\t// Compute dew point in Celsius (isFahreheit = false)\n\t\tfloat dpc12 = dht12.dewPoint(t12, h12, false);\n\n```\n**Full read** to get a specified status.\n```cpp\n\t\t// The read of sensor have 2secs of elapsed time, unless you pass force parameter\n\t\tDHT12::ReadStatus chk = dht12.readStatus();\n\t\tSerial.print(F(\"\\nRead sensor: \"));\n\t\tswitch (chk) {\n\t\tcase DHT12::OK:\n\t\t\tSerial.println(F(\"OK\"));\n\t\t\tbreak;\n\t\tcase DHT12::ERROR_CHECKSUM:\n\t\t\tSerial.println(F(\"Checksum error\"));\n\t\t\tbreak;\n\t\tcase DHT12::ERROR_TIMEOUT:\n\t\t\tSerial.println(F(\"Timeout error\"));\n\t\t\tbreak;\n\t\tcase DHT12::ERROR_TIMEOUT_LOW:\n\t\t\tSerial.println(F(\"Timeout error on low signal, try put high pullup resistance\"));\n\t\t\tbreak;\n\t\tcase DHT12::ERROR_TIMEOUT_HIGH:\n\t\t\tSerial.println(F(\"Timeout error on low signal, try put low pullup resistance\"));\n\t\t\tbreak;\n\t\tcase DHT12::ERROR_CONNECT:\n\t\t\tSerial.println(F(\"Connect error\"));\n\t\t\tbreak;\n\t\tcase DHT12::ERROR_ACK_L:\n\t\t\tSerial.println(F(\"AckL error\"));\n\t\t\tbreak;\n\t\tcase DHT12::ERROR_ACK_H:\n\t\t\tSerial.println(F(\"AckH error\"));\n\t\t\tbreak;\n\t\tcase DHT12::ERROR_UNKNOWN:\n\t\t\tSerial.println(F(\"Unknown error DETECTED\"));\n\t\t\tbreak;\n\t\tcase DHT12::NONE:\n\t\t\tSerial.println(F(\"No result\"));\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tSerial.println(F(\"Unknown error\"));\n\t\t\tbreak;\n\t\t}\n\n\t\t// Read temperature as Celsius (the default)\n\t\tfloat t12 = dht12.readTemperature();\n\t\t// Read temperature as Fahrenheit (isFahrenheit = true)\n\t\tfloat f12 = dht12.readTemperature(true);\n\t\t// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)\n\t\tfloat h12 = dht12.readHumidity();\n\t\t\n\t\t// Compute heat index in Fahrenheit (the default)\n\t\tfloat hif12 = dht12.computeHeatIndex(f12, h12);\n\t\t// Compute heat index in Celsius (isFahreheit = false)\n\t\tfloat hic12 = dht12.computeHeatIndex(t12, h12, false);\n\t\t// Compute dew point in Fahrenheit (the default)\n\t\tfloat dpf12 = dht12.dewPoint(f12, h12);\n\t\t// Compute dew point in Celsius (isFahreheit = false)\n\t\tfloat dpc12 = dht12.dewPoint(t12, h12, false);\n\t\n```\n\nWith examples, there are the connection diagram, it's important to use correct pullup resistor.\n\nThanks to Bobadas, dplasa and adafruit, to share the code in github (where I take some code and ideas).\n\n## DHT12 PIN ##\n\n![DHT12 Pin](https://github.com/xreef/DHT12_sensor_library/blob/master/resources/DHT12_pinout.png) \n\n## DHT12 connection schema ##\nArduinoUNO i2c\n\n![ArduinoUNO i2c](https://github.com/xreef/DHT12_sensor_library/blob/master/examples/ArduinoI2CDHT12/ArduinoI2CDHT12.png)\n\nArduinoUNO oneWire \n\n![ArduinoUNO oneWire](https://github.com/xreef/DHT12_sensor_library/blob/master/examples/ArduinoOneWireDHT12/ArduinoOneWireDHT12.png)\n\nesp8266 (D1Mini) i2c\n\n![esp8266 (D1Mini) i2c](https://github.com/xreef/DHT12_sensor_library/blob/master/examples/esp8266I2CDHT12/esp8266I2CDHT12.png)\n\nesp8266 (D1Mini) oneWire\n\n![esp8266 (D1Mini) oneWire](https://github.com/xreef/DHT12_sensor_library/blob/master/examples/esp8266OneWireDHT12/esp8266OneWireDHT12.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxreef%2Fdht12_sensor_library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxreef%2Fdht12_sensor_library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxreef%2Fdht12_sensor_library/lists"}