Hi,
I'm new to the forum and have a question. I'm working on a project to send the temperature and humidity via a text message (SMS).
So for this project I broke up the in two sections:
(1) Temperature & Humidity
(2) SMS
(3) Integrating 1 and 2
(1) Temperature & Humidity
For the temperature and humidity I'm using the SHT15 which I got working, below the code to that.
Maybe some one has a few pointers to that, but as stated it is working and I can read the temperature and humidity from the com port.
int temperatureCommand = B00000011; // command used to read temperature
int humidityCommand = B00000101; // command used to read humidity
int clockPin = 8; // pin used for clock
int dataPin = 9; // pin used for data
int ack; // track acknowledgment for errors
int val;
float temperature;
float humidity;
void setup()
{
Serial.begin(9600); // open serial at 9600 bps
}
void loop()
{
// read the temperature and convert it to centigrades
sendCommandSHT(temperatureCommand, dataPin, clockPin);
waitForResultSHT(dataPin);
val = getData16SHT(dataPin, clockPin);
skipCrcSHT(dataPin, clockPin);
temperature = (float)val * 0.01 - 40;
Serial.print("temperature: ");
Serial.print(temperature);
// read the humidity
sendCommandSHT(humidityCommand, dataPin, clockPin);
waitForResultSHT(dataPin);
val = getData16SHT(dataPin, clockPin);
skipCrcSHT(dataPin, clockPin);
humidity = -4.0 + 0.0405 * val + -0.0000028 * val * val;
Serial.print(" humidity: ");
Serial.println(humidity);
delay(1800000); // wait for 200 milliseconds for next reading
}
// commands for reading/sending data to a SHTx sensor
// send a command to the SHTx sensor
void sendCommandSHT(int command, int dataPin, int clockPin)
{
int ack;
// transmission start
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
digitalWrite(dataPin, HIGH);
digitalWrite(clockPin, HIGH);
digitalWrite(dataPin, LOW);
digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(dataPin, HIGH);
digitalWrite(clockPin, LOW);
// shift out the command (the 3 MSB are address and must be 000, the last 5 bits are the command)
shiftOut(dataPin, clockPin, MSBFIRST, command);
// verify we get the right ACK
digitalWrite(clockPin, HIGH);
pinMode(dataPin, INPUT);
ack = digitalRead(dataPin);
if (ack != LOW)
Serial.println("ACK error 0");
digitalWrite(clockPin, LOW);
ack = digitalRead(dataPin);
if (ack != HIGH)
Serial.println("ACK error 1");
}
// wait for the SHTx answer
void waitForResultSHT(int dataPin)
{
int ack;
pinMode(dataPin, INPUT);
for (int i = 0; i < 100; ++i)
{
delay(20);
ack = digitalRead(dataPin);
if (ack == LOW)
break;
}
if (ack == HIGH)
Serial.println("ACK error 2");
}
// get data from the SHTx sensor
int getData16SHT(int dataPin, int clockPin)
{
int val;
// get the MSB (most significant bits)
pinMode(dataPin, INPUT);
pinMode(clockPin, OUTPUT);
val = shiftIn(dataPin, clockPin, MSBFIRST);
val *= 256; // this is equivalent to val << 8;
// send the required ACK
pinMode(dataPin, OUTPUT);
digitalWrite(dataPin, HIGH);
digitalWrite(dataPin, LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
// get the LSB (less significant bits)
pinMode(dataPin, INPUT);
val |= shiftIn(dataPin, clockPin, MSBFIRST);
return val;
}
// skip CRC data from the SHTx sensor
void skipCrcSHT(int dataPin, int clockPin)
{
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
digitalWrite(dataPin, HIGH);
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
(2) SMS
Here is where I'm having trouble. I have the SM5100B shield and connected it to the Arduino Board.
My first question is to look at the picture I have uploaded and have I connected it right?
Secondly and thats why I'm doubting the connection I have tried to send an text message and to check iff the board has an network connection. I found different approaches to on sending an text message on the forum, but none has worked for me so far. I need help.
What I have tried so far on code.
// Serial.println("at+cmgf=1");
// Serial.println("at+cmgs=\"214244****\"");
// Serial.print("This is my message");
// Serial.write(26); // this is ctrl-z
#include <SoftwareSerial.h>
SoftwareSerial cell(2,3); // We need to create a serial port on D2/D3 to talk to the GSM module
char mobilenumber[] = "xxxxxxxxxx"; // Replace xxxxxxxx with the recipient's mobile number
void setup()
{ //Initialize serial ports for communication.
cell.begin(9600);
delay(35000); // give the GSM module time to initialise, locate network etc.
// this delay time varies. Use example 26.1 sketch to measure the amount
// of time from board reset to SIND: 4, then add five seconds just in case
}
void loop()
{
cell.println("AT+CMGF=1"); // set SMS mode to text
cell.print("AT+CMGS="); // now send message...
cell.print(34); // ASCII equivalent of "
cell.print(mobilenumber);
cell.println(34); // ASCII equivalent of "
delay(500); // give the module some thinking time
cell.print("They call me the count... because I like to count! Ah ha ha ha"); // our message to send
cell.println(26); // ASCII equivalent of Ctrl-Z
delay(15000); // the SMS module needs time to return to OK status
do // You don't want to send out multiple SMSs.... or do you?
{
delay(1);
}
while (1>0);
}
It compiles right, but i'm not receiving any message.
I need help thanks in advance!
Regards,
Jeroen