Hi experts,
I've done quite a bit of reading and googling, but need some support to figure out how to get my DS18B20 temp sensor reading to send via SMS on the GPRS Shield. I have already ran successful sketches to view the temperature readings through the Serial monitor, send an SMS with random text, and send an SMS with just the temperature reading. Now I am looking to combine them into one sketch.
This is my configuration:
- Arduino Leonardo (currently using an UNO, but want to use the Leonardo I have here
- Seeed Studio GPRS Shield V2.0, with unlocked SIM
- Dallas/Maxim DS18B20
- Connected via breadboard
The GPRS Shield is not pictured here, but it is on top of the Arduino, and the jumpers going into the headers on that.
What I would like the code to do is the following:
- Send an SMS that says "The temp is currently " and insert the reading after that (see textForSMS below)
- Perform this at an interval of every 5 minutes
I know that the string stuff associated with this line "textForSMS = textForSMS + (currentTemp)" in the code below is incorrect, but I can not quite figure out how to fix it.
/*Demo for GPRS Shield to send SMS message
The microcontrollers Digital Pin 7 and hence allow unhindered communication with GPRS Shield using SoftSerial Library.
IDE: Arduino 1.0 or later */
#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, be careful need to add a country code before the cellphone number
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());
}
I am buried in tabs in Firefox of projects that are slightly different and don't quite answer the questions above through digging through the code. Any ideas here? I want to be able to build this with some students in a STEM workshop next week so we would really appreciate any pointers.
Thanks!