#include <Servo.h>
const int PIR_Sensor = 8;
Servo doorservo;
int ldr = A0;
int tmp = A1;
int d;
int const trigPin = 7;
int const echoPin = 6;
void setup()
{
Serial.begin(9600);
pinMode(ldr,INPUT);
pinMode(tmp,INPUT);
pinMode(11,OUTPUT);
doorservo.attach(10);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop()
{
int ldrs = analogRead(ldr); //LDR & Bulb part
if(ldrs < 300)
{
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
}
else
{
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}
int reading = analogRead(tmp); //TMP & buzzer part
float voltage = reading * 5.0;
voltage /= 1024.0;
float temperatureC = (voltage - 0.5) * 100 ;
if(temperatureC >= 30)
{
digitalWrite(11,HIGH);
}
else
{
digitalWrite(11,LOW);
}
int duration, distance; //Distance sensor & Mic servo motor part
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
d = digitalRead (7);
if (distance <= 60 && distance >= 0) {
doorservo.write(100);
} else {
doorservo.write(0);
}
delay(60);
if (digitalRead(PIR_Sensor)==HIGH) //PIR sensor & Red Led
{digitalWrite(5, HIGH);}
else {digitalWrite(5, LOW);}
}