This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:practical:hardware:sut:esp32:emb3_1 [2024/03/14 13:51] – [Result validation] pczekalski | en:iot-open:practical:hardware:sut:esp32:emb3_1 [2024/06/29 15:54] (current) – [Prerequisites] pczekalski | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== EMB3: Use of integrated temperature and humidity sensor ===== | ====== EMB3: Use of integrated temperature and humidity sensor ===== | ||
- | In this scenario, we will introduce a popular DHT11 sensor. The DHT series covers DHT11, DHT22, and AM2302. Those sensors differ in accuracy and physical dimensions but can all read environmental temperature and humidity. This scenario can be run stand-alone to read weather data in the laboratory nodes' room. The DHT11 sensor is controlled with one GPIO (in all our laboratory nodes, it is GPIO 47) and uses a proprietary protocol. | + | In this scenario, we will introduce a popular |
===== Prerequisites ===== | ===== Prerequisites ===== | ||
Line 6: | Line 6: | ||
<code ini> | <code ini> | ||
lib_deps = | lib_deps = | ||
- | | + | |
| | ||
</ | </ | ||
Line 13: | Line 13: | ||
* [[en: | * [[en: | ||
* [[en: | * [[en: | ||
- | * [[en: | + | * [[en: |
+ | |||
+ | It is also possible to present the temperature as the LED colour changes with a PWM-controlled LED or LED stripe. Their usage is described here: | ||
+ | * [[en: | ||
* [[en: | * [[en: | ||
Line 25: | Line 28: | ||
In this scenario, we only focus on reading the sensor (temperature and humidity). Information on how to display measurements is part of other scenarios that you should refer to to create a fully functional solution (see links above). | In this scenario, we only focus on reading the sensor (temperature and humidity). Information on how to display measurements is part of other scenarios that you should refer to to create a fully functional solution (see links above). | ||
==== Task to be implemented ==== | ==== Task to be implemented ==== | ||
- | //Describe a task to be implemented by the scenario user.// | + | Present |
==== Start ==== | ==== Start ==== | ||
Line 31: | Line 34: | ||
==== Steps ==== | ==== Steps ==== | ||
- | // Write some extra information if, i.e. some steps are optional; otherwise, cancel this paragraph | + | The steps below present only interaction with the sensor. Those steps should be supplied to present the data (or send it over the network) using other scenarios accordingly. |
=== Step 1 === | === Step 1 === | ||
- | //Describe activities done in Step 1.// | + | Include the DHT library and related sensor library. |
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | </code> | ||
- | ... | + | === Step 2 === |
+ | Declare type of the sensor and GPIO pin: | ||
+ | <code c> | ||
+ | #define DHTTYPE DHT11 // DHT 11 | ||
+ | #define DHTPIN 47 | ||
+ | </ | ||
- | === Step n === | + | === Step 3 === |
- | //Describe activities done in Step n.// | + | Declare controller class and variables to store data: |
+ | <code c> | ||
+ | static DHT dht(DHTPIN, DHTTYPE, | ||
+ | static float hum = 0; | ||
+ | static float temp = 0; | ||
+ | static boolean isDHTOk = false; | ||
+ | </code> | ||
+ | |||
+ | === Step 4 === | ||
+ | Initialise sensor (mind the '' | ||
+ | <code c> | ||
+ | dht.begin(); | ||
+ | delay(100); | ||
+ | </code> | ||
+ | |||
+ | === Step 5 === | ||
+ | Reat the data and check whether the sensor works OK. In the case of the DHT sensor and its controller class, we check the correctness of the readings once the reading is finished. The sensor does not return any status but checks if the reading is okay. This can be done by comparing the readings with the '' | ||
+ | <code c> | ||
+ | hum = dht.readHumidity(); | ||
+ | temp = dht.readTemperature(); | ||
+ | | ||
+ | </code> | ||
+ | <note important> | ||
==== Result validation ==== | ==== Result validation ==== | ||
Line 46: | Line 80: | ||
===== FAQ ===== | ===== FAQ ===== | ||
- | This section | + | **I've got NaN (Not a Number) readings. What to do?**: Check if GPIO is OK (should |
- | When using the printed version of this manual, please refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ. | + | |
- | // | + | |
- | **Question? | + | |
- | // | + | |
+ | <WRAP noprint> | ||
===== Project information ===== | ===== Project information ===== | ||
{{: | {{: | ||
Line 68: | Line 99: | ||
{{: | {{: | ||
</ | </ | ||
- | + | </ | |
- | + |