Advertisement
learnelectronics

Modular Arduino Prototyping

Mar 30th, 2020
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.39 KB | None | 0 0
  1. //**********************************************************//
  2. //*                                                        *//
  3. //*                   Lotus board &                        *//
  4. //*                 Grove Sensor Demo                      *//
  5. //*                                                        *//
  6. //*                by learnelectronics                     *//
  7. //*                   30 MAR 2020                          *//
  8. //*           www.youtube.com/learnelectronics             *//
  9. //*             email: arduino0169@gmail.com               *//
  10. //*                                                        *//
  11. //**********************************************************//
  12.  
  13.  
  14.  
  15. #include <DHT.h>                                                        //add DHT sensor library
  16. #include <rgb_lcd.h>                                                    //add LCD library
  17. #define DHTPIN 2                                                        //set digital pin2 as DHTPIN
  18. #define DHTTYPE DHT11                                                   //set the sensor type as DHT 11
  19.  
  20. DHT dht(DHTPIN, DHTTYPE);                                               //assign dht as the name of DHT sensor, set the sensor pin as DHTPIN(pin2),set the sensor type as DHTTYPE(DHT11)
  21.  
  22. rgb_lcd lcd;                                                            //assign lcd as the name of rgb_lcd screen
  23.  
  24. void setup() {
  25.  
  26.   dht.begin();                                                          //initialise the dht sensor
  27.   lcd.begin(16, 2);                                                     //initialise the lcd screen; set up the lcd's number of columns and rows:
  28.   delay(2000);                                                          //wait for 2s
  29. }
  30.  
  31. void loop() {
  32.  
  33.   int h = dht.readHumidity();                                           //store the humidity value to h
  34.   int t = dht.readTemperature();                                        //store the temperature value to t(in Celsius)
  35.  
  36.   lcd.setCursor(0, 0);                                                  //set the LCD cursor to column 0, line 0
  37.   lcd.print("Temperature:");                                            //Print text temperature: to the LCD
  38.   lcd.setCursor(12, 0);                                                 //set the LCD cursor to column 12, line 0
  39.   lcd.print(t);                                                         //Print temperature value t to the LCD
  40.   lcd.setCursor(14, 0);                                                 //set the LCD cursor to column 14, line 0
  41.   lcd.write(223);                                                       //Print temperature º is character 223 on lookup table
  42.   lcd.print("C");                                                       //Print C to the LCD
  43.   lcd.setCursor(0, 1);                                                  //set the LCD cursor to column 0, line 1
  44.   lcd.print("Humidity: ");                                              //Print text Humidity: to the LCD
  45.   lcd.setCursor(10, 1);                                                 //set the LCD cursor to column 10, line 1
  46.   lcd.print(h);                                                         //Print humidity value h to the LCD
  47.   lcd.setCursor(12, 1);                                                 //set the LCD cursor to column 12, line 1
  48.   lcd.print("%");                                                       //Print sign % to the LCD
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement