7777浏览
查看: 7777|回复: 0

[项目] 作品1 2.0 添加短信通知功能

[复制链接]
之前做了一个利用LCD屏监视植物土壤湿度和周围环境温度和湿度的小作品,昨晚修改了一下添加了当泥土湿度过高或者过低的时候Arduino会发信息到预设好的手机提醒状况。基本上都是上次的配件,加上DFRobot的TEL0051模块。
PS:不知道是其他问题,还是IDE的问题,还是GSM模块的问题发不了还有中文字的信息,希望前辈可以帮忙看看有没有办法修改一下。
作品1 2.0 添加短信通知功能图9
作品1 2.0 添加短信通知功能图8
作品1 2.0 添加短信通知功能图7
作品1 2.0 添加短信通知功能图6
作品1 2.0 添加短信通知功能图5
作品1 2.0 添加短信通知功能图4
作品1 2.0 添加短信通知功能图3
作品1 2.0 添加短信通知功能图2
作品1 2.0 添加短信通知功能图1
代码如下:


  1. //sensor pin A0, SCL AREF-2, SDA AREF-1; Sensor 3V, LCD 5V
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. #include <dht11.h>
  5. #define DHT11PIN A1
  6. dht11 DHT11;
  7. LiquidCrystal_I2C lcd(0x27, 24,3);
  8. int sensorPin = A2;    // select the input pin for the potentiometer
  9. int sensorValue = 0;  // variable to store the value coming from the sensor
  10. int counter=0;
  11. int sentSMSCounter=0;
  12. String num="AT+CMGS="***********"";
  13. void setup() {
  14.   // declare the ledPin as an OUTPUT:
  15.    //Serial.begin(9600);  
  16.    //--------------------------------------
  17.     //端口模式设置
  18.     pinMode(3,OUTPUT);
  19.     pinMode(4,OUTPUT);
  20.     pinMode(5,OUTPUT);
  21.     //GSM开机时序
  22.     digitalWrite(5,HIGH);
  23.     delay(1500);
  24.     digitalWrite(5,LOW);  
  25.     //使能GSM串口
  26.     digitalWrite(3,LOW);
  27.     digitalWrite(4,HIGH);
  28.     delay(2000);
  29.     //设置波特率
  30.     Serial.begin(9600);
  31.     //等待call ready
  32.     delay(5000);
  33.     delay(5000);
  34.     delay(5000);
  35.    //--------------------------------------
  36. }
  37. double dewPoint(double celsius, double humidity){
  38.         double A0= 373.15/(273.15 + celsius);
  39.         double SUM = -7.90298 * (A0-1);
  40.         SUM += 5.02808 * log10(A0);
  41.         SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  42.         SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  43.         SUM += log10(1013.246);
  44.         double VP = pow(10, SUM-3) * humidity;
  45.         double T = log(VP/0.61078);   // temp var
  46.         return (241.88 * T) / (17.558-T);
  47. }
  48. double dewPointFast(double celsius, double humidity){
  49.         double a = 17.271;
  50.         double b = 237.7;
  51.         double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  52.         double Td = (b * temp) / (a - temp);
  53.         return Td;
  54. }
  55. int backlightState = LOW;
  56. void loop() {
  57.   backlightState = HIGH;
  58.   int chk = DHT11.read(DHT11PIN);
  59.   lcd.init();                      // initialize the lcd
  60.   lcd.backlight();
  61.   lcd.home();
  62.   lcd.setCursor(0, 0);
  63.   // read the value from the sensor:
  64.   sensorValue = analogRead(sensorPin);   
  65.   Serial.print("sensor = " );   
  66.   Serial.println(sensorValue);   
  67.   if(sensorValue<100){
  68.     Serial.println("Dry Soil really need water");
  69.     lcd.println("Dry Soil need water");
  70.     lcd.setCursor(0, 1);
  71.     lcd.print("Hum(%):");
  72.     lcd.print((float)DHT11.humidity, 0);
  73.     lcd.setCursor(0, 2);
  74.     lcd.print("temp:");
  75.     lcd.print((float)DHT11.temperature,0);//2 means 2 digi
  76.     lcd.setCursor(0, 3);
  77.     //lcd.println(counter);
  78.     //----------------------------------------
  79.         //发送AT命令同步
  80.     Serial.println("AT");   
  81.     delay(2000);
  82.     Serial.println("AT");   
  83.     delay(2000);
  84.     //发送短信
  85.     Serial.println("AT+CMGF=1");
  86.     delay(1000);
  87.     Serial.println(num)
  88.     delay(1000);
  89.     Serial.print("Dry Soil really need water! ");
  90.     Serial.print("Hum(%):");
  91.     Serial.print((float)DHT11.humidity, 0);
  92.     Serial.print(" Temp:");
  93.     Serial.print((float)DHT11.temperature,0);
  94.     //Serial.print(" 请处理");
  95.     delay(11000);
  96.     Serial.write(26);
  97.     while(1);
  98.     sentSMSCounter++;
  99.     if(sentSMSCounter=3){
  100.       delay(30000);
  101.     }
  102.     if(sentSMSCounter>3){
  103.       num="give up!";
  104.       delay(100000);
  105.     }
  106.     //----------------------------------------
  107.   }
  108.   if(sensorValue<=600&&sensorValue>=100){
  109.     Serial.println("Humid Soil Plants feeling good!");
  110.    lcd.println("Humid Soil feeling good");
  111.    lcd.setCursor(0, 1);
  112.        lcd.print("Hum(%):");
  113.     lcd.print((float)DHT11.humidity, 0);
  114.     lcd.setCursor(0, 2);
  115.     lcd.print("temp:");
  116.     lcd.print((float)DHT11.temperature,0);//2 means 2 digi
  117.     lcd.setCursor(0, 3);
  118.    //lcd.println(counter);
  119.   }
  120.   if(sensorValue>600){
  121.     Serial.println("Stop Too much water!!");
  122.     lcd.println("Stop Too much water");
  123.     lcd.setCursor(0, 1);
  124.     lcd.print("Hum(%):");
  125.     lcd.print((float)DHT11.humidity, 0);
  126.     lcd.setCursor(0, 2);
  127.     lcd.print("temp:");
  128.     lcd.print((float)DHT11.temperature,0);//2 means 2 digi
  129.     lcd.setCursor(0, 3);
  130.     //lcd.println(counter);
  131.     //----------------------------------------
  132.         //发送AT命令同步
  133.     Serial.println("AT");   
  134.     delay(2000);
  135.     Serial.println("AT");   
  136.     delay(2000);
  137.     //发送短信
  138.     Serial.println("AT+CMGF=1");
  139.     delay(1000);
  140.     Serial.println(num)
  141.     delay(1000);
  142.     Serial.print("Too much water! ");
  143.     Serial.print("Hum(%):");
  144.     Serial.print((float)DHT11.humidity, 0);
  145.     Serial.print(" Temp:");
  146.     Serial.print((float)DHT11.temperature,0);
  147.     //Serial.print(" 请处理");
  148.     delay(11000);
  149.     Serial.write(26);
  150.     while(1);
  151.     sentSMSCounter++;
  152.     if(sentSMSCounter=3){
  153.       delay(30000);
  154.     }
  155.     if(sentSMSCounter>3){
  156.       num="give up!";
  157.       delay(100000);
  158.     }
  159.     //----------------------------------------
  160.   }
  161.   counter++;
  162. delay(1000);  
  163. }
复制代码



您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail