Arduino and gsm

hi,
I am a new one to c++, trying do something with Arduino and GSM module. i have two codes, one is for alerting me according to a pin voltage and another one is for acquiring the status of the pin through sms. while combining these two codes, the status acquiring message not working. help me to combine it.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(11, 12); // RX, TX

const int V1 = 2;
int st1 = 0;
int ontmr=0;
int oftmr=0;

void setup() {
  mySerial.begin(9600);
    Serial.begin(9600);
   // initialize the pushbutton pin as an input:
  pinMode(V1, INPUT);
}

void loop() {
     // print response over serial port
if (mySerial.available())
Serial.write(mySerial.read());

st1 = digitalRead(V1);
{
if  (st1 == LOW) goto alert;
if  (st1 == HIGH) goto ok;

ok:
 Serial.println("OK");
 oftmr=-1;
 ontmr++ ;
 Serial.println (ontmr);
 if (ontmr == 5 )
 {
 Serial.println("POWER UP");
 mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
 delay(1000);  // Delay of 1000 milli seconds or 1 second
 mySerial.println("AT+CMGS=\" x \"\r"); // Replace x with mobile number
 delay(500);
 mySerial.println("POWER UP");// The SMS text you want to send
 delay(100);
 mySerial.println((char)26);// ASCII code of CTRL+Z
 delay(5000);

 
 mySerial.println("ATD+x;"); // ATDxxxxxxxxxx;
 delay(2000);
 Serial.println("check down up- if");
 }
 delay(1000);
 goto end1;
   
 alert:
 ontmr=-1;
 oftmr++ ;
 Serial.println (oftmr);
 Serial.println("DOWN");
 ontmr=-1;


 if (oftmr % 1800 == 0)
 {

mySerial.println("ATD x ;"); // replace x with mob number
 delay(5000);

Serial.println("DOWN - SMS sent");
mySerial.println("AT+CMGF=1");
delay(1000);

mySerial.println("AT+CMGS=\"x\"\r"); // Replace x with mobile number
 delay(500);
 mySerial.println("POWER DOWN!");// The SMS text you want to send
 delay(100);
 mySerial.println((char)26);// ASCII code of CTRL+Z
 delay(5000);

 }
 delay(1000);
 goto end1;


end1:
delay(500);
}
  }

CODE 2

#include <SoftwareSerial.h>

SoftwareSerial mySerial(11, 12); // RX, TX
char incoming_char=0;
char msg=0;
const int V1 = 2;
int st1 = 0;



void setup() {
  mySerial.begin(9600);
 Serial.begin(9600);
 mySerial.print("AT+CNMI=2,2,0,0,0\r");
 delay(1000);
}

void loop() {

 Serial.println (st1);

st1 = digitalRead(V1);

{
mySerial.print("AT+CNMI=2,2,0,0,0\r");
incoming_char=mySerial.read(); 
    //Print the incoming character to the terminal
  //Serial.print(incoming_char); 

  String message = mySerial.readStringUntil('\n'); // read the message until newline character

    // Check if the message is "hi#"
    if (message.indexOf("hi#") != -1) {
      // Send a reply
      mySerial.println("AT+CMGS=\" x \""); // Replace with your phone number
      delay(1000);
      mySerial.println("Status :");
      mySerial.print(st1);
      mySerial.write(26); // End of message character
      delay(1000);
    Serial.println ("Status Enq SMS");
  }
}

Hello,

Please correct your post and add code tags around your code.

There is a small pencil image below your existing posts.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)

--

do yourself a favour and please read How to get the best out of this forum and post accordingly (including code with code tags and necessary documentation for your ask like your exact circuit and power supply, links to components etc).

HI,
sorry for the mistake,
new post edited and uploaded

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.