├── .gitattributes ├── DHT-sensor-library ├── .github │ ├── ISSUE_TEMPLATE.md │ └── PULL_REQUEST_TEMPLATE.md ├── Adafruit_Sensor.h ├── DHT.cpp ├── DHT.h ├── DHT_U.cpp ├── DHT_U.h ├── README.md ├── examples │ ├── DHT_Unified_Sensor │ │ └── DHT_Unified_Sensor.ino │ └── DHTtester │ │ └── DHTtester.ino ├── keywords.txt └── library.properties ├── README.md ├── XODhumidifier ├── main │ └── patch.xodp └── project.xod ├── autoHumidifier └── autoHumidifier.ino ├── scheme1.jpg └── scheme2.jpg /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /DHT-sensor-library/.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /DHT-sensor-library/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /DHT-sensor-library/Adafruit_Sensor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/autoHumidifier/a4ee0fda48700ae0e747570528d95a892e30c142/DHT-sensor-library/Adafruit_Sensor.h -------------------------------------------------------------------------------- /DHT-sensor-library/DHT.cpp: -------------------------------------------------------------------------------- 1 | /* DHT library 2 | 3 | MIT license 4 | written by Adafruit Industries 5 | */ 6 | 7 | #include "DHT.h" 8 | 9 | #define MIN_INTERVAL 2000 10 | 11 | DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { 12 | _pin = pin; 13 | _type = type; 14 | #ifdef __AVR 15 | _bit = digitalPinToBitMask(pin); 16 | _port = digitalPinToPort(pin); 17 | #endif 18 | _maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for 19 | // reading pulses from DHT sensor. 20 | // Note that count is now ignored as the DHT reading algorithm adjusts itself 21 | // basd on the speed of the processor. 22 | } 23 | 24 | void DHT::begin(void) { 25 | // set up the pins! 26 | pinMode(_pin, INPUT_PULLUP); 27 | // Using this value makes sure that millis() - lastreadtime will be 28 | // >= MIN_INTERVAL right away. Note that this assignment wraps around, 29 | // but so will the subtraction. 30 | _lastreadtime = -MIN_INTERVAL; 31 | DEBUG_PRINT("Max clock cycles: "); DEBUG_PRINTLN(_maxcycles, DEC); 32 | } 33 | 34 | //boolean S == Scale. True == Fahrenheit; False == Celcius 35 | float DHT::readTemperature(bool S, bool force) { 36 | float f = NAN; 37 | 38 | if (read(force)) { 39 | switch (_type) { 40 | case DHT11: 41 | f = data[2]; 42 | if(S) { 43 | f = convertCtoF(f); 44 | } 45 | break; 46 | case DHT22: 47 | case DHT21: 48 | f = data[2] & 0x7F; 49 | f *= 256; 50 | f += data[3]; 51 | f *= 0.1; 52 | if (data[2] & 0x80) { 53 | f *= -1; 54 | } 55 | if(S) { 56 | f = convertCtoF(f); 57 | } 58 | break; 59 | } 60 | } 61 | return f; 62 | } 63 | 64 | float DHT::convertCtoF(float c) { 65 | return c * 1.8 + 32; 66 | } 67 | 68 | float DHT::convertFtoC(float f) { 69 | return (f - 32) * 0.55555; 70 | } 71 | 72 | float DHT::readHumidity(bool force) { 73 | float f = NAN; 74 | if (read()) { 75 | switch (_type) { 76 | case DHT11: 77 | f = data[0]; 78 | break; 79 | case DHT22: 80 | case DHT21: 81 | f = data[0]; 82 | f *= 256; 83 | f += data[1]; 84 | f *= 0.1; 85 | break; 86 | } 87 | } 88 | return f; 89 | } 90 | 91 | //boolean isFahrenheit: True == Fahrenheit; False == Celcius 92 | float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit) { 93 | // Using both Rothfusz and Steadman's equations 94 | // http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml 95 | float hi; 96 | 97 | if (!isFahrenheit) 98 | temperature = convertCtoF(temperature); 99 | 100 | hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094)); 101 | 102 | if (hi > 79) { 103 | hi = -42.379 + 104 | 2.04901523 * temperature + 105 | 10.14333127 * percentHumidity + 106 | -0.22475541 * temperature*percentHumidity + 107 | -0.00683783 * pow(temperature, 2) + 108 | -0.05481717 * pow(percentHumidity, 2) + 109 | 0.00122874 * pow(temperature, 2) * percentHumidity + 110 | 0.00085282 * temperature*pow(percentHumidity, 2) + 111 | -0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2); 112 | 113 | if((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0)) 114 | hi -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882); 115 | 116 | else if((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0)) 117 | hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2); 118 | } 119 | 120 | return isFahrenheit ? hi : convertFtoC(hi); 121 | } 122 | 123 | boolean DHT::read(bool force) { 124 | // Check if sensor was read less than two seconds ago and return early 125 | // to use last reading. 126 | uint32_t currenttime = millis(); 127 | if (!force && ((currenttime - _lastreadtime) < 2000)) { 128 | return _lastresult; // return last correct measurement 129 | } 130 | _lastreadtime = currenttime; 131 | 132 | // Reset 40 bits of received data to zero. 133 | data[0] = data[1] = data[2] = data[3] = data[4] = 0; 134 | 135 | // Send start signal. See DHT datasheet for full signal diagram: 136 | // http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf 137 | 138 | // Go into high impedence state to let pull-up raise data line level and 139 | // start the reading process. 140 | digitalWrite(_pin, HIGH); 141 | delay(250); 142 | 143 | // First set data line low for 20 milliseconds. 144 | pinMode(_pin, OUTPUT); 145 | digitalWrite(_pin, LOW); 146 | delay(20); 147 | 148 | uint32_t cycles[80]; 149 | { 150 | // Turn off interrupts temporarily because the next sections are timing critical 151 | // and we don't want any interruptions. 152 | InterruptLock lock; 153 | 154 | // End the start signal by setting data line high for 40 microseconds. 155 | digitalWrite(_pin, HIGH); 156 | delayMicroseconds(40); 157 | 158 | // Now start reading the data line to get the value from the DHT sensor. 159 | pinMode(_pin, INPUT_PULLUP); 160 | delayMicroseconds(10); // Delay a bit to let sensor pull data line low. 161 | 162 | // First expect a low signal for ~80 microseconds followed by a high signal 163 | // for ~80 microseconds again. 164 | if (expectPulse(LOW) == 0) { 165 | DEBUG_PRINTLN(F("Timeout waiting for start signal low pulse.")); 166 | _lastresult = false; 167 | return _lastresult; 168 | } 169 | if (expectPulse(HIGH) == 0) { 170 | DEBUG_PRINTLN(F("Timeout waiting for start signal high pulse.")); 171 | _lastresult = false; 172 | return _lastresult; 173 | } 174 | 175 | // Now read the 40 bits sent by the sensor. Each bit is sent as a 50 176 | // microsecond low pulse followed by a variable length high pulse. If the 177 | // high pulse is ~28 microseconds then it's a 0 and if it's ~70 microseconds 178 | // then it's a 1. We measure the cycle count of the initial 50us low pulse 179 | // and use that to compare to the cycle count of the high pulse to determine 180 | // if the bit is a 0 (high state cycle count < low state cycle count), or a 181 | // 1 (high state cycle count > low state cycle count). Note that for speed all 182 | // the pulses are read into a array and then examined in a later step. 183 | for (int i=0; i<80; i+=2) { 184 | cycles[i] = expectPulse(LOW); 185 | cycles[i+1] = expectPulse(HIGH); 186 | } 187 | } // Timing critical code is now complete. 188 | 189 | // Inspect pulses and determine which ones are 0 (high state cycle count < low 190 | // state cycle count), or 1 (high state cycle count > low state cycle count). 191 | for (int i=0; i<40; ++i) { 192 | uint32_t lowCycles = cycles[2*i]; 193 | uint32_t highCycles = cycles[2*i+1]; 194 | if ((lowCycles == 0) || (highCycles == 0)) { 195 | DEBUG_PRINTLN(F("Timeout waiting for pulse.")); 196 | _lastresult = false; 197 | return _lastresult; 198 | } 199 | data[i/8] <<= 1; 200 | // Now compare the low and high cycle times to see if the bit is a 0 or 1. 201 | if (highCycles > lowCycles) { 202 | // High cycles are greater than 50us low cycle count, must be a 1. 203 | data[i/8] |= 1; 204 | } 205 | // Else high cycles are less than (or equal to, a weird case) the 50us low 206 | // cycle count so this must be a zero. Nothing needs to be changed in the 207 | // stored data. 208 | } 209 | 210 | DEBUG_PRINTLN(F("Received:")); 211 | DEBUG_PRINT(data[0], HEX); DEBUG_PRINT(F(", ")); 212 | DEBUG_PRINT(data[1], HEX); DEBUG_PRINT(F(", ")); 213 | DEBUG_PRINT(data[2], HEX); DEBUG_PRINT(F(", ")); 214 | DEBUG_PRINT(data[3], HEX); DEBUG_PRINT(F(", ")); 215 | DEBUG_PRINT(data[4], HEX); DEBUG_PRINT(F(" =? ")); 216 | DEBUG_PRINTLN((data[0] + data[1] + data[2] + data[3]) & 0xFF, HEX); 217 | 218 | // Check we read 40 bits and that the checksum matches. 219 | if (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) { 220 | _lastresult = true; 221 | return _lastresult; 222 | } 223 | else { 224 | DEBUG_PRINTLN(F("Checksum failure!")); 225 | _lastresult = false; 226 | return _lastresult; 227 | } 228 | } 229 | 230 | // Expect the signal line to be at the specified level for a period of time and 231 | // return a count of loop cycles spent at that level (this cycle count can be 232 | // used to compare the relative time of two pulses). If more than a millisecond 233 | // ellapses without the level changing then the call fails with a 0 response. 234 | // This is adapted from Arduino's pulseInLong function (which is only available 235 | // in the very latest IDE versions): 236 | // https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/wiring_pulse.c 237 | uint32_t DHT::expectPulse(bool level) { 238 | uint32_t count = 0; 239 | // On AVR platforms use direct GPIO port access as it's much faster and better 240 | // for catching pulses that are 10's of microseconds in length: 241 | #ifdef __AVR 242 | uint8_t portState = level ? _bit : 0; 243 | while ((*portInputRegister(_port) & _bit) == portState) { 244 | if (count++ >= _maxcycles) { 245 | return 0; // Exceeded timeout, fail. 246 | } 247 | } 248 | // Otherwise fall back to using digitalRead (this seems to be necessary on ESP8266 249 | // right now, perhaps bugs in direct port access functions?). 250 | #else 251 | while (digitalRead(_pin) == level) { 252 | if (count++ >= _maxcycles) { 253 | return 0; // Exceeded timeout, fail. 254 | } 255 | } 256 | #endif 257 | 258 | return count; 259 | } 260 | -------------------------------------------------------------------------------- /DHT-sensor-library/DHT.h: -------------------------------------------------------------------------------- 1 | /* DHT library 2 | 3 | MIT license 4 | written by Adafruit Industries 5 | */ 6 | #ifndef DHT_H 7 | #define DHT_H 8 | 9 | #if ARDUINO >= 100 10 | #include "Arduino.h" 11 | #else 12 | #include "WProgram.h" 13 | #endif 14 | 15 | 16 | // Uncomment to enable printing out nice debug messages. 17 | //#define DHT_DEBUG 18 | 19 | // Define where debug output will be printed. 20 | #define DEBUG_PRINTER Serial 21 | 22 | // Setup debug printing macros. 23 | #ifdef DHT_DEBUG 24 | #define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); } 25 | #define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); } 26 | #else 27 | #define DEBUG_PRINT(...) {} 28 | #define DEBUG_PRINTLN(...) {} 29 | #endif 30 | 31 | // Define types of sensors. 32 | #define DHT11 11 33 | #define DHT22 22 34 | #define DHT21 21 35 | #define AM2301 21 36 | 37 | 38 | class DHT { 39 | public: 40 | DHT(uint8_t pin, uint8_t type, uint8_t count=6); 41 | void begin(void); 42 | float readTemperature(bool S=false, bool force=false); 43 | float convertCtoF(float); 44 | float convertFtoC(float); 45 | float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); 46 | float readHumidity(bool force=false); 47 | boolean read(bool force=false); 48 | 49 | private: 50 | uint8_t data[5]; 51 | uint8_t _pin, _type; 52 | #ifdef __AVR 53 | // Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask 54 | // for the digital pin connected to the DHT. Other platforms will use digitalRead. 55 | uint8_t _bit, _port; 56 | #endif 57 | uint32_t _lastreadtime, _maxcycles; 58 | bool _lastresult; 59 | 60 | uint32_t expectPulse(bool level); 61 | 62 | }; 63 | 64 | class InterruptLock { 65 | public: 66 | InterruptLock() { 67 | noInterrupts(); 68 | } 69 | ~InterruptLock() { 70 | interrupts(); 71 | } 72 | 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /DHT-sensor-library/DHT_U.cpp: -------------------------------------------------------------------------------- 1 | // DHT Temperature & Humidity Unified Sensor Library 2 | // Copyright (c) 2014 Adafruit Industries 3 | // Author: Tony DiCola 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | #include "DHT_U.h" 23 | 24 | DHT_Unified::DHT_Unified(uint8_t pin, uint8_t type, uint8_t count, int32_t tempSensorId, int32_t humiditySensorId): 25 | _dht(pin, type, count), 26 | _type(type), 27 | _temp(this, tempSensorId), 28 | _humidity(this, humiditySensorId) 29 | {} 30 | 31 | void DHT_Unified::begin() { 32 | _dht.begin(); 33 | } 34 | 35 | void DHT_Unified::setName(sensor_t* sensor) { 36 | switch(_type) { 37 | case DHT11: 38 | strncpy(sensor->name, "DHT11", sizeof(sensor->name) - 1); 39 | break; 40 | case DHT21: 41 | strncpy(sensor->name, "DHT21", sizeof(sensor->name) - 1); 42 | break; 43 | case DHT22: 44 | strncpy(sensor->name, "DHT22", sizeof(sensor->name) - 1); 45 | break; 46 | default: 47 | // TODO: Perhaps this should be an error? However main DHT library doesn't enforce 48 | // restrictions on the sensor type value. Pick a generic name for now. 49 | strncpy(sensor->name, "DHT?", sizeof(sensor->name) - 1); 50 | break; 51 | } 52 | sensor->name[sizeof(sensor->name)- 1] = 0; 53 | } 54 | 55 | void DHT_Unified::setMinDelay(sensor_t* sensor) { 56 | switch(_type) { 57 | case DHT11: 58 | sensor->min_delay = 1000000L; // 1 second (in microseconds) 59 | break; 60 | case DHT21: 61 | sensor->min_delay = 2000000L; // 2 seconds (in microseconds) 62 | break; 63 | case DHT22: 64 | sensor->min_delay = 2000000L; // 2 seconds (in microseconds) 65 | break; 66 | default: 67 | // Default to slowest sample rate in case of unknown type. 68 | sensor->min_delay = 2000000L; // 2 seconds (in microseconds) 69 | break; 70 | } 71 | } 72 | 73 | DHT_Unified::Temperature::Temperature(DHT_Unified* parent, int32_t id): 74 | _parent(parent), 75 | _id(id) 76 | {} 77 | 78 | bool DHT_Unified::Temperature::getEvent(sensors_event_t* event) { 79 | // Clear event definition. 80 | memset(event, 0, sizeof(sensors_event_t)); 81 | // Populate sensor reading values. 82 | event->version = sizeof(sensors_event_t); 83 | event->sensor_id = _id; 84 | event->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; 85 | event->timestamp = millis(); 86 | event->temperature = _parent->_dht.readTemperature(); 87 | 88 | return true; 89 | } 90 | 91 | void DHT_Unified::Temperature::getSensor(sensor_t* sensor) { 92 | // Clear sensor definition. 93 | memset(sensor, 0, sizeof(sensor_t)); 94 | // Set sensor name. 95 | _parent->setName(sensor); 96 | // Set version and ID 97 | sensor->version = DHT_SENSOR_VERSION; 98 | sensor->sensor_id = _id; 99 | // Set type and characteristics. 100 | sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; 101 | _parent->setMinDelay(sensor); 102 | switch (_parent->_type) { 103 | case DHT11: 104 | sensor->max_value = 50.0F; 105 | sensor->min_value = 0.0F; 106 | sensor->resolution = 2.0F; 107 | break; 108 | case DHT21: 109 | sensor->max_value = 80.0F; 110 | sensor->min_value = -40.0F; 111 | sensor->resolution = 0.1F; 112 | break; 113 | case DHT22: 114 | sensor->max_value = 125.0F; 115 | sensor->min_value = -40.0F; 116 | sensor->resolution = 0.1F; 117 | break; 118 | default: 119 | // Unknown type, default to 0. 120 | sensor->max_value = 0.0F; 121 | sensor->min_value = 0.0F; 122 | sensor->resolution = 0.0F; 123 | break; 124 | } 125 | } 126 | 127 | DHT_Unified::Humidity::Humidity(DHT_Unified* parent, int32_t id): 128 | _parent(parent), 129 | _id(id) 130 | {} 131 | 132 | bool DHT_Unified::Humidity::getEvent(sensors_event_t* event) { 133 | // Clear event definition. 134 | memset(event, 0, sizeof(sensors_event_t)); 135 | // Populate sensor reading values. 136 | event->version = sizeof(sensors_event_t); 137 | event->sensor_id = _id; 138 | event->type = SENSOR_TYPE_RELATIVE_HUMIDITY; 139 | event->timestamp = millis(); 140 | event->relative_humidity = _parent->_dht.readHumidity(); 141 | 142 | return true; 143 | } 144 | 145 | void DHT_Unified::Humidity::getSensor(sensor_t* sensor) { 146 | // Clear sensor definition. 147 | memset(sensor, 0, sizeof(sensor_t)); 148 | // Set sensor name. 149 | _parent->setName(sensor); 150 | // Set version and ID 151 | sensor->version = DHT_SENSOR_VERSION; 152 | sensor->sensor_id = _id; 153 | // Set type and characteristics. 154 | sensor->type = SENSOR_TYPE_RELATIVE_HUMIDITY; 155 | _parent->setMinDelay(sensor); 156 | switch (_parent->_type) { 157 | case DHT11: 158 | sensor->max_value = 80.0F; 159 | sensor->min_value = 20.0F; 160 | sensor->resolution = 5.0F; 161 | break; 162 | case DHT21: 163 | sensor->max_value = 100.0F; 164 | sensor->min_value = 0.0F; 165 | sensor->resolution = 0.1F; 166 | break; 167 | case DHT22: 168 | sensor->max_value = 100.0F; 169 | sensor->min_value = 0.0F; 170 | sensor->resolution = 0.1F; 171 | break; 172 | default: 173 | // Unknown type, default to 0. 174 | sensor->max_value = 0.0F; 175 | sensor->min_value = 0.0F; 176 | sensor->resolution = 0.0F; 177 | break; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /DHT-sensor-library/DHT_U.h: -------------------------------------------------------------------------------- 1 | // DHT Temperature & Humidity Unified Sensor Library 2 | // Copyright (c) 2014 Adafruit Industries 3 | // Author: Tony DiCola 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | #ifndef DHT_U_H 23 | #define DHT_U_H 24 | 25 | #include 26 | #include 27 | 28 | #define DHT_SENSOR_VERSION 1 29 | 30 | class DHT_Unified { 31 | public: 32 | DHT_Unified(uint8_t pin, uint8_t type, uint8_t count=6, int32_t tempSensorId=-1, int32_t humiditySensorId=-1); 33 | void begin(); 34 | 35 | class Temperature : public Adafruit_Sensor { 36 | public: 37 | Temperature(DHT_Unified* parent, int32_t id); 38 | bool getEvent(sensors_event_t* event); 39 | void getSensor(sensor_t* sensor); 40 | 41 | private: 42 | DHT_Unified* _parent; 43 | int32_t _id; 44 | 45 | }; 46 | 47 | class Humidity : public Adafruit_Sensor { 48 | public: 49 | Humidity(DHT_Unified* parent, int32_t id); 50 | bool getEvent(sensors_event_t* event); 51 | void getSensor(sensor_t* sensor); 52 | 53 | private: 54 | DHT_Unified* _parent; 55 | int32_t _id; 56 | 57 | }; 58 | 59 | Temperature temperature() { 60 | return _temp; 61 | } 62 | 63 | Humidity humidity() { 64 | return _humidity; 65 | } 66 | 67 | private: 68 | DHT _dht; 69 | uint8_t _type; 70 | Temperature _temp; 71 | Humidity _humidity; 72 | 73 | void setName(sensor_t* sensor); 74 | void setMinDelay(sensor_t* sensor); 75 | 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /DHT-sensor-library/README.md: -------------------------------------------------------------------------------- 1 | This is an Arduino library for the DHT series of low cost temperature/humidity sensors. 2 | 3 | Tutorial: https://learn.adafruit.com/dht 4 | 5 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT. Check that the DHT folder contains DHT.cpp and DHT.h. Place the DHT library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. 6 | 7 | # Adafruit DHT Humidity & Temperature Unified Sensor Library 8 | 9 | This library also includes an optional class for the 10 | [DHT humidity and temperature sensor](https://learn.adafruit.com/dht/overview) 11 | which is designed to work with the [Adafruit unified sensor library](https://learn.adafruit.com/using-the-adafruit-unified-sensor-driver/introduction). 12 | 13 | You must have the following Arduino libraries installed to use this class: 14 | 15 | - [Adafruit Unified Sensor Library](https://github.com/adafruit/Adafruit_Sensor) 16 | -------------------------------------------------------------------------------- /DHT-sensor-library/examples/DHT_Unified_Sensor/DHT_Unified_Sensor.ino: -------------------------------------------------------------------------------- 1 | // DHT Temperature & Humidity Sensor 2 | // Unified Sensor Library Example 3 | // Written by Tony DiCola for Adafruit Industries 4 | // Released under an MIT license. 5 | 6 | // Depends on the following Arduino libraries: 7 | // - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor 8 | // - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define DHTPIN 2 // Pin which is connected to the DHT sensor. 15 | 16 | // Uncomment the type of sensor in use: 17 | //#define DHTTYPE DHT11 // DHT 11 18 | #define DHTTYPE DHT22 // DHT 22 (AM2302) 19 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 20 | 21 | // See guide for details on sensor wiring and usage: 22 | // https://learn.adafruit.com/dht/overview 23 | 24 | DHT_Unified dht(DHTPIN, DHTTYPE); 25 | 26 | uint32_t delayMS; 27 | 28 | void setup() { 29 | Serial.begin(9600); 30 | // Initialize device. 31 | dht.begin(); 32 | Serial.println("DHTxx Unified Sensor Example"); 33 | // Print temperature sensor details. 34 | sensor_t sensor; 35 | dht.temperature().getSensor(&sensor); 36 | Serial.println("------------------------------------"); 37 | Serial.println("Temperature"); 38 | Serial.print ("Sensor: "); Serial.println(sensor.name); 39 | Serial.print ("Driver Ver: "); Serial.println(sensor.version); 40 | Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); 41 | Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" *C"); 42 | Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" *C"); 43 | Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" *C"); 44 | Serial.println("------------------------------------"); 45 | // Print humidity sensor details. 46 | dht.humidity().getSensor(&sensor); 47 | Serial.println("------------------------------------"); 48 | Serial.println("Humidity"); 49 | Serial.print ("Sensor: "); Serial.println(sensor.name); 50 | Serial.print ("Driver Ver: "); Serial.println(sensor.version); 51 | Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); 52 | Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println("%"); 53 | Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println("%"); 54 | Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println("%"); 55 | Serial.println("------------------------------------"); 56 | // Set delay between sensor readings based on sensor details. 57 | delayMS = sensor.min_delay / 1000; 58 | } 59 | 60 | void loop() { 61 | // Delay between measurements. 62 | delay(delayMS); 63 | // Get temperature event and print its value. 64 | sensors_event_t event; 65 | dht.temperature().getEvent(&event); 66 | if (isnan(event.temperature)) { 67 | Serial.println("Error reading temperature!"); 68 | } 69 | else { 70 | Serial.print("Temperature: "); 71 | Serial.print(event.temperature); 72 | Serial.println(" *C"); 73 | } 74 | // Get humidity event and print its value. 75 | dht.humidity().getEvent(&event); 76 | if (isnan(event.relative_humidity)) { 77 | Serial.println("Error reading humidity!"); 78 | } 79 | else { 80 | Serial.print("Humidity: "); 81 | Serial.print(event.relative_humidity); 82 | Serial.println("%"); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /DHT-sensor-library/examples/DHTtester/DHTtester.ino: -------------------------------------------------------------------------------- 1 | // Example testing sketch for various DHT humidity/temperature sensors 2 | // Written by ladyada, public domain 3 | 4 | #include "DHT.h" 5 | 6 | #define DHTPIN 2 // what digital pin we're connected to 7 | 8 | // Uncomment whatever type you're using! 9 | //#define DHTTYPE DHT11 // DHT 11 10 | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 11 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 12 | 13 | // Connect pin 1 (on the left) of the sensor to +5V 14 | // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 15 | // to 3.3V instead of 5V! 16 | // Connect pin 2 of the sensor to whatever your DHTPIN is 17 | // Connect pin 4 (on the right) of the sensor to GROUND 18 | // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor 19 | 20 | // Initialize DHT sensor. 21 | // Note that older versions of this library took an optional third parameter to 22 | // tweak the timings for faster processors. This parameter is no longer needed 23 | // as the current DHT reading algorithm adjusts itself to work on faster procs. 24 | DHT dht(DHTPIN, DHTTYPE); 25 | 26 | void setup() { 27 | Serial.begin(9600); 28 | Serial.println("DHTxx test!"); 29 | 30 | dht.begin(); 31 | } 32 | 33 | void loop() { 34 | // Wait a few seconds between measurements. 35 | delay(2000); 36 | 37 | // Reading temperature or humidity takes about 250 milliseconds! 38 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 39 | float h = dht.readHumidity(); 40 | // Read temperature as Celsius (the default) 41 | float t = dht.readTemperature(); 42 | // Read temperature as Fahrenheit (isFahrenheit = true) 43 | float f = dht.readTemperature(true); 44 | 45 | // Check if any reads failed and exit early (to try again). 46 | if (isnan(h) || isnan(t) || isnan(f)) { 47 | Serial.println("Failed to read from DHT sensor!"); 48 | return; 49 | } 50 | 51 | // Compute heat index in Fahrenheit (the default) 52 | float hif = dht.computeHeatIndex(f, h); 53 | // Compute heat index in Celsius (isFahreheit = false) 54 | float hic = dht.computeHeatIndex(t, h, false); 55 | 56 | Serial.print("Humidity: "); 57 | Serial.print(h); 58 | Serial.print(" %\t"); 59 | Serial.print("Temperature: "); 60 | Serial.print(t); 61 | Serial.print(" *C "); 62 | Serial.print(f); 63 | Serial.print(" *F\t"); 64 | Serial.print("Heat index: "); 65 | Serial.print(hic); 66 | Serial.print(" *C "); 67 | Serial.print(hif); 68 | Serial.println(" *F"); 69 | } 70 | -------------------------------------------------------------------------------- /DHT-sensor-library/keywords.txt: -------------------------------------------------------------------------------- 1 | ########################################### 2 | # Syntax Coloring Map For DHT-sensor-library 3 | ########################################### 4 | 5 | ########################################### 6 | # Datatypes (KEYWORD1) 7 | ########################################### 8 | 9 | DHT KEYWORD1 10 | 11 | ########################################### 12 | # Methods and Functions (KEYWORD2) 13 | ########################################### 14 | 15 | begin KEYWORD2 16 | readTemperature KEYWORD2 17 | convertCtoF KEYWORD2 18 | convertFtoC KEYWORD2 19 | computeHeatIndex KEYWORD2 20 | readHumidity KEYWORD2 21 | read KEYWORD2 22 | 23 | -------------------------------------------------------------------------------- /DHT-sensor-library/library.properties: -------------------------------------------------------------------------------- 1 | name=DHT sensor library 2 | version=1.3.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors 6 | paragraph=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors 7 | category=Sensors 8 | url=https://github.com/adafruit/DHT-sensor-library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![AlexGyver YouTube](http://alexgyver.ru/git_banner.jpg)](https://www.youtube.com/channel/UCgtAOyEQdAyjvm9ATCi_Aig?sub_confirmation=1) 2 | # Автоматический увлажнитель воздуха 3 | * [Описание проекта](#chapter-0) 4 | * [Папки проекта](#chapter-1) 5 | * [Схемы подключения](#chapter-2) 6 | * [Материалы и компоненты](#chapter-3) 7 | * [Настройка и использование](#chapter-4) 8 | * [FAQ](#chapter-5) 9 | * [Полезная информация](#chapter-6) 10 | 11 | 12 | ## Описание проекта 13 | Увлажнитель с датчиком влажности 14 | - Подробности в видео: https://youtu.be/EWCFQCREO4s 15 | 16 | 17 | ## Папки 18 | - **DHT-sensor-library** - библиотека датчика, скопировать в 19 | `C:\Program Files (x86)\Arduino\libraries\` (Windows x64) 20 | `C:\Program Files\Arduino\libraries\` (Windows x86) 21 | - **autoHumidifier** - прошивка для Arduino, файлы в папках открыть в Arduino IDE (читай [FAQ](#chapter-5)) 22 | - **XODhumidifier** - прошивка для Arduino, версия для [XOD](https://goo.gl/teWUBm) из видео 23 | 24 | 25 | ## Схема с DHT11 26 | ![СХЕМА](https://github.com/AlexGyver/autoHumidifier/blob/master/scheme1.jpg) 27 | 28 | ## Схема с DHT22 29 | ![СХЕМА](https://github.com/AlexGyver/autoHumidifier/blob/master/scheme2.jpg) 30 | 31 | 32 | ## Материалы и компоненты 33 | * Испаритель https://ali.ski/Q7W4i7 34 | https://ali.ski/J0ZdXX 35 | * Блок питания 24В https://ali.ski/WLg30F 36 | https://ali.ski/JmB8m 37 | * Испаритель + БП https://ali.ski/fABFNq 38 | https://ali.ski/TzGv6W 39 | * Arduino NANO https://ali.ski/zsfMEM 40 | * Датчик DHT11 https://ali.ski/n8qTZ 41 | * Датчик DHT22 https://ali.ski/6QWNm 42 | * MOSFET модуль https://ali.ski/sXnrd 43 | * Понижайка https://ali.ski/BePrd 44 | * Вентилятор https://ali.ski/nZF9y 45 | * Потенциометры https://ali.ski/RmqBS 46 | * Светодиоды https://ali.ski/2--Qh1 47 | * Резисторы https://ali.ski/fn-qTx 48 | 49 | ## Вам скорее всего пригодится 50 | * [Всё для пайки (паяльники и примочки)](http://alexgyver.ru/all-for-soldering/) 51 | * [Недорогие инструменты](http://alexgyver.ru/my_instruments/) 52 | * [Все существующие модули и сенсоры Arduino](http://alexgyver.ru/arduino_shop/) 53 | * [Электронные компоненты](http://alexgyver.ru/electronics/) 54 | * [Аккумуляторы и зарядные модули](http://alexgyver.ru/18650/) 55 | 56 | 57 | ## Настройка и использование 58 | * [Загрузка прошивки](http://alexgyver.ru/arduino-first/) - ультра подробная статья по началу работы с Ардуино 59 | * Установить библиотеки в 60 | `C:\Program Files (x86)\Arduino\libraries\` (Windows x64) 61 | `C:\Program Files\Arduino\libraries\` (Windows x86) 62 | * Подключить Ардуино к компьютеру 63 | * Запустить файл прошивки 64 | * Настроить (COM порт, модель Arduino NANO 328) 65 | * Нажать загрузить 66 | * Пользоваться 67 | 68 | ## Настройки в коде 69 | DHTTYPE DHT11 // используемый датчик, DHT11 или DHT22 70 | 71 | 72 | 73 | ## FAQ 74 | ### Основные вопросы 75 | В: Как скачать с этого грёбаного сайта? 76 | О: На главной странице проекта (где ты читаешь этот текст) вверху справа зелёная кнопка **Clone or download**, вот её жми, там будет **Download ZIP** 77 | 78 | В: Скачался какой то файл .zip, куда его теперь? 79 | О: Это архив. Можно открыть стандартными средствами Windows, но думаю у всех на компьютере установлен WinRAR, архив нужно правой кнопкой и извлечь. 80 | 81 | В: Я совсем новичок! Что мне делать с Ардуиной, где взять все программы? 82 | О: Читай и смотри видос http://alexgyver.ru/arduino-first/ 83 | 84 | В: Компьютер никак не реагирует на подключение Ардуины! 85 | О: Возможно у тебя зарядный USB кабель, а нужен именно data-кабель, по которому можно данные передавать 86 | 87 | В: Ошибка! Скетч не компилируется! 88 | О: Путь к скетчу не должен содержать кириллицу. Положи его в корень диска. 89 | 90 | В: Сколько стоит? 91 | О: Ничего не продаю. 92 | 93 | ### Вопросы по этому проекту 94 | 95 | 96 | ## Полезная информация 97 | * [Мои видеоуроки по пайке](https://www.youtube.com/playlist?list=PLOT_HeyBraBuMIwfSYu7kCKXxQGsUKcqR) 98 | * [Мои видеоуроки по Arduino](http://alexgyver.ru/arduino_lessons/) 99 | * [Мой сайт](http://alexgyver.ru/) 100 | * [Основной YouTube канал](https://www.youtube.com/channel/UCgtAOyEQdAyjvm9ATCi_Aig?sub_confirmation=1) 101 | * [YouTube канал про Arduino](https://www.youtube.com/channel/UC4axiS76D784-ofoTdo5zOA?sub_confirmation=1) -------------------------------------------------------------------------------- /XODhumidifier/main/patch.xodp: -------------------------------------------------------------------------------- 1 | { 2 | "links": [ 3 | { 4 | "id": "B1gT4MvCW", 5 | "input": { 6 | "nodeId": "S1Lh4Mv0W", 7 | "pinKey": "HJjZLRdBw1-" 8 | }, 9 | "output": { 10 | "nodeId": "S1nRWzPC-", 11 | "pinKey": "HkgBE9D8Z" 12 | } 13 | }, 14 | { 15 | "id": "HkBkrzPCW", 16 | "input": { 17 | "nodeId": "BkeaWGw0W", 18 | "pinKey": "HJ6HsEngZ" 19 | }, 20 | "output": { 21 | "nodeId": "S1Lh4Mv0W", 22 | "pinKey": "HktZUCdrPkZ" 23 | } 24 | }, 25 | { 26 | "id": "HyB6NMw0-", 27 | "input": { 28 | "nodeId": "S1Lh4Mv0W", 29 | "pinKey": "SJqZ8COrDkW" 30 | }, 31 | "output": { 32 | "nodeId": "H186ZMwRb", 33 | "pinKey": "SyBtREhlW" 34 | } 35 | }, 36 | { 37 | "id": "S1I1rzwRb", 38 | "input": { 39 | "nodeId": "SkC3bfPCZ", 40 | "pinKey": "HJ6HsEngZ" 41 | }, 42 | "output": { 43 | "nodeId": "S1Lh4Mv0W", 44 | "pinKey": "HktZUCdrPkZ" 45 | } 46 | }, 47 | { 48 | "id": "rktJHGwAW", 49 | "input": { 50 | "nodeId": "HkU7MMD0Z", 51 | "pinKey": "HJ6HsEngZ" 52 | }, 53 | "output": { 54 | "nodeId": "S1Lh4Mv0W", 55 | "pinKey": "HktZUCdrPkZ" 56 | } 57 | } 58 | ], 59 | "nodes": [ 60 | { 61 | "boundValues": { 62 | "B134j4neZ": 3, 63 | "HJ6HsEngZ": true 64 | }, 65 | "description": "sensor vcc", 66 | "id": "B1JT-zwAZ", 67 | "position": { 68 | "x": 204, 69 | "y": 204 70 | }, 71 | "type": "xod/core/digital-output" 72 | }, 73 | { 74 | "boundValues": { 75 | "B134j4neZ": 2 76 | }, 77 | "description": "mosfet pin", 78 | "id": "BkeaWGw0W", 79 | "position": { 80 | "x": -68, 81 | "y": 408 82 | }, 83 | "type": "xod/core/digital-output" 84 | }, 85 | { 86 | "boundValues": { 87 | "BJuORNheZ": 1 88 | }, 89 | "description": "potentiometer", 90 | "id": "H186ZMwRb", 91 | "position": { 92 | "x": 102, 93 | "y": 204 94 | }, 95 | "type": "xod/core/analog-input" 96 | }, 97 | { 98 | "boundValues": { 99 | "B134j4neZ": 12 100 | }, 101 | "description": "red LED", 102 | "id": "HkU7MMD0Z", 103 | "position": { 104 | "x": 68, 105 | "y": 408 106 | }, 107 | "type": "xod/core/digital-output" 108 | }, 109 | { 110 | "id": "S1Lh4Mv0W", 111 | "position": { 112 | "x": 34, 113 | "y": 306 114 | }, 115 | "type": "xod/core/less" 116 | }, 117 | { 118 | "boundValues": { 119 | "SkUQV5wIb": 4 120 | }, 121 | "id": "S1nRWzPC-", 122 | "position": { 123 | "x": -34, 124 | "y": 204 125 | }, 126 | "type": "xod/common-hardware/dht11-thermometer" 127 | }, 128 | { 129 | "boundValues": { 130 | "B134j4neZ": 11 131 | }, 132 | "description": "blue LED", 133 | "id": "SkC3bfPCZ", 134 | "position": { 135 | "x": 0, 136 | "y": 408 137 | }, 138 | "type": "xod/core/digital-output" 139 | }, 140 | { 141 | "boundValues": { 142 | "B134j4neZ": 5 143 | }, 144 | "description": "sensor GND", 145 | "id": "SybC2ZzwC-", 146 | "position": { 147 | "x": 272, 148 | "y": 204 149 | }, 150 | "type": "xod/core/digital-output" 151 | } 152 | ] 153 | } -------------------------------------------------------------------------------- /XODhumidifier/project.xod: -------------------------------------------------------------------------------- 1 | { 2 | "name": "humidifier" 3 | } -------------------------------------------------------------------------------- /autoHumidifier/autoHumidifier.ino: -------------------------------------------------------------------------------- 1 | #define DHTTYPE DHT11 // используемый датчик, DHT11 или DHT22 2 | 3 | #define potPIN A1 4 | #define mosPIN 2 5 | #define sensVCC 3 6 | #define sensDATA 4 7 | #define sensGND 5 8 | #define blueLED 11 9 | #define redLED 12 10 | 11 | #include "DHT.h" 12 | DHT dht(sensDATA, DHTTYPE); 13 | 14 | unsigned long readTimer; 15 | float hum; 16 | int pot; 17 | 18 | void setup() { 19 | pinMode(mosPIN, OUTPUT); 20 | pinMode(sensVCC, OUTPUT); 21 | pinMode(sensGND, OUTPUT); 22 | pinMode(blueLED, OUTPUT); 23 | pinMode(redLED, OUTPUT); 24 | pinMode(sensDATA, INPUT_PULLUP); 25 | digitalWrite(mosPIN, 0); 26 | digitalWrite(sensVCC, 1); 27 | digitalWrite(sensGND, 0); 28 | digitalWrite(blueLED, 0); 29 | digitalWrite(redLED, 0); 30 | 31 | Serial.begin(9600); 32 | dht.begin(); 33 | delay(1000); 34 | hum = dht.readHumidity(); 35 | } 36 | 37 | void loop() { 38 | pot = analogRead(potPIN) / 10; // перевод в диапазон примерно от 0 до 100 39 | if (pot > hum) { // если установка больше текущей влажности 40 | digitalWrite(mosPIN, 1); // врубить всё 41 | digitalWrite(blueLED, 1); 42 | digitalWrite(redLED, 1); 43 | } else { // если нет 44 | digitalWrite(mosPIN, 0); // вырубить всё 45 | digitalWrite(blueLED, 0); 46 | digitalWrite(redLED, 0); 47 | } 48 | 49 | if (millis() - readTimer > 1000) { // секундный таймер (для стабильности измерений) 50 | hum = dht.readHumidity(); // получить значение с датчика 51 | readTimer = millis(); // обнулить таймер 52 | } 53 | delay(5); // задержка для стабильности 54 | } 55 | -------------------------------------------------------------------------------- /scheme1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/autoHumidifier/a4ee0fda48700ae0e747570528d95a892e30c142/scheme1.jpg -------------------------------------------------------------------------------- /scheme2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/autoHumidifier/a4ee0fda48700ae0e747570528d95a892e30c142/scheme2.jpg --------------------------------------------------------------------------------