Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Servo.h>
- #include "DHT.h"
- #define DHTPIN 2
- #define DHTTYPE DHT11
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- DHT dht(DHTPIN, DHTTYPE);
- Servo myservo;
- int maxAngl = 60;
- float setTemp = 24.00;
- int flag = 0;
- int oflag = 0;
- void setup() {
- Serial.begin(9600);
- lcd.init();
- lcd.init();
- lcd.backlight();
- myservo.attach(5);
- dht.begin();
- }
- void loop() {
- float t = dht.readTemperature();
- Serial.println(t);
- lcd.setCursor(0, 0);
- lcd.print("Temp: ");
- lcd.print(t);
- lcd.print(" 'C");
- if (t > setTemp) {
- if (oflag == 0) {
- openWindow();
- delay(5000);
- oflag = 1;
- }
- else {
- myservo.write(maxAngl);
- }
- lcd.setCursor(0, 1);
- lcd.print("Window is OPEN");
- flag = 1;
- }
- else if (t <= setTemp) {
- if (flag == 1) {
- closeWindow();
- delay(5000);
- flag = 0;
- oflag = 0;
- }
- else {
- myservo.write(0);
- }
- lcd.setCursor(0, 1);
- lcd.print("Window is CLOSED");
- }
- }//end of Loop
- void openWindow() {
- for (int i = 0; i <= maxAngl; i++) {
- myservo.write(i);
- delay(50);
- }
- }
- void closeWindow() {
- for (int j = maxAngl; j >= 0; j--) {
- myservo.write(j);
- delay(50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement