Hi,
blocks image uploaded , arduino code also
arduino code
#include <LiquidCrystal.h>
#include <dht.h>
dht DHT;
String text;
String value;
int var;
int i;
// rs,e,d4,d5,d6,d7
//LiquidCrystal lcd(22, 23, 24, 25, 26, 27); // Assigning arduino pins to LCD display module
LiquidCrystal lcd(10, 9, 7, 6, 5, 4);
int greenLED = 11; //2
int redLED = 12; //3
int gasPin1 = A0;
int pirPin1 = A1; //36
int tempPin1 = A2; //A8
int ldrPin1 = A3;
int speakerPin = 13; //10
int relayPin = A5;
int testPin = 8;
int zone = 0;
int alarmActive = 0;
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(speakerPin, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(testPin, OUTPUT);
pinMode(pirPin1, INPUT); //Motion
pinMode(gasPin1, INPUT); //Gas
pinMode(ldrPin1, INPUT); //LDR
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
digitalWrite(speakerPin, LOW);
lcd.print(" Warrming up ");
//delay(20000);
delay(100);
lcd.clear();
lcd.print(" Welcome AAST ");
delay(100);
}
void loop(){
alarmActive = 1;
readstatus();
Serial.flush();
checksensor();
readtemp();
//sendstatus();
}
///////////////////////// Functions /////////////////////////////////
void readtemp() // Read Tempreature
{
lcd.clear();
int chk = DHT.read11(tempPin1);
value = (String) DHT.temperature + "C" + "," + (String) DHT.humidity + "%" + "," + (String) digitalRead(relayPin);
Serial.println(value);
lcd.setCursor(0,0);
lcd.print("Temp : ");
lcd.setCursor(10,0);
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(DHT.humidity);
lcd.print("%");
delay(1500);
}
void alarmTriggered(){
//alarmActive = 1;
digitalWrite(speakerPin, HIGH);
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
lcd.clear(); //asm
lcd.print("SYSTEM TRIGGERED");
//lcd.setCursor(0,3);
//lcd.print(" ");
if (zone == 0) {
lcd.setCursor(0,1);
lcd.print("Motion Detected");
delay(500);
lcd.clear();
delay(500);
}
if (zone == 5) {
lcd.setCursor(0,1);
lcd.print("Light Detected");
delay(500);
lcd.clear();
delay(500);
}
else if (zone == 4){
lcd.setCursor(0,1);
lcd.print("Gas Detected");
delay(500);
}
digitalWrite(speakerPin, LOW);
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
}
void checksensor(){
if (alarmActive == 1)
{
if (digitalRead(pirPin1) == HIGH)
{
zone = 0;
alarmTriggered();
}
if (digitalRead(gasPin1) == HIGH)
{
zone = 4;
alarmTriggered();
}
if (digitalRead(ldrPin1) == LOW)
{
zone = 5;
alarmTriggered();
}
}
else
//Serial.println("readtemp");
readtemp();
}
void readstatus()
{while (Serial.available())
{ delay(100);
char c = Serial.read();
text += c;
}
if (text.length() > 0)
{
//Serial.print(text);
if (text == "1")
{
digitalWrite(relayPin, HIGH);
}
if (text == "0")
{
digitalWrite(relayPin, LOW);
}
if (text == "query")
{
digitalWrite(testPin, LOW);
}
text = "";
}
}
void sendstatus(){
//var = 0;
//while ( var < 200)
while(Serial.available())
{ value = (String) DHT.temperature + "C" + "," + (String) DHT.humidity + "%" + "," + (String) digitalRead(relayPin);
Serial.println(value);
delay(1500);
//var++;
}
}
void sendstatus1(){
for (int i=0; i<10; i++)
Serial.println(value);
}