Advertisement
safwan092

Untitled

Dec 11th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Servo.h>
  4. #include "DHT.h"
  5.  
  6. #define DHTPIN 2
  7. #define DHTTYPE DHT11
  8.  
  9. LiquidCrystal_I2C lcd(0x27, 16, 2);
  10. DHT dht(DHTPIN, DHTTYPE);
  11. Servo myservo;
  12. int maxAngl = 60;
  13. float setTemp = 24.00;
  14. int flag = 0;
  15. int oflag = 0;
  16.  
  17. void setup() {
  18. Serial.begin(9600);
  19. lcd.init();
  20. lcd.init();
  21. lcd.backlight();
  22. myservo.attach(5);
  23. dht.begin();
  24. }
  25.  
  26. void loop() {
  27. float t = dht.readTemperature();
  28. Serial.println(t);
  29. lcd.setCursor(0, 0);
  30. lcd.print("Temp: ");
  31. lcd.print(t);
  32. lcd.print(" 'C");
  33. if (t > setTemp) {
  34. if (oflag == 0) {
  35. openWindow();
  36. delay(5000);
  37. oflag = 1;
  38. }
  39. else {
  40. myservo.write(maxAngl);
  41. }
  42. lcd.setCursor(0, 1);
  43. lcd.print("Window is OPEN");
  44. flag = 1;
  45. }
  46. else if (t <= setTemp) {
  47.  
  48. if (flag == 1) {
  49. closeWindow();
  50. delay(5000);
  51. flag = 0;
  52. oflag = 0;
  53. }
  54. else {
  55. myservo.write(0);
  56. }
  57. lcd.setCursor(0, 1);
  58. lcd.print("Window is CLOSED");
  59. }
  60.  
  61. }//end of Loop
  62.  
  63. void openWindow() {
  64. for (int i = 0; i <= maxAngl; i++) {
  65. myservo.write(i);
  66. delay(50);
  67. }
  68. }
  69.  
  70. void closeWindow() {
  71. for (int j = maxAngl; j >= 0; j--) {
  72. myservo.write(j);
  73. delay(50);
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement