#include <Servo.h>
int buttonpin= 7;
int relaypin = 4;
int last_state= HIGH;
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 11
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,20,4);
Servo myservo; // Create Servo object to control servo
// 12 servo objects can be created on most boards
long pos = 0; //var to store servo position
void setup(){
pinMode(DHTPIN,INPUT);
lcd.init();
lcd.backlight();
dht.begin();
Serial.begin(115200);
pinMode(buttonpin, INPUT_PULLUP);
pinMode(relaypin, OUTPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
lcd.setCursor(1,0);
int value=digitalRead(buttonpin);
if(last_state!=value){
last_state=value;
if(value==HIGH){
digitalWrite(relaypin,LOW);
lcd.print("released");
for(pos=0;pos<=180;pos+=1){
myservo.write(pos);
delay(15);
}
for(pos=180;pos>=0;pos-=1){
myservo.write(pos);
delay(15);
}
}
else{
digitalWrite(relaypin,HIGH);
lcd.print("pressed");
}
}
}