#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.
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....
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.
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
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)?