This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:sut:generalpurpose2:b2 [2021/02/27 11:46] – pczekalski | en:iot-open:remotelab:sut:generalpurpose2:b2 [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ==== B2: Presenting temperature and humidity on the LCD ==== | ||
| + | In this scenario, you will present temperature and humidity as read by the attached DHT11 sensor, on the LCD screen. | ||
| + | === Target group === | ||
| + | Beginners | ||
| + | |||
| + | === Prerequisites === | ||
| + | You need to know, how to print and position text on the LCD display. | ||
| + | Use LCD I2C library to control it: | ||
| + | <code c> | ||
| + | #include < | ||
| + | </ | ||
| + | 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): | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | </ | ||
| + | === Scenario === | ||
| + | Once you initialise sensor and LCD display, read sensor data (temperature and humidity, mind they' | ||
| + | <note warning> | ||
| + | The first line of the LCD should display: "// | ||
| + | The second line should provide temperature within the "// | ||
| + | The third line should display: "// | ||
| + | Finally, the fourth should present relative humidity: "// | ||
| + | |||
| + | You will use '' | ||
| + | === Result === | ||
| + | You should be able to see temperature and humidity readings on the LCD display using the video stream. | ||
| + | |||
| + | === Start === | ||
| + | There are no special steps to be performed. | ||
| + | |||
| + | === Steps === | ||
| + | |||
| + | == Step 1 == | ||
| + | Include LCD and DHT sensor driver libraries: | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | </ | ||
| + | |||
| + | == Step 2 == | ||
| + | Instantiate software controller components for the LCD display and DHT sensor: | ||
| + | <code c> | ||
| + | LiquidCrystal_I2C lcd(0x3F, | ||
| + | // | ||
| + | // for a 20 chars and 4 line display | ||
| + | DHT dht(DHTpin, DHT11, 50); | ||
| + | </ | ||
| + | == Step 3 == | ||
| + | Declare a buffer for '' | ||
| + | <code c> | ||
| + | char buffer [10]; | ||
| + | </ | ||
| + | |||
| + | == Step 4 == | ||
| + | Initialize LCD and DHT sensor: | ||
| + | <code c> | ||
| + | ... | ||
| + | lcd.init(D2, | ||
| + | lcd.backlight(); | ||
| + | lcd.home(); | ||
| + | ... | ||
| + | dht.begin(); | ||
| + | delay(1000); | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | == Step 5 == | ||
| + | Read in the loop: | ||
| + | <code c> | ||
| + | ... | ||
| + | float hum = dht.readHumidity(); | ||
| + | float temp = dht.readTemperature(); | ||
| + | ... | ||
| + | </ | ||
| + | To convert float into the string with formatting use '' | ||
| + | <code c> | ||
| + | ... | ||
| + | sprintf(buffer," | ||
| + | ... | ||
| + | sprintf(buffer," | ||
| + | ... | ||
| + | delay(5000); | ||
| + | ... | ||
| + | </ | ||
| + | <note tip>'' | ||
| + | <code c> | ||
| + | delay(time) | ||
| + | </ | ||
| + | |||
| + | === Result validation === | ||
| + | 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. | ||