Pir gsm alarm

hello everybody
i have a problem in the arduino code that the GSM module is not receiving any msg to make my alarm project complete... if anybody could help me.

#include<SoftwareSerial.h>
SoftwareSerial mySerial(8, 9);//Pin 9,10 used as Rx and Tx
int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int pinSpeaker = 10;           //Set up a speaker on a PWM pin (digital 9, 10, or 11)
int sms_count=0;
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(pinSpeaker, OUTPUT);
  mySerial.begin(9600);
  Serial.begin(9600);
}

void loop(){
  
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    playTone(300, 160);
    delay(150);
  while(sms_count<2) //Number of SMS Alerts to be sent limited at 2
    {  
      SendTextMessage(); // Function to send AT Commands to GSM module
    }
    
    if (pirState == LOW) {
      // we have just turned on
    
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
      digitalWrite(ledPin, LOW); // turn LED OFF
      playTone(0, 0);
      delay(300);    
      if (pirState == HIGH){
      // we have just turned of
      
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}
void SendTextMessage()
{
  mySerial.println("AT+CMGF=1");    //To send SMS in Text Mode
  delay(1000);
  mySerial.println("AT+CMGS=\"+212642543498\"\r"); //Phone no 
  delay(1000);
  mySerial.println("Quelqu'un dans la maison");//content of the message
  delay(200);
  mySerial.println((char)26);//stopping character
  delay(500);
  sms_count++;
}
// duration in mSecs, frequency in hertz
void playTone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(pinSpeaker,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(pinSpeaker, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}
SoftwareSerial mySerial([color=red]8, 9[/color]);//Pin [color=red]9,10[/color] used as Rx and Tx

seems either a stupid comment or a bug...

that will send it twice in a row because of the while

  while(sms_count<2) //Number of SMS Alerts to be sent limited at 2
    {  
      SendTextMessage(); // Function to send AT Commands to GSM module
    }
  mySerial.println("AT+CMGF=1");    //To send SMS in Text Mode
  delay(1000);
  mySerial.println("AT+CMGS=\"+212642543498\"\r"); //Phone no 
  delay(1000);
  mySerial.println("Quelqu'un dans la maison");//content of the message
  delay(200);
  mySerial.println((char)26);//stopping character

remember that print[color=red]ln[/color]() add \r\n for you at the end of what is printed (so double check what it means for AT+CMGS

you should use write instead of println to send the ctrl-Z

This code    int period = (1.0 / freq) * 1000000;would probably be better written as    int period = (1000000 / freq); and an int might be not appropriate for representing the result

--- PLEASE FOLLOW FORUM RULES, READ THE MESSAGES AT THE TOP OF THE FORUM ---
Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

thank you for your respond!! could you help me more please to modify the code because i'm a beginner in Arduino !!

NO I won’t do it for you.

First because Here we help out those investing time and reading tutorials, experimenting and not willing something just done for them.

Second because you did not even bother fixing the presentation as asked or thinking through the recommendation, which is a bad sign of respect for forum rules and etiquette. I take that seriously and you feel definitely in the category or lazy members. (sorry I just speak my mind)

So you should first start by

  • fixing your initial post and read how to use the forum
  • document in plain English and in details what YOUR project should do

Then start small steps:

  • writing a code to experiment with the PIR (read tutorials about initialisation, triggering, the role of the 2 potentiometers you might have on the unit etc)
  • writing another program with a function that sends ONE sms and call it just from setup() to see if it works. Learn about how much current is needed for the shield etc
  • then writing a code that is not using the GSM, just print something in the console based on your needs
  • then put it all together

If you do that you’ll find plenty volunteers to help out, if not you can go to the Gigs and Collaboration forum and offer some money for a good programmer to do what you don’t want to learn doing.

i don't want to pay nobody sir!! i just asked you for more help and explain me what mean every instruction
so that i can learn to write a code by myself not to write to me the whole code!!

however thank you for responding!

Elya_amal:
could you help me more please to modify the code because i'm a beginner in Arduino !!

Sorry I don’t read this as « please explain what every line does »... It reads as « do my homework for me »....

If the code is too complicated for you, and you are a beginner, then go where beginners needs to start: learn the basics of programming, the language and then do some very basic arduino tutorials

When you master that, come back to fix this more complex problem. I gave you steps for exploration - do those, show us code for every step.

And as you still did not bother fixing the first post, you showed no respect. I’m out of this thread. Someone else might be more generous and help out - good luck

it's already been fixed. this is my first day i entered to the forum i'm sorry if i did a mistake!! it's probably my ignorance to the rules

You fixed it after my last post. Time stamp on it...

Sure - and as a new comer and beginner you decided not to read the posts at the top of the forum, right?

See those posts titled

How to use this forum - please read.
Read this before posting a programming question ...
Useful links - check here for reference posts / tutorials

You thought probably “I don’t need those. They are for losers. I want my problem solved quick...”

...anyway - leaving someone else to help you out unless you come back with code as per the learning path I mentioned and that you understand the lines you use

you just think that i thought like this but nothing like that!! sorry for disturbing you and i repeat this is my first day here i don't know nothing even if that code must be written like this mode!! if i didn't fix it before because i were trying to understand your notes !! some friends told me about the forrum to post my question and they will answer me but i see that i entred to argue with you!! i'm not a lazy person because if i were i would'nt come here to ask you about my problem so i'm really sorry for this massive problem!! i'll go somewhere else to search for my problem and try to fix it by myself !! sorry again :slight_smile:

Your call - we would help if you try to do this in the right order, as suggested. Seems,you want to go fast but going fast without a plan just gets you in the middle of nowhere fast, not to your destination.

Have fun