Project tutorial
Mains Failure Detector

Mains Failure Detector © GPL3+

How avoid a freezer disaster while I am away.

  • 499 views
  • 0 comments
  • 4 respects

Components and supplies

Ard nano
Arduino Nano R3
Arduino NANO or UNO or PRO MINI
×1
GPRS shield SIM900
×1
12V switching wall power supply
×1
12702 01
SparkFun Solder-able Breadboard - Mini
×1
Pppc081lfbn rc sml
Female Header 8 Position 1 Row (0.1")
One with short pins, two with long pins to stack on GPRS shield
×3
Male power Jack
×2
Female power jack
×2
Tens70
9V battery (generic)
×1
Keystone 233 image 75px
9V Battery Clip
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×2
Resistor 5,6K ohm or 6,8k ohm
×1
Fairchild semiconductor 1n4004. image
1N4007 – High Voltage, High Current Rated Diode
×2
Panasonic eca2am101
Capacitor 100 µF
×1

Necessary tools and machines

09507 01
Soldering iron (generic)

About this project

It's very easy: if mains power fails, the GPRS module sends an alarm message with an SMS to my cell-phone.

Pin D2 of the Arduino is normally at HIGH level (see below: 4, 6V from the resistor divider R2/R1+R3). When mains power fails, it goes at LOW level and the GPRS module sends a message.

When the electric power returns, the GPRS module sends an "ok" message.

I used a solderable breadboard to build the circuit and headers & jumpers to connect the GPRS shield as indicated:

Connector 1 from Arduino D7 to GPRS TXD (UART)

Connector 2 from Arduino D8 to GPRS RXD (UART)

Connector 3 from Arduino D9 to GPRS D9 (board)

Arduino GND to GPRS GND (UART)

The 9V battery feeds Arduino and GPRS shield when electricity supply, normally given through the 12V jack, is off.

I tested it and works well with UNO, NANO and MINI with the same software.

Code

SMS_1a.inoArduino
At lines 68, 85 and 102 you must replace XXXXXXXXXXXX with your phone number in international format.
You can compile the same code for Arduino UNO, NANO and PRO MINI. Required memory is very little.

Lines from 26 to 30 will switch on the shield, but, if it is just ON it will go OFF!!!! It's important to start the program with the shield OFF. So, ATTENTION:

1. Load software
2. Detach USB connector
2. Connect first the 12V power supply
3. Connect 9V battery

Now "Status" led on the shield will be on and "NetLight" led will be blinking and it will arrive the message "*** SISTEMA CONNESSO ***" (system connected).

If you want more informations about the GPRS shield, at https://randomnerdtutorials.com/sim900-gsm-gprs-shield-arduino/ you will find a very helpfull tutorial.
/*  

GPRS Shield with SIM900

Connections:
Arduino UNO pin 2 to Vin
Arduino UNO pin 7 to Shield TXD
Arduino UNO pin 8 to Shield RXD
Arduino UNO pin 9 to Shield pin 9 (shield ON/OFF)
Arduino UNO GND to Shield GND

*/

#include <SoftwareSerial.h>

// Configure software serial port
SoftwareSerial SIM900(7, 8); 

//Variable to save incoming SMS characters
char incoming_char=0;
//Allarm status
byte allarmSent = LOW;

void setup() {
  // Switch on the GSM shild
  pinMode(9,OUTPUT);
  digitalWrite(9, HIGH);
  delay(2000);
  digitalWrite(9, LOW);
  delay(5000);
  // Set pin 2 as input for Vin detection
  pinMode(2,INPUT);
  // Arduino communicates with SIM900 GSM shield at a baud rate of 19200
  SIM900.begin(19200);
  // Give time to GSM shield to log on to network
  delay(30000);
  // AT command to set SIM900 to SMS mode
  SIM900.print("AT+CMGF=1\r"); 
  delay(100);
  sendSMSready();
  // Set module to send SMS data to serial out upon receipt 
  // SIM900.print("AT+CNMI=2,2,0,0,0\r");
  // delay(100);
}

void loop()
{
  // Display any text that the GSM shield sends out on the serial monitor
  if(SIM900.available() >0) {
    //Get the character from the cellular serial port
    incoming_char=SIM900.read();
    //Print the incoming character to the terminal
    Serial.print(incoming_char);
  }
  while (digitalRead(2) == HIGH) {}
  if(digitalRead(2) == LOW && allarmSent == LOW) {
    // whait 1" more and send message if pin 2 is already LOW
    delay(1000);
    if(digitalRead(2) == LOW) sendSMSallarm();
  }
  while (digitalRead(2) == LOW) {}
  if(digitalRead(2) == HIGH && allarmSent == HIGH) sendSMSallarmOFF();
}

void sendSMSallarm()
{
  // Set recipient's mobile number in international format
  SIM900.println("AT + CMGS = \"+XXXXXXXXXXXX\""); 
  delay(100);
  // Set SMS message
  SIM900.println("*** MANCANZA TENSIONE RETE ***");
  delay(100);
  // End AT command with a ^Z, ASCII code 26
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  // Give module time to send SMS
  delay(5000);
  allarmSent = HIGH;
}

void sendSMSallarmOFF()
{
  // Set recipient's mobile number in international format
  SIM900.println("AT + CMGS = \"+XXXXXXXXXXXX\""); 
  delay(100);
  // Set SMS message
  SIM900.println("*** TENSIONE RETE OK ***");
  delay(100);
  // End AT command with a ^Z, ASCII code 26
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  // Give module time to send SMS
  delay(5000);
  allarmSent = LOW;
}

void sendSMSready()
{
  // Set recipient's mobile number in international format
  SIM900.println("AT + CMGS = \"+XXXXXXXXXXXX\""); 
  delay(100);
  // Set SMS message
  SIM900.println("*** SISTEMA CONNESSO ***");
  delay(100);
  // End AT command with a ^Z, ASCII code 26
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  // Give module time to send SMS
  delay(5000);
}

Comments

Similar projects you might like

Arduino EMF Detector A.K.A Ghost Detector

Project showcase by Patel Darshil

  • 8,022 views
  • 9 comments
  • 18 respects

Jar Temperature Detector and Cooling Fan

Project tutorial by Kutluhan Aktar

  • 1,311 views
  • 0 comments
  • 7 respects

The Vibrating Pressure Temperature Altitude Tilt Detector

Project tutorial by Kutluhan Aktar

  • 1,397 views
  • 0 comments
  • 4 respects

Arduino Project: Burglar Zone Input Tester

Project tutorial by Cezarjar

  • 1,549 views
  • 2 comments
  • 9 respects

Light Intensity and Solar Panel Energy Detector

Project tutorial by Kutluhan Aktar

  • 2,633 views
  • 3 comments
  • 14 respects

Remote Lamp

Project tutorial by Kutluhan Aktar

  • 2,332 views
  • 0 comments
  • 7 respects
Add projectSign up / Login