// Sending an SMS every time when the garage door was opened.
// Use reed switch to monitor door state (open/closed).
#include <GSM.h>
#define REED_SWITCH_PIN 6
#define PINNUMBER "" // SIM card PIN
#define RECIPIENT_NUMBER "+380987654321" // Replace with your telephone number.
GSM gsmAccess;
GSM_SMS sms;
bool notConnected = true;
bool opened = false;
void setup() {
pinMode(REED_SWITCH_PIN, INPUT);
// Start GSM shield.
// If your SIM has PIN, pass it as a parameter of begin() in quote.
while(notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
delay(1000);
}
}
}
void loop() {
// There are two types of reed switches: NO (normally open) and NC (normally closed).
// Normal state means the state when the switch is not under the influence of a magnet.
// Closed - conducts current. Open - does not conduct current.
// So for NO switch HIGH means the door is closed (switch is near the magnet).
// For NC switch HIGH means the door is opened (switch is far from the magnet).
// You can use both types of reed switches, but update the check accordingly.
// NO reed switch consumes more energy in this circuit,
// but when someone maliciously cuts the wires, an SMS will be sent.
// This check is for NO (normally open) reed switch.
if (digitalRead(REED_SWITCH_PIN) == HIGH) { // the door is closed
opened = false;
} else if (!opened) { // the door was just opened (the door is open and previously it was closed)
opened = true;
// send SMS
sms.beginSMS(RECIPIENT_NUMBER);
sms.print("Garage door was open.");
sms.endSMS();
// 15 minutes break
delay(900000);
}
}
Comments