Advertisement
learnelectronics

Relay control w/ grove sensors

Apr 7th, 2020
2,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.75 KB | None | 0 0
  1. //**********************************************************//
  2. //*                                                        *//
  3. //*                   Lotus board &                        *//
  4. //*            Grove Sensor Temp Cntrl Relay               *//
  5. //*                                                        *//
  6. //*                by learnelectronics                     *//
  7. //*                    7 APR 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.  int myvar = 24;                                                        //Initial temp setting for relay
  24.  
  25. void setup() {
  26.  
  27.   dht.begin();                                                          //initialise the dht sensor
  28.   lcd.begin(16, 2);                                                     //initialise the lcd screen; set up the lcd's number of columns and rows:
  29.   pinMode(6,INPUT);
  30.   pinMode(7,INPUT);
  31.   pinMode(3,OUTPUT);
  32.   Serial.begin(9600);                                                   //start serial comms for debugging
  33.   digitalWrite(3,LOW);
  34.   delay(2000);                                                          //wait for 2s
  35. }
  36.  
  37. void loop() {
  38.  
  39.   int h = dht.readHumidity();                                           //store the humidity value to h
  40.   int t = dht.readTemperature();                                        //store the temperature value to t(in Celsius)
  41.  
  42.  
  43.  
  44.   lcd.setCursor(0, 0);                                                  //set the LCD cursor to column 0, line 0
  45.   lcd.print("Temp:");                                                   //Print text temperature: to the LCD
  46.   lcd.setCursor(6, 0);                                                 //set the LCD cursor to column 12, line 0
  47.   lcd.print(t);                                                         //Print temperature value t to the LCD
  48.   lcd.write(223);                                                       //Print temperature º is character 223 on lookup table
  49.   lcd.print(" Set:");
  50.   lcd.print(myvar);                                                      
  51.   lcd.setCursor(0, 1);                                                  //set the LCD cursor to column 0, line 1
  52.   lcd.print("Hmdty: ");                                                //Print text Humidity: to the LCD
  53.   lcd.setCursor(7, 1);                                                 //set the LCD cursor to column 10, line 1
  54.   lcd.print(h);                                                         //Print humidity value h to the LCD
  55.   lcd.print("%");                                                       //Print sign % to the LCD
  56.  
  57.   if (t>myvar){
  58.   lcd.print("   ON ");
  59.   digitalWrite(3,HIGH);
  60.   }
  61.   if (t<myvar){
  62.     lcd.print("   OFF");
  63.     digitalWrite(3,LOW);
  64.   }
  65.   delay(500);
  66.   digitalRead(6);
  67.   digitalRead(7);
  68.   if (digitalRead(6)==0) myvar=myvar-1;
  69.   if (digitalRead(7)==0) myvar=myvar+1;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement