This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:ume:smartme:u1 [2019/09/30 19:28] – salvatdi | en:iot-open:remotelab:ume:smartme:u1 [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ==== IU1: Showing temperature, | ||
| + | |||
| + | |||
| + | === Target group === | ||
| + | This hands-on lab guide is intended for the Undergraduate but other target groups may benefit from it, treating it as basics for advanced projects. | ||
| + | |||
| + | === Prerequisites === | ||
| + | |||
| + | == Liquid Crystal == | ||
| + | For this library, you may refer to the [[en: | ||
| + | |||
| + | == DHT == | ||
| + | For this library, you may refer to the [[en: | ||
| + | |||
| + | |||
| + | == PMS7003 == | ||
| + | All the SmartME Network Laboratory Arduino nodes are equipped with a PMS7003 sensor. | ||
| + | This sensor allows measuring the air quality by taking into account the PMx concentration. The working principle of such a sensor is based on producing scattering by using a laser to radiate suspending particles in the air, then collecting scattering light to a certain degree, and finally obtaining the curve of scattering light change with time. In the end, the equivalent particle diameter and the number of particles with different diameters per unit volume can be calculated [1]. | ||
| + | So, the values of PM1.0, PM2.5, and PM10, will be available for our scopes. | ||
| + | |||
| + | In order to physically interface the 10 bus lines of the dust sensor with Arduino Uno, we used the PMS7003 connector [2]. By supplying the adapter at 5V, the particle sensor will operate correctly and the data will be available at RX and TX pins. However, the serial voltage level is 3.3V typical, while Arduino Uno needs 5V. | ||
| + | For this reason, to supply the HV (High Voltage) side at 5V and the LV (Low Voltage), we introduced a bi-directional level converter [3] which allows correcting the serial levels of Arduino (5V) and of PMS7003 (3.3V). | ||
| + | |||
| + | [1]https:// | ||
| + | |||
| + | [2]https:// | ||
| + | |||
| + | [3]https:// | ||
| + | |||
| + | == Arduino Serial == | ||
| + | |||
| + | This function is used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port. On Uno pins 0 and 1 are used for communication with the computer. Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board) [4]. | ||
| + | |||
| + | Since is not possible to deploy the code by using, at the same time, the default RX, TX pins (0,1) of Arduino Uno, the PMS7003 is connected to pins 9 and 10: by using the < | ||
| + | |||
| + | [4]https:// | ||
| + | |||
| + | [5] https:// | ||
| + | |||
| + | === Scenario === | ||
| + | First, initialize LCD screen with the labels of temperature (“T”), relative humidity (“H”), and dust particles (“PM10”). | ||
| + | Then, after the sensor detection, next to the labels, the sensor values will be displayed, every 1 second. | ||
| + | Notice that, by enabling the serial print section, data will be available to the serial monitor too. | ||
| + | The sensor is able to measure three types of dust particles: PM1.0, PM2.5, and PM10. | ||
| + | It may take several seconds to have more precious values about these values. | ||
| + | Such values are represented by two bytes: the MSB and the LSB one, as shown in [6] (appendix I). | ||
| + | Only the MSB byte can be shown or, alternatively, | ||
| + | |||
| + | [6]https:// | ||
| + | |||
| + | === Result === | ||
| + | You should see the values of temperature, | ||
| + | |||
| + | === Start === | ||
| + | There are no special steps to be performed. | ||
| + | |||
| + | === Steps === | ||
| + | |||
| + | == Step 1 == | ||
| + | Include LCD driver library, DHT library and Software Serial library: | ||
| + | |||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include " | ||
| + | </ | ||
| + | |||
| + | == Step 2 == | ||
| + | Instantiate the software controller component for the LCD display. Then set up: | ||
| + | - 1) the DHTPIN (which refers to the digital pin we use to get the signal); | ||
| + | - 2) the DHT sensor type in use (DHT11 or DHT22, it depends on the node of the lab you are using). | ||
| + | Set the RX and TX pin of Arduino in the object of the SoftwareSerial library. | ||
| + | |||
| + | <code c> | ||
| + | #define DHTPIN 8 | ||
| + | #define DHTTYPE DHT22 | ||
| + | |||
| + | DHT dht(DHTPIN, DHTTYPE); | ||
| + | LiquidCrystal lcd(7, 6, 5, 4, 13, 2); | ||
| + | // Arduino Uno port RX, TX | ||
| + | SoftwareSerial mySerial(9, | ||
| + | </ | ||
| + | === Step 3 == | ||
| + | Initialize display. | ||
| + | Initialize the DHT sensor. | ||
| + | Sets the data rate in bits per second (baud) for serial data transmissions, | ||
| + | We suggest to do it in the setup() function: | ||
| + | |||
| + | <code c> | ||
| + | void setup() { | ||
| + | lcd.begin(16, | ||
| + | // Print Temperature label to the LCD | ||
| + | | ||
| + | | ||
| + | // Print the Humidity label to the LCD | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | // for debugging | ||
| + | Serial.begin(115200); | ||
| + | // Use software serial | ||
| + | mySerial.begin(9600); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | == Step 4 == | ||
| + | |||
| + | Implement loop() to sample and display the values of the temperature, | ||
| + | | ||
| + | <code c> | ||
| + | void loop() { | ||
| + | float h = dht.readHumidity(); | ||
| + | // read temperature in Celsius | ||
| + | float t = dht.readTemperature(); | ||
| + | // compute heat index in Celsius (isFahreheit = false); | ||
| + | float hic = dht.computeHeatIndex(t, | ||
| + | // in Fahrenheit | ||
| + | // | ||
| + | // | ||
| + | |||
| + | // print Temperature value to the LCD | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | // print the Humidity value to the LCD | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | int chksum=0; | ||
| + | byte pms[32]={0, | ||
| + | if(mySerial.available()> | ||
| + | for(int j=0; j<32 ; j++){ | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | if(pms[30] != (byte)(chksum>> | ||
| + | || pms[31] != (byte)(chksum) ){ | ||
| + | } | ||
| + | } | ||
| + | delay(1000); | ||
| + | lcd.setCursor(5, | ||
| + | lcd.print(pms[14]); | ||
| + | lcd.print(" | ||
| + | lcd.print(pms[15]); | ||
| + | lcd.print(" | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Result validation === | ||
| + | |||
| + | Observe the temperature, | ||
| + | |||
| + | === Platformio.ini === | ||
| + | < | ||
| + | [env:uno] | ||
| + | platform = atmelavr | ||
| + | board = uno | ||
| + | framework = arduino | ||
| + | |||
| + | lib_ldf_mode=deep+ | ||
| + | lib_compat_mode=strict | ||
| + | |||
| + | lib_deps = | ||
| + | DHT sensor library@1.3.0 | ||
| + | | ||
| + | |||
| + | lib_deps_external = | ||
| + | | ||
| + | </ | ||
| + | |||
| + | === IU1.cpp === | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include " | ||
| + | #define DHTPIN 8 | ||
| + | |||
| + | #define DHTTYPE DHT22 | ||
| + | DHT dht(DHTPIN, DHTTYPE); | ||
| + | LiquidCrystal lcd(7, 6, 5, 4, 13, 2); | ||
| + | |||
| + | SoftwareSerial mySerial(9, | ||
| + | |||
| + | void setup() { | ||
| + | | ||
| + | // Print Temperature label to the LCD | ||
| + | | ||
| + | | ||
| + | // Print the Humidity label to the LCD | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | // for debuging | ||
| + | | ||
| + | |||
| + | // Use software serial | ||
| + | | ||
| + | } | ||
| + | void loop() { | ||
| + | float h = dht.readHumidity(); | ||
| + | // read temperature as Celsius | ||
| + | float t = dht.readTemperature(); | ||
| + | // read temperature as Fahrenheit | ||
| + | // float f = dht.readTemperature(true); | ||
| + | // compute heat index in Fahrenheit (the default) | ||
| + | // float hif = dht.computeHeatIndex(f, | ||
| + | // compute heat index in Celsius (isFahreheit = false); | ||
| + | float hic = dht.computeHeatIndex(t, | ||
| + | |||
| + | // print Temperature value to the LCD | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | // print the Humidity value to the LCD | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | int chksum=0; | ||
| + | byte pms[32]={0, | ||
| + | |||
| + | | ||
| + | for(int j=0; j<32 ; j++){ | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | if(pms[30] != (byte)(chksum>> | ||
| + | || pms[31] != (byte)(chksum) ){ | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||