Question about sim900

#include <SoftwareSerial.h>   
  SoftwareSerial SIM900(7,8);
  int sensor=12;
  
  void setup()   
  {
  pinMode(sensor,INPUT);   
  SIM900.begin(9600);    
  Serial.begin(9600); 
  Serial.println ("Move in front of the sensor");  
   
  }   
  void loop()  
  {        
  
    if (digitalRead(sensor) == HIGH) {           
     
    Serial.println("Movement detected");
    delay(2000);
    SendMessage();  
  } 
  }   
  void SendMessage()   
  {   
  Serial.println ("Sending Message");   
  SIM900.println("AT+CMGF=1");    
  delay(1000);   
  Serial.println ("Set SMS Number");   
  SIM900.println("AT+CMGS=\"xxxxxxxxxxxxx\"\r"); 
  delay(1000);   
  Serial.println ("Set SMS Content");   
  SIM900.println("MOTION DETECTED"); 
  delay(100);   
  Serial.println ("Finish");   
  SIM900.println((char)26);  
  delay(1000);   
  }

I apologize if someone has already asked this question.

This is the code i came up with with a little help from the community....
so I have arduino uno and shield sim900 connected and everything works....
but I need advice on how it can send me only one sms when activating the pir sensor and not a series of several and without stopping even though nothing in front of the sensor is moving.
And if I put a "button" it doesn't help, a series of messages are sent until I turn everything off.

Welcome to the forum

You need to detect when the sensor becomes HIGH rather than when it is HIGH

See the StateChangeDetection example in the IDE

Thank you :grinning:
I could be 100% wrong, but I don't think that is the problem, since even if I use one jumper cable 5v-pin12, the same problem occurs

How are you connecting the button? Do you have a pulldown resistor connected?

The way your code is written all the time the sensor is HIGH a text will be sent every 2 seconds

How long does the PIR keep the input pin HIGH once movement is detected ?

that's a good question i don't have an answer to...
therefore, I should make a code that, when the sensor detects something, sends only one message and waits for X seconds before he can send another? Clearly, if there is nothing to detect, it does not send anything....

that shouldn't be a problem either, although I think I've tried that too

Firstly you should confirm what your sensor is doing. They can often be run in different modes... for example... stay HIGH for x seconds after movement vs. only stay HIGH while there is movement.

Of course it will be a problem... without the value will be floating when the button is not being pressed.

Can you tell me how to check that?

You need to check the datasheet for your sensor. For example the HC-SR501 has jumpers to change the way movement is signalled.

yes, I should have uploaded what I put together first, I apologize for that,
that's the sensor i have.

Can't see much from that picture. Is there a datasheet?

the only thing I found is this scroll down there is some info

Looks like the default is 2.5s HIGH, but might pay to check yours.

it says that if you change the resistor, you change the delay, but I'm certainly not going to touch those small resistors with a home soldering iron, so I thought I'd compensate in the code

Yep, no problem with that. After the sensor goes HIGH just don't check it again for X seconds.

1 Like

ok, we could work with that, but now there is another problem... I passed in front of it with my hand only once and it sent me 8 messages.....
there can't be a problem only in the sensor, and on the other hand, if the problem was a "short circuit", wouldn't it start sending messages even without the sensor or with something connected to pin 12 (with the fact that I tried other pins as well)?

Replace the sensor with a button and try that.

You need a pull down resistor though. (Or define as INPUT_PULLUP, connect button to GND, and check for LOW).

5v>jumper>resistor>pin11 (this time)
works without problems

I can't find the button so I improvised :grimacing: :grimacing:

in conclusion if there is no break between the pins it sends messages non-stop

i just tried your method and same thing happens if i press the button one time it sends messages constantly.

5v>jumper>resistor>pin11 but it worked perfectly that way

I am currently blocked as a new member, so we will continue the topic later

You need to use the resistor as a pulldown.

Not sure what this means? Are you saying if you connect to 5v then it keeps sending? That is exactly what you expect isn't it?