#include <SoftwareSerial.h>
#include <DHT.h>
#define DHTTYPE DHT22
const int smoke=A5;
const int tem=2;
const int red=3;
const int button=4;
const int fan=12;
const int led=13;
int R;
unsigned char R1=0;
DHT dht(tem, DHTTYPE);
void setup() {
Serial.begin(9600);
pinMode(smoke,INPUT);
pinMode(tem,INPUT);
pinMode(red,INPUT);
pinMode(button,INPUT);
pinMode(fan,OUTPUT);
pinMode(led,OUTPUT);
dht.begin();
}
void loop() {
R=digitalRead(red);
int a = analogRead(smoke);
int b = dht.readHumidity();
int c = dht.readTemperature();
int d = dht.readTemperature(true);
byte Data[13];
Data[0]=97;
Data[1]=a/256;
Data[2]=a%256;
Data[3]='b';
Data[4]=b/256;
Data[5]=b%256;
Data[6]='c';
Data[7]=c/256;
Data[8]=c%256;
Data[9]='d';
Data[10]=d/256;
Data[11]=d%256;
if(R == HIGH){
Data[12]='e';
}
if(R==LOW){
Data[12]='f';
}
if (Serial.available() > 0) {
char val = Serial.read();
switch (val) {
case 1:
for (int i = 0 ; i < 13 ; i++)
Serial.write(Data[i]);
delay(100);
break;
case 2:
digitalWrite(fan, HIGH);
break;
case 3:
digitalWrite(fan, LOW);
break;
}
}
if(R1){
if(R == LOW){
R1=0;
digitalWrite(led,LOW);
}
}
else{
if(R==HIGH){
R1=1;
digitalWrite(led,HIGH);
}
}
if(digitalRead(button) == HIGH){
if(digitalRead(led) == HIGH){
digitalWrite(led, LOW);
delay(500);
}
else{
digitalWrite(led, HIGH);
delay(500);
}
}
} |