| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| en:iot-open:remotelab:sut:generalpurpose2:b2 [2020/04/28 16:00] – pczekalski | en:iot-open:remotelab:sut:generalpurpose2:b2 [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 |
|---|
| ==== B2: Presenting temperature and humidity on the LCD ==== | ==== B2: Presenting temperature and humidity on the LCD ==== |
| In this scenario, you will present temperature and humidity as read by the attached DHT22 sensor, on the LCD screen. | In this scenario, you will present temperature and humidity as read by the attached DHT11 sensor, on the LCD screen. |
| === Target group === | === Target group === |
| Beginners | Beginners |
| #include <LiquidCrystal_I2C.h> | #include <LiquidCrystal_I2C.h> |
| </code> | </code> |
| The temperature and humidity sensor is all-in-one, DHT22 sensor (white) or DHT11 (blue), connected to the pin D4. Observe your camera to check which sensor is equipped with your lab and consult node documentation.\\ | The temperature and humidity sensor is all-in-one, DHT11, connected to the pin D4. Observe your camera to check which sensor is equipped with your lab and consult node documentation.\\ |
| To read data you may use a dedicated library (libraries): | To read data you may use a dedicated library (libraries): |
| <code c> | <code c> |
| === Scenario === | === Scenario === |
| Once you initialise sensor and LCD display, read sensor data (temperature and humidity, mind they're float values, not integers) and then display them in the loop. Give each loop execution some 5-10s delay. | Once you initialise sensor and LCD display, read sensor data (temperature and humidity, mind they're float values, not integers) and then display them in the loop. Give each loop execution some 5-10s delay. |
| <note warning>Do not try to read temperature and humidity too frequent. Once every 5s is quite enough both for information and safe enough to not let your readings race with the communication protocol. If you read too frequent, your sensor may not be able to deliver data on time and you will obtain a 'nan' (not a number) instead of temperature and humidity.</note> | <note warning>Do not try to read temperature and humidity too frequently. Once every 5s is quite enough both for information and safe enough to not let your readings race with the communication protocol. If you read too frequent, your sensor may not be able to deliver data on time and you will obtain a 'nan' (not a number) instead of temperature and humidity.</note> |
| The first line of the LCD should display: "//Temperature is://"\\ | The first line of the LCD should display: "//Temperature is://"\\ |
| The second line should provide temperature within the "//NN.N C//" form, in Celcius.\\ | The second line should provide temperature within the "//NN.N C//" form, in Celcius.\\ |
| |
| == Step 2 == | == Step 2 == |
| Instantiate software controler component for the LCD display: | Instantiate software controller components for the LCD display and DHT sensor: |
| <code c> | <code c> |
| LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x3F for nodes 1 through 5, 8 and 9 | LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x3F for nodes 1 through 5, 8 and 9 |
| //LiquidCrystal_I2C lcd(0x27,20,4); // for nodes 10 and 11 only! | //LiquidCrystal_I2C lcd(0x27,20,4); // for nodes 10 and 11 only! |
| // for a 20 chars and 4 line display | // for a 20 chars and 4 line display |
| DHT dht(DHTpin,DHT22,50); | DHT dht(DHTpin, DHT11, 50); |
| </code> | </code> |
| == Step 3 == | == Step 3 == |
| |
| == Step 4 == | == Step 4 == |
| Initialize LCD and dht sensor: | Initialize LCD and DHT sensor: |
| <code c> | <code c> |
| ... | ... |
| ... | ... |
| </code> | </code> |
| <note tip>''sprintf'' uses number of wildcards that are rendered with data. Refer to the c/c++ documentation on ''sprintf''. Here <code c>%2.1f</code> means: having float number render it to string using two digits before decimal point and one after. Temperature in our lab is always above 10C. <code c>%%</code> is an escape character to print a <code c>%</code> (percent) symbol.\\''delay(time)'' is measured in milliseconds.</note> | <note tip>''sprintf'' uses number of wildcards that are rendered with data. Refer to the c/c++ documentation on ''sprintf''. Here <code c>%2.1f</code> means: having float number render it to string using two digits before decimal point and one after. Temperature in our lab is always above 10C. <code c>%%</code> is an escape character to print a <code c>%</code> (percent) symbol. |
| | <code c> |
| | delay(time) |
| | </code> is measured in milliseconds.</note> |
| |
| === Result validation === | === Result validation === |
| Observe temperature and humidity readings on the LCD. Temperature ranges between 20-30C while humidity between 35-60%Rh. | Observe temperature and humidity readings on the LCD. The temperature in our lab usually ranges between 20-30C (not, we observed over 30C during really hot summer!) while humidity is usually between 30-60%Rh. |
| |