通过SMS发送传感器读数

时间:2014-10-27 02:48:05

标签: arduino at-command gprs arduino-uno

有关1线温度传感器DS18B20和SIM900 GPRS Shield的简单问题

我已经完成了相当多的阅读和谷歌搜索,但需要一些支持来弄清楚如何让我的DS18B20温度传感器读取通过GPRS屏蔽上的短信发送。我已经运行了成功的草图,通过串行监视器查看温度读数,发送带随机文本的短信,并发送短信 温度读数。现在我希望将它们组合成一个草图。

这是我的配置:

  • Arduino Leonardo(目前正在使用UNO,但想使用我在这里的Leonardo
  • Seeed Studio GPRS Shield V2.0,带解锁SIM卡
  • Dallas / Maxim DS18B20
  • 通过面包板连接

图片在这里:http://i.stack.imgur.com/9YdyW.png 这里没有图示GPRS Shield,但是它位于Arduino的顶部,并且跳线进入了标题。

我希望代码的作用如下:

  1. 发送一条短信,上面写着"临时状态"然后插入读数(参见下面的textForSMS)
  2. 每隔5分钟执行一次
  3. 我知道与此行相关的字符串内容" textForSMS = textForSMS +(currentTemp)"在下面的代码中是不正确的,但我不知道如何解决它。

    #include <SoftwareSerial.h>
    #include <String.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    String textForSMS;
    float currentTemp;
    
    SoftwareSerial cellSerial(7,8);
    
    #define ONE_WIRE_BUS 2
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    
    void setup()
    {
    cellSerial.begin(19200); // the GPRS baud rate  
    Serial.begin(9600); // temp sensor rate
    delay(500);
    sensors.begin();
    }
    
    ///SendTextMessage()
    ///this function is to send a sms message
    void SendTextMessage(String message)
    {
    cellSerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
    delay(100);
    cellSerial.println("AT + CMGS = \"+1XXXXXX4470\"");//send sms message, 
    delay(100);
    cellSerial.println(message);//the content of the message
    delay(100);
    cellSerial.println((char)26);//the ASCII code of the ctrl+z is 26
    delay(100);
    cellSerial.println();
    }
    
    void loop()
    {
    currentTemp = sensors.getTempCByIndex(0);
    textForSMS = "Temp is ";
    Serial.println(currentTemp);
    textForSMS = textForSMS + (currentTemp)
    SendTextMessage(textForSMS);
    do {} while (1);
    }
    
    void ShowSerialData()
    {
    while(cellSerial.available()!=0)
    Serial.write(cellSerial.read());
    }
    

    我被隐藏在Firefox中的项目中,这些项目略有不同,并且通过挖掘代码并没有完全回答上述问题。这里有什么想法?我希望能够在下周的STEM研讨会上与一些学生建立这个,所以我们真的很感激任何指针。

    谢谢!

0 个答案:

没有答案
相关问题