之前做了一个利用LCD屏监视植物土壤湿度和周围环境温度和湿度的小作品,昨晚修改了一下添加了当泥土湿度过高或者过低的时候 Arduino会发信息到预设好的手机提醒状况。基本上都是上次的配件,加上DFRobot的TEL0051模块。 PS:不知道是其他问题,还是IDE的问题,还是GSM模块的问题发不了还有中文字的信息,希望前辈可以帮忙看看有没有办法修改一下。 代码如下:
- //sensor pin A0, SCL AREF-2, SDA AREF-1; Sensor 3V, LCD 5V
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <dht11.h>
- #define DHT11PIN A1
- dht11 DHT11;
- LiquidCrystal_I2C lcd(0x27, 24,3);
- int sensorPin = A2; // select the input pin for the potentiometer
- int sensorValue = 0; // variable to store the value coming from the sensor
- int counter=0;
- int sentSMSCounter=0;
- String num="AT+CMGS="***********"";
- void setup() {
- // declare the ledPin as an OUTPUT:
- //Serial.begin(9600);
- //--------------------------------------
- //端口模式设置
- pinMode(3,OUTPUT);
- pinMode(4,OUTPUT);
- pinMode(5,OUTPUT);
- //GSM开机时序
- digitalWrite(5,HIGH);
- delay(1500);
- digitalWrite(5,LOW);
-
- //使能GSM串口
- digitalWrite(3,LOW);
- digitalWrite(4,HIGH);
- delay(2000);
- //设置波特率
- Serial.begin(9600);
- //等待call ready
- delay(5000);
- delay(5000);
- delay(5000);
- //--------------------------------------
- }
- double dewPoint(double celsius, double humidity){
- double A0= 373.15/(273.15 + celsius);
- double SUM = -7.90298 * (A0-1);
- SUM += 5.02808 * log10(A0);
- SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
- SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
- SUM += log10(1013.246);
- double VP = pow(10, SUM-3) * humidity;
- double T = log(VP/0.61078); // temp var
- return (241.88 * T) / (17.558-T);
- }
- double dewPointFast(double celsius, double humidity){
- double a = 17.271;
- double b = 237.7;
- double temp = (a * celsius) / (b + celsius) + log(humidity/100);
- double Td = (b * temp) / (a - temp);
- return Td;
- }
- int backlightState = LOW;
- void loop() {
- backlightState = HIGH;
- int chk = DHT11.read(DHT11PIN);
- lcd.init(); // initialize the lcd
- lcd.backlight();
- lcd.home();
- lcd.setCursor(0, 0);
- // read the value from the sensor:
- sensorValue = analogRead(sensorPin);
- Serial.print("sensor = " );
- Serial.println(sensorValue);
-
- if(sensorValue<100){
- Serial.println("Dry Soil really need water");
- lcd.println("Dry Soil need water");
- lcd.setCursor(0, 1);
- lcd.print("Hum(%):");
- lcd.print((float)DHT11.humidity, 0);
- lcd.setCursor(0, 2);
- lcd.print("temp:");
- lcd.print((float)DHT11.temperature,0);//2 means 2 digi
- lcd.setCursor(0, 3);
- //lcd.println(counter);
- //----------------------------------------
- //发送AT命令同步
- Serial.println("AT");
- delay(2000);
- Serial.println("AT");
- delay(2000);
-
- //发送短信
- Serial.println("AT+CMGF=1");
- delay(1000);
- Serial.println(num)
- delay(1000);
- Serial.print("Dry Soil really need water! ");
- Serial.print("Hum(%):");
- Serial.print((float)DHT11.humidity, 0);
- Serial.print(" Temp:");
- Serial.print((float)DHT11.temperature,0);
- //Serial.print(" 请处理");
- delay(11000);
- Serial.write(26);
-
- while(1);
- sentSMSCounter++;
- if(sentSMSCounter=3){
- delay(30000);
- }
- if(sentSMSCounter>3){
- num="give up!";
- delay(100000);
- }
-
- //----------------------------------------
- }
- if(sensorValue<=600&&sensorValue>=100){
- Serial.println("Humid Soil Plants feeling good!");
- lcd.println("Humid Soil feeling good");
- lcd.setCursor(0, 1);
- lcd.print("Hum(%):");
- lcd.print((float)DHT11.humidity, 0);
- lcd.setCursor(0, 2);
- lcd.print("temp:");
- lcd.print((float)DHT11.temperature,0);//2 means 2 digi
- lcd.setCursor(0, 3);
- //lcd.println(counter);
- }
- if(sensorValue>600){
- Serial.println("Stop Too much water!!");
- lcd.println("Stop Too much water");
- lcd.setCursor(0, 1);
- lcd.print("Hum(%):");
- lcd.print((float)DHT11.humidity, 0);
- lcd.setCursor(0, 2);
- lcd.print("temp:");
- lcd.print((float)DHT11.temperature,0);//2 means 2 digi
- lcd.setCursor(0, 3);
- //lcd.println(counter);
- //----------------------------------------
- //发送AT命令同步
- Serial.println("AT");
- delay(2000);
- Serial.println("AT");
- delay(2000);
-
- //发送短信
- Serial.println("AT+CMGF=1");
- delay(1000);
- Serial.println(num)
- delay(1000);
- Serial.print("Too much water! ");
- Serial.print("Hum(%):");
- Serial.print((float)DHT11.humidity, 0);
- Serial.print(" Temp:");
- Serial.print((float)DHT11.temperature,0);
- //Serial.print(" 请处理");
- delay(11000);
- Serial.write(26);
-
- while(1);
- sentSMSCounter++;
- if(sentSMSCounter=3){
- delay(30000);
- }
- if(sentSMSCounter>3){
- num="give up!";
- delay(100000);
- }
-
- //----------------------------------------
- }
- counter++;
- delay(1000);
- }
复制代码
|
|
|
|
|
|