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:53] – [Steps] 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 45: | Line 48: | ||
#define DHTPIN 47 | #define DHTPIN 47 | ||
</ | </ | ||
- | === Step n === | + | |
- | //Describe activities done in Step n.// | + | === Step 3 === |
+ | 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 54: | 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 76: | Line 99: | ||
{{: | {{: | ||
</ | </ | ||
- | + | </ | |
- | + |