10-12-2015, 23:03
Działa musiałem przełączyć na modemie A z tą aktywacją ciężko to zrobić sms ?wtedy było by dokładnie tak jak sobie wymarzyłem
Ocena wątku:
Alarm powiadomienie sms aktywacja sms
|
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
int sms = 0 ;
char incoming_char = 0;
void setup()
{
SIM900.begin(19200);
SIM900power();
delay(20000);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void loop()
{
if ( digitalRead(2) == LOW ){sms = 1;sendSMS();}
if ( digitalRead(3) == LOW ){sms = 2;sendSMS();}
if(SIM900.available() >0){
incoming_char=SIM900.read();
Serial.print(incoming_char);
if ( incoming_char == '1' ){digitalWrite(4, HIGH);}
if ( incoming_char == '0' ){digitalWrite(4, LOW);}
}
}
void sendSMS()
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"+12128675309\""); // recipient's mobile number, in international format
delay(100);
if (sms == 1)SIM900.println("sms czujnika 1"); // message to send
if (sms == 2)SIM900.println("sms czujnika 1");
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
SIM900power();
sms = 0; // turn off module
}
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
int sms = 0 ;
char incoming_char = 0;
void setup()
{
SIM900.begin(19200);
SIM900power();
delay(20000);
pinMode(2 , INPUT_PULLUP);
pinMode(3 , INPUT_PULLUP);
pinMode(4 , OUTPUT);
digitalWrite(4, LOW);
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void loop()
{
if ( digitalRead(2) == LOW ){sms = 1;sendSMS();}
if ( digitalRead(3) == LOW ){sms = 2;sendSMS();}
if(SIM900.available() >0){receiveSMS();}
}
void sendSMS(){
SIM900.println("AT + CMGS = \"+12128675309\""); // recipient's mobile number, in international format
delay(100);
if (sms == 1)SIM900.println("sms czujnika 1"); // message to send
if (sms == 2)SIM900.println("sms czujnika 1");
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
sms = 0;
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(200);
SIM900.println("AT+CMGD=1,4");
delay(200);
}
void receiveSMS(){
incoming_char=SIM900.read();
delay(20);
if ( incoming_char == '1' ){digitalWrite(4, HIGH);}
if ( incoming_char == '0' ){digitalWrite(4, LOW);}
Serial.print(incoming_char);
SIM900.println("AT+CMGD=1,4");
}
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
int sms = 5 ;
char incoming_char = 0;
void setup()
{
SIM900.begin(19200);
SIM900power();
delay(20000);
pinMode(2 , INPUT_PULLUP);
pinMode(3 , INPUT_PULLUP);
pinMode(4 , OUTPUT);
digitalWrite(4, LOW);
delay(200);
smsRecStart();
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void loop()
{
if ( digitalRead(2) == LOW ){sms = 1;sendSMS();}
if ( digitalRead(3) == LOW ){sms = 2;sendSMS();}
receiveSMS();
sms = 0 ;
}
void sendSMS(){
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"+12128675309\""); // recipient's mobile number, in international format
delay(100);
if (sms == 1)SIM900.println("sms czujnika 1"); // message to send
if (sms == 2)SIM900.println("sms czujnika 1");
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
smsRecStart();
}
void receiveSMS(){
if(SIM900.available() >0){
incoming_char=SIM900.read();
delay(20);
if ( incoming_char == '1' ){digitalWrite(4, HIGH);}
if ( incoming_char == '0' ){digitalWrite(4, LOW);}
Serial.print(incoming_char);
SIM900.println("AT+CMGD=1,4");
}
}
void smsRecStart(){
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(200);
SIM900.println("AT+CMGD=1,4");
}