Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**********************************************************//
- //* *//
- //* Lotus board & *//
- //* Grove Sensor Temp Cntrl Relay *//
- //* *//
- //* by learnelectronics *//
- //* 7 APR 2020 *//
- //* www.youtube.com/learnelectronics *//
- //* email: arduino0169@gmail.com *//
- //* *//
- //**********************************************************//
- #include <DHT.h> //add DHT sensor library
- #include <rgb_lcd.h> //add LCD library
- #define DHTPIN 2 //set digital pin2 as DHTPIN
- #define DHTTYPE DHT11 //set the sensor type as DHT 11
- 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)
- rgb_lcd lcd; //assign lcd as the name of rgb_lcd screen
- int myvar = 24; //Initial temp setting for relay
- void setup() {
- dht.begin(); //initialise the dht sensor
- lcd.begin(16, 2); //initialise the lcd screen; set up the lcd's number of columns and rows:
- pinMode(6,INPUT);
- pinMode(7,INPUT);
- pinMode(3,OUTPUT);
- Serial.begin(9600); //start serial comms for debugging
- digitalWrite(3,LOW);
- delay(2000); //wait for 2s
- }
- void loop() {
- int h = dht.readHumidity(); //store the humidity value to h
- int t = dht.readTemperature(); //store the temperature value to t(in Celsius)
- lcd.setCursor(0, 0); //set the LCD cursor to column 0, line 0
- lcd.print("Temp:"); //Print text temperature: to the LCD
- lcd.setCursor(6, 0); //set the LCD cursor to column 12, line 0
- lcd.print(t); //Print temperature value t to the LCD
- lcd.write(223); //Print temperature º is character 223 on lookup table
- lcd.print(" Set:");
- lcd.print(myvar);
- lcd.setCursor(0, 1); //set the LCD cursor to column 0, line 1
- lcd.print("Hmdty: "); //Print text Humidity: to the LCD
- lcd.setCursor(7, 1); //set the LCD cursor to column 10, line 1
- lcd.print(h); //Print humidity value h to the LCD
- lcd.print("%"); //Print sign % to the LCD
- if (t>myvar){
- lcd.print(" ON ");
- digitalWrite(3,HIGH);
- }
- if (t<myvar){
- lcd.print(" OFF");
- digitalWrite(3,LOW);
- }
- delay(500);
- digitalRead(6);
- digitalRead(7);
- if (digitalRead(6)==0) myvar=myvar-1;
- if (digitalRead(7)==0) myvar=myvar+1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement