//Comments to MCU
//DHT22 Pin2>D2
//LDR AO>A0
//PIR PO>P3
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define LDRPIN A0
#define PIRPIN 3
DHT dht(DHTPIN,DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
dht.begin();
pinMode(LDRPIN, INPUT);
pinMode(PIRPIN, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
float t = dht.readTemperature();
float h = dht.readHumidity();
int LightLevel = analogRead(LDRPIN);
int motion = digitalRead(PIRPIN);
//Condition for temperature
if (t < 20)
{
Serial.print("Warning: Low Temperature");
Serial.print(" | ");
}
else if(t > 35)
{
Serial.print("Warning: High Temperature");
Serial.print(" | ");
}
else
{
Serial.print("Normal Temperature");
Serial.print(" | ");
}
//Condition for humidity
if (h < 30)
{
Serial.print("Warning: Low Humidity");
Serial.print(" | ");
}
else if(h > 78)
{
Serial.print("Warning: High Humidity");
Serial.print(" | ");
}
else
{
Serial.print("Normal Humidity");
Serial.print(" | ");
}
//Condition for Light Level
if (LightLevel < 390)
{
Serial.print("Warning: Low Light");
Serial.print(" | ");
}
else if (LightLevel >168)
{
Serial.print("Warning: High Light");
Serial.print(" | ");
}
else
{
Serial.print("Normal Light");
Serial.print(" | ");
}
//Condition for Motion
if (motion == HIGH)
{
Serial.print("Warning: Motion Detected!");
Serial.print(" | ");
}
else
{
Serial.print("No Motion Detected");
}
//Serial.print(motion);
Serial.println();("");
delay(2000);
}