Skip to content

Instantly share code, notes, and snippets.

@axayjha
Created July 22, 2021 21:32
Show Gist options
  • Save axayjha/bcb50b0ef04bfdec1211c6654fbe9350 to your computer and use it in GitHub Desktop.
Save axayjha/bcb50b0ef04bfdec1211c6654fbe9350 to your computer and use it in GitHub Desktop.
#include <Servo.h>
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 2
int threshold;
int ac=3;
int curtain=5;
Servo myservo;
#define DHTTYPE DHT11
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,4,5,6,7);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// set up the LCD's number of columns and rows:
myservo.attach(curtain);
myservo.write(90);
Serial.begin(9600);
dht.begin();
lcd.begin(16, 2);
pinMode(ac,INPUT);
// Print a message to the LCD.
lcd.print("Getting data...");
delay(2000);
}
void loop() {
lcd.clear();
lcd.print("Loading.... ");
delay(100);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
int h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
lcd.setCursor(0, 0);
/* if (isnan(h) || isnan(t) || isnan(f)) {
lcd.clear();
lcd.print("Failed!");
return;
}*/
if(t>30)
{
onAc();
}
else
{
offAc();
}
lcd.print("Temp = ");
lcd.print(t);
lcd.print(" *C");
lcd.setCursor(0, 1);
lcd.print("Humidity = ");
lcd.print(h);
lcd.print(" %");
delay(2000);
// print the number of seconds since reset:
}
void onAc()
{
digitalWrite(ac,HIGH);
delay(500);
digitalWrite(ac,LOW);
delay(500);
digitalWrite(ac,HIGH);
delay(500);
digitalWrite(ac,LOW);
delay(500);
digitalWrite(ac,HIGH);
delay(500);
}
void offAc()
{
digitalWrite(ac,LOW);
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment