Having the below code, my other requirements to this project are as follows:
Be able to set/write a threshold into the EEPROM via SMS i.e send SMS "set30" to set the threshold to 30, "set12" to set threshold to 12. The temperature should then be compared to this set threshold in EEPROM and if above this threshold an SMS needs to be sent out. So basically I want to see if the set command is sent and if so, read the 2 digits are set, IF they are numerical write that value in EEPROM
Be able to query status of the current room temperature by sending SMS
Any kind of help will be appreciated as I need to submit this project by the end of the year :-(. I really need help.
This is the code that I have used thus far:
#include <SoftwareSerial.h>
#include <EEPROM.h>
SoftwareSerial SIM900(2,3); // RX, TX
float temperature;
byte threshold;
int addr = 0;
void setup()
{
Serial.println("lm35 test 0.1.00");
Serial.begin(19200); // set the baud rate
SIM900.begin(19200); // for GSM shield
delay(20000); // give time to log on to network.
SIM900.print("ATE0\r");
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(1000);
SIM900.println("AT+CNMI=2,2,0,0,0\r");
delay(1000);
Serial.println("Finished Setup Section");
}
/*
as your error information --> variable or field 'sendSMS' declared void
You should write "void sendSMS()"
*/
void sendSMS()
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(1000);
SIM900.println("AT + CMGS = \XXXXXX\""); // recipient's mobile number, in international format
delay(1000);
SIM900.print( " WARNING TEMPERATURE IS: ");
SIM900.print(temperature);
Serial.println(temperature);
SIM900.println( " degree Celcius");
delay(1000);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(1000);
SIM900.println();
Serial.println("Message sent");
delay(5000); // give module time to send SMS
}
void loop()
{
int val = analogRead(0);
float voltage = val * (4.0 /1023); // compiler can optimize the constant part
temperature = voltage * 100; // 0.01V = 1C
EEPROM.write(addr, 35); // writing into EEPROM
threshold = EEPROM.read(addr); // reading EEPROM value
Serial.print("Current Temp: ");
Serial.print(temperature, 2); // Reading the temperature to 1 decimal point
Serial.println("C"); // ALT-0176 => °
delay(500);
if (temperature >= threshold)
{
sendSMS();
delay(5000); // wait for 5 second
}
}
Be able to set/write a threshold into the EEPROM via SMS
What EEPROM do you have that you can send text messages to?
If you mean that you want to send a text message to the Arduino with GSM shield, and have it interpret the message and store some information from the message in it's internal EEPROM, having some code to actually receive the text message would the a good start.
So basically I want to see if the set command is sent
Why is this a problem? You can see, on the Arduino end, where the message is sent. When it is sent, do whatever else it is you want to do.
If you mean that you want to know when the "EEPROM receives the SMS", well that is going to have to happen on this mysterious EEPROM.
I need to submit this project by the end of the year :-(. I really need help.
I hope you can get an extension. I have my doubts about the end of next year.
I want to write into the internal EEPROM of Arduino REV3. I want to send SMS to Arduino via a GSM shield. The GSM module will recieve the SMS "setXX" and send it to the arduino. The arduino will then extract the XX from the SMS and write that into its internal EEPROM so that I can use. The XX needs to be numerical only.
How can I get XX from the SMS sent to arduino? Here is the code is have thus far:
#include <SoftwareSerial.h>
#include <EEPROM.h>
SoftwareSerial SIM900(2,3); // RX, TX
float temperature;
byte threshold;
int addr = 0;
char buffer[7]; // eight char plus null terminator
char secret_code[] = "set30";
char incoming_char=0;
byte buffer_pos=0;
void setup()
{
Serial.println("lm35 test 0.1.00");
Serial.begin(19200); // set the baud rate
SIM900.begin(19200); // for GSM shield
delay(20000); // give time to log on to network.
SIM900.print("ATE0\r");
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(1000);
SIM900.println("AT+CNMI=2,2,0,0,0\r");
delay(1000);
Serial.println("Finished Setup Section");
}
/*
as your error information --> variable or field 'sendSMS' declared void
You should write "void sendSMS()"
*/
void sendSMS()
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(1000);
SIM900.println("AT + CMGS = \"+27XXXXXXX\""); // recipient's mobile number, in international format
delay(1000);
SIM900.print( " WARNING TEMPERATURE IS: ");
SIM900.print(temperature);
Serial.println(temperature);
SIM900.println( " degree Celcius");
delay(1000);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(1000);
SIM900.println();
Serial.println("Message sent");
delay(5000); // give module time to send SMS
}
void loop()
{
while (SIM900.available())
{
delay(100);
incoming_char=SIM900.read();
buffer[buffer_pos]=incoming_char;
buffer_pos++;
if (buffer_pos==5) // Already incremented
{
//Print it out
buffer[buffer_pos]='\0';
Serial.write(buffer);
Serial.println();
if (strcmp(buffer,secret_code)==0)
{
Serial.println("It's a match!");
threshold = Serial.println(secret_code[3-4]);
// printing 3rd and 4th characters i.e. 30 and store the value to variable. Once this value is on a variable, i can then
// write it to the EEPROM
int val = analogRead(0);
float voltage = val * (4.0 /1023); // compiler can optimize the constant part
temperature = voltage * 100; // 0.01V = 1C
EEPROM.write(addr, 30); // writing into EEPROM
threshold = EEPROM.read(addr); // reading EEPROM value
Serial.print("Current Temp: ");
Serial.print(temperature, 2); // Reading the temperature to 1 decimal point
Serial.println("C"); // ALT-0176 => °
delay(500);
delay(10000); // wait for a second
}
if (temperature >= threshold)
{
sendSMS();
delay(5000); // wait for 5 second
}
}
}
}
Thanks for the feed back. I was thinking of reading the 3rd and 4th character like below and doing a strcat:
Serial.println() returns the number of characters printed. Since you are printing one character, plus the carriage return and line feed, threshold1 and threshold2 will be assigned the value 3.
Hardly seems useful.
The strcat() function expects two arrays as input. Neither of the arguments is an array.
If you want the character in the [3] and the [4] position, why not just copy them:
char copy[3];
copy[0] = secret_code[3];
copy[1] = secret_code[4];
copy[2] = '\0';
int val = atoi(copy);
char copy[3]; ??? // declaring copy as a char
copy[0] = secret_code[3]; //copying 3rd char in secret_code to position 0
copy[1] = secret_code[4]; //copying 3rd char in secret_code to position 1
copy[2] = '\0'; ?????
int val = atoi(copy); // converting string to integer
It's really very simple. What don't you understand?
The first set of question marks precedes a statement that is true.
The second set is how one assigns a NULL - standard practice in C, generally explained on about page 10 of any C book. It's time you bought one.