Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- char input[64]; // variable to store the incoming characters
- SoftwareSerial debug(4, 5); //RX, TX
- const int Relay = 8;
- void setup() {
- debug.begin(9600);
- debug.println("Device Initializing...");
- pinMode(Relay, OUTPUT);
- memset(input, 0, 64); //clear input buffer
- digitalWrite(Relay, LOW);
- // wake up the GSM shield
- Serial.begin(9600);
- delay(2000);
- Serial.println("AT+CMGF=1"); // set SMS mode to text
- delay(100);
- Serial.println("AT+CNMI=2,2,0,0,0");
- // just to get a notification when SMS arrives &direct out SMS upon receipt to the GSM serial out
- delay(100);
- }
- void executeCommand(){
- if(!strcmp(input, "$a0")){
- debug.println("Relay OFF");
- digitalWrite(Relay, LOW);
- } else if(!strcmp(input, "$a1")) {
- debug.println("Relay ON");
- digitalWrite(Relay, HIGH);
- } else {
- debug.println(strcat("Unknown Command: ", input));
- }
- Serial.println("AT+CMGD=1,4"); // delete all SMS
- delay(1000);
- }
- void loop(){
- //If a character comes in from the GSM...
- int i = 0;
- while(Serial.available()){
- char c = Serial.read();
- input[i++] = c;
- delay(12);
- }
- if(i){
- input[i++] = 0; //null terminate our string
- executeCommand();
- i = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement