Sie sind auf Seite 1von 3

#include <dht.

h>
#include <LiquidCrystal.h>
#include <Adafruit_BMP085.h>
#include <SoftwareSerial.h>
#include <Wire.h>

#define RX 10
#define TX 11

char buff[120];
dht DHT;

const int rs = 12, en = 9, d4 = 5, d5 = 4, d6 = 3, d7 = 2;


LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
SoftwareSerial mySerial(RX, TX);
void SendMessage(char *ptr);

char PRESSURESHOW[4];// initializing a character of size 4 for showing the result

#define DHT11_PIN 7

int nRainIn = A1;


int nRainDigitalIn = A0;
int nRainVal;
int countTrueCommand;
int countTimeCommand;
boolean found = false;

boolean bIsRaining = false;


String strRaining;

String AP = "moto"; // CHANGE ME


String PASS = "apple1234"; // CHANGE ME

String API = "VT3OKKEALGESACIP"; // CHANGE ME


String HOST = "api.thingspeak.com";
String PORT = "80";
String field_temp = "field1";
String field_moist = "field2";
String field_humid = "field3";
String field_press = "field4";
String field_rain = "field5";

int buzzer = 8;
int MsgInterval=1; //1min
uint32_t nextSendTime=0;

Adafruit_BMP085 bmp;
void setup() {

Serial.begin(9600);
mySerial.begin(115200);
pinMode(nRainDigitalIn, INPUT);
pinMode(buzzer, OUTPUT);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("BLDE");

if (!bmp.begin())

Serial.println("ERROR");///if there is an error in communication

while (1) {}

}
}

void loop()
{

nRainVal = analogRead(nRainIn);
bIsRaining = !(digitalRead(nRainDigitalIn));

if (bIsRaining) {
strRaining = "Y";
}
else {
strRaining = "N";
}

int chk = DHT.read11(DHT11_PIN);


if ( DHT.temperature > 0)
{
lcd.clear();
lcd.print("T=");
int temp = (int)DHT.temperature;
lcd.print(temp);
lcd.print(" C");

lcd.print(" H=");
lcd.print(DHT.humidity);
lcd.print("%");
lcd.setCursor(0, 1);

lcd.print("P="); // print name

String PRESSUREVALUE = String(bmp.readPressure());

PRESSUREVALUE.toCharArray(PRESSURESHOW, 4);

lcd.print(PRESSURESHOW);

lcd.print("Pa ");

lcd.print("Rain:");
lcd.print(strRaining);
delay(1000);
// buzzer code
if (DHT.humidity > 30) {

digitalWrite(buzzer, 1);
delay(200);
}
else {
digitalWrite(buzzer, 0);
}
}

sprintf(buff,"temp:%d Humidity:%d Rain:%c pressure:%s Mositure:%d",


(int)DHT.temperature,(int)DHT.humidity,((bIsRaining==1)?'Y':'N'),PRESSURESHOW);
Serial.println(buff);

if(millis()>nextSendTime)
{
nextSendTime = millis()+MsgInterval*60000;
SendMessage(buff);
}
}

void SendMessage(char *ptr)


{

mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode


delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"7204099395\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println(ptr);// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
Serial.println("Sending The msg");
}

Das könnte Ihnen auch gefallen