This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:iot-open:remotelab:ume:smartme:b2 [2019/09/27 13:08] – created salvatdi | en:iot-open:remotelab:ume:smartme:b2 [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== B2: Presenting temperature and humidity values on the LCD ====== | + | ==== IB2: Presenting temperature and humidity values on the LCD ==== |
| - | + | === Target group === | |
| - | + | ||
| - | ===== Target group ===== | + | |
| This hands-on lab guide is intended for the Beginners but other target groups may benefit from it, treating it as basics for advanced projects. | This hands-on lab guide is intended for the Beginners but other target groups may benefit from it, treating it as basics for advanced projects. | ||
| - | ===== Prerequisites | + | === Prerequisites === |
| - | ==== Liquid Crystal | + | === Liquid Crystal === |
| For this library, you may refer to the [[en: | For this library, you may refer to the [[en: | ||
| - | ==== DHT sensors | + | === DHT sensors === |
| The nodes of SmartME Network Laboratory are equipped with different versions of DHT sensors: DHT11 and DHT22. | The nodes of SmartME Network Laboratory are equipped with different versions of DHT sensors: DHT11 and DHT22. | ||
| The sensors look a bit similar and have the same pinout, but have different characteristics. | The sensors look a bit similar and have the same pinout, but have different characteristics. | ||
| Below you can find the DHT technical specifications: | Below you can find the DHT technical specifications: | ||
| - | === DHT11 === | + | == DHT11 == |
| * Ultra-low-cost | * Ultra-low-cost | ||
| * 3 to 5V power and I/O | * 3 to 5V power and I/O | ||
| Line 27: | Line 25: | ||
| * 4 pins with 0.1" spacing | * 4 pins with 0.1" spacing | ||
| - | === DHT22 === | + | == DHT22 == |
| * Low cost | * Low cost | ||
| Line 45: | Line 43: | ||
| Temperature and relative humidity can be used to determine the apparent temperature or the human perceived equivalent temperature, | Temperature and relative humidity can be used to determine the apparent temperature or the human perceived equivalent temperature, | ||
| - | ==== Scenario ==== | + | === Scenario === |
| First, initialize LCD screen with the labels of temperature and relative humidity. | First, initialize LCD screen with the labels of temperature and relative humidity. | ||
| Then, after the sensor detection, next to the labels, the sensor values will be displayed, one per line, every 3 seconds. Note, the function readTemperature() reads temperature as Celsius (the default). If you want to read the temperature as Farenight, you have to set the true value as a parameter of the signature in the readTemperature(true) function. The relative humidity is expressed as a percentage. That means that at 100% RH the condensation occurs, while at 0% RH the air is completely dry. | Then, after the sensor detection, next to the labels, the sensor values will be displayed, one per line, every 3 seconds. Note, the function readTemperature() reads temperature as Celsius (the default). If you want to read the temperature as Farenight, you have to set the true value as a parameter of the signature in the readTemperature(true) function. The relative humidity is expressed as a percentage. That means that at 100% RH the condensation occurs, while at 0% RH the air is completely dry. | ||
| More, but not used in the proposed exercise, it is possible to compute the heat index in Fahrenheit (the default) by using the function computeHeatIndex(temp_value_farenight, | More, but not used in the proposed exercise, it is possible to compute the heat index in Fahrenheit (the default) by using the function computeHeatIndex(temp_value_farenight, | ||
| Result | Result | ||
| - | You should see the values of temperature and relative humidity, that are sampled and displayed every 3 seconds (3000 ms). | + | You should see the values of temperature and relative humidity, that is sampled and displayed every 3 seconds (3000 ms). |
| Start | Start | ||
| There are no special steps to be performed. | There are no special steps to be performed. | ||
| - | ==== Steps ==== | + | === Steps === |
| - | === Step 1 === | + | == Step 1 == |
| Include LCD driver library and DHT library: | Include LCD driver library and DHT library: | ||
| <code c> | <code c> | ||
| Line 64: | Line 63: | ||
| - | === Step 2 === | + | == Step 2 == |
| Instantiate the software controller component for the LCD display. Then set up: | Instantiate the software controller component for the LCD display. Then set up: | ||
| - the DHTPIN (which refers to the digital pin we use to get the signal); | - the DHTPIN (which refers to the digital pin we use to get the signal); | ||
| Line 70: | Line 69: | ||
| Then initialize the DHT sensor. | Then initialize the DHT sensor. | ||
| + | <code c> | ||
| // initialize the library with the numbers of the interface pins | // initialize the library with the numbers of the interface pins | ||
| LiquidCrystal lcd(7, 6, 5, 4, 13, 2); | LiquidCrystal lcd(7, 6, 5, 4, 13, 2); | ||
| Line 78: | Line 78: | ||
| // Initialize DHT sensor | // Initialize DHT sensor | ||
| DHT dht(DHTPIN, DHTTYPE); | DHT dht(DHTPIN, DHTTYPE); | ||
| + | </ | ||
| - | Step 3 | + | == Step 3 == |
| Initialize display and Initialize the DHT sensor - we suggest to do it in the setup() function: | Initialize display and Initialize the DHT sensor - we suggest to do it in the setup() function: | ||
| + | <code c> | ||
| void setup() { | void setup() { | ||
| // set up the LCD's number of columns and rows: | // set up the LCD's number of columns and rows: | ||
| Line 91: | Line 94: | ||
| // Print the Humidity label to the LCD. | // Print the Humidity label to the LCD. | ||
| lcd.print(" | lcd.print(" | ||
| - | |||
| dht.begin(); | dht.begin(); | ||
| } | } | ||
| + | </ | ||
| - | Step 4 | + | == Step 4 == |
| Implement loop() to sample and display the values of temperature and relative humidity on the LCD display, every 3 seconds: | Implement loop() to sample and display the values of temperature and relative humidity on the LCD display, every 3 seconds: | ||
| + | <code c> | ||
| void loop() { | void loop() { | ||
| // Wait three seconds between measurements. | // Wait three seconds between measurements. | ||
| Line 110: | Line 115: | ||
| // read temperature as Fahrenheit | // read temperature as Fahrenheit | ||
| //float f = dht.readTemperature(true); | //float f = dht.readTemperature(true); | ||
| - | | ||
| - | |||
| // compute heat index in Fahrenheit (the default) | // compute heat index in Fahrenheit (the default) | ||
| float hif = dht.computeHeatIndex(f, | float hif = dht.computeHeatIndex(f, | ||
| // compute heat index in Celsius (isFahreheit = false) | // compute heat index in Celsius (isFahreheit = false) | ||
| float hic = dht.computeHeatIndex(t, | float hic = dht.computeHeatIndex(t, | ||
| - | |||
| // print Temperature value to the LCD | // print Temperature value to the LCD | ||
| lcd.setCursor(14, | lcd.setCursor(14, | ||
| Line 124: | Line 126: | ||
| lcd.print(h); | lcd.print(h); | ||
| } | } | ||
| - | + | </ | |
| - | Result validation | + | |
| + | |||
| + | === Result validation | ||
| Observe the temperature and relative humidity values shown in the LCD display. The display will refresh values every 3 seconds. | Observe the temperature and relative humidity values shown in the LCD display. The display will refresh values every 3 seconds. | ||
| - | Platformio.ini | + | === Platformio.ini |
| - | + | < | |
| [env:uno] | [env:uno] | ||
| platform = atmelavr | platform = atmelavr | ||
| Line 144: | Line 148: | ||
| lib_deps_external = | lib_deps_external = | ||
| | | ||
| - | + | </ | |
| - | B2.cpp | + | |
| + | === IB2.cpp === | ||
| + | |||
| + | |||
| + | <code c> | ||
| #include < | #include < | ||
| #include " | #include " | ||
| Line 194: | Line 201: | ||
| | | ||
| } | } | ||
| + | </ | ||