Early Warning Perimeter Bridging Alarm. for Copper Theft, Solar Panel Theft. Use Arduino for Fiber Optic Communication and Sent to G-mail.

by Andred56 in Circuits > Arduino

300 Views, 1 Favorites, 0 Comments

Early Warning Perimeter Bridging Alarm. for Copper Theft, Solar Panel Theft. Use Arduino for Fiber Optic Communication and Sent to G-mail.

Alarm PV solar system.jpg
1.jpg

In short this project is how you can protect your very expensive Solar panels from theft. If you want t its can also be used for perimeter bridging alarm.

Now this project is very simple to make even in you know nothing about electronics. If you are good in electronics I will also show you the short cut. Coding the Arduino is simple.

Why did I create this, well in South Africa they steal everything. Like solar panels, all you can do now is connect this fiber wire with plastic caps under the solar with super clue or how ever you like. If the thief cut, break or bent the fiber wire it will make alarm. the alarm can be added to normal house alarm or panic alarm. If you add your E-mail credencials you will get E-mail if alarm is trigger.

To protect perimeter you can wire the fiber with your electric fence wire. Thief's will bridge fence wire out so the fence alarm will not go off, but with fiber added there are no bypass. Unplug, cut or bent it more that 100 degrees will set alarm off.

You can use this on your farm to protect cattle in the camps. Farmers will know to well how thief's in the night break open the camps to get cattle out. Adding fiber to camp will set off alarm.

This project will never give a false alarms. Also alarm system is only good if there are support when alarm goes off.

Supplies

ESP8266_WEMOS_D1_MINI_USBC-7.png
single-channel-5v-relay-module-for-arduino.jpg
TEL0156.jpg
TEL0153.jpg
  1. You will need 1 solder iron 30 watt from China.
  2. Solder wire 0.8mm from China.
  3. Flax for making it look professional and alcohol to clean flux.
  4. Arduino UNO, mini or ESP8266 or ESP32. This is optional, will show now why this is.
  5. A Relay module with one relay on. To connect to home alarm system, else you will need alarm horn on relay if you don't connect to house system.
  6. 10 cm to 5 km Fiber optic. SC connectors only.
  7. Fiber optic Receiver/Transmitter. After months of testing and searching this part and I also want to make it as easy as possible for every one to built this project. So I found the Gravity UART to Fiber Optic Transceiver Module. This is the best, you can built one your self also. I did and its expensive. You can get it any market place or the suppliers. https://www.dfrobot.com/product-2588.html

Software and ESP8266

wemos.jpeg
mcu.jpeg

We will use Arduino IDE for programming the ESP8266 or Arduino Uno. Start with:

  1. Download and install Arduino IDE software from the link http://www.arduino.cc/en/main/software
  2. Open arduino IDE
  3. Go to File on the Arduino menu, select "Preferences" or Press Cntl+COMMA
  4. Add the URL in the 'Additional Boards Manager' (URL Below)

http://arduino.esp8266.com/stable/package_esp8266com_index.json

NEXT STEPS TO INSTALL BOARD SUPPORT

  1. Goto Tools in Arduino menu
  2. Goto Board and select Board Manager
  3. Search ESP8266 and install it.

After this is done you can select your ESP board. For you that use windows PC. Istall driver for Serial chip you have on your board.

Making Project

TEL0153-datail-001_564x376.jpg
ESP8266_WEMOS_D1_MINI_USBC-7.png
FGRT4PNLMKM0QGL.jpg

The Gravity Module comes with small white plug and wired. Wemos can be Arduino UNO or ESP8266 or ESP32.

  • Ground to ground on Wemos
  • Red is 3.3 v or 5 v on Wemos
  • Green is RX on Wemos
  • Blue is TX on Wemos

Relay module have 3 wires.

  • 5 v to Wemos 5 v
  • Ground to Ground
  • Signal to D3. Do not use D4, its onboard led on Wemos.

You done! Simple as I said.

BEFORE UPLOADING CODE, YOU HAVE TO DISCONNECT GRAVITY MODULE FROM WEMOS OR UNO!

What You Will Have Now

3.jpg

This is what your wiring should look like.

For pro's only: On the Gravity Module is an extra purple wire. It is the test LED on the module. You can connect it directly to the relay and with the modules ground. Which will trigger alarm if Fiber wire is broken, cut or bent to much. You do not need an Arduino or ESP/ Wemos if you do this. No need for code but you really need to be skilled to solder wire on that LED. This LED is for testing fiber speed and connection.

I want every one to built this for extra protection so we will use Wemos from here. With Wemos its much easier.

All in One Code

uno.jpg

You can use this code on most Arduino Supported board (not PICO PI) The data you sent over fiber does not matter, you can change it to whatever. It is just to reset alarm delay. You can set up e-mail to sent e-mail if alarm is triggered.

Code is in blocks, making it easy to add or remove thing you want. Not going to explain the code. I added comments in code to make it easier to understand and read.

You can upload this code as is to Arduino Uno and it will disable Wi-Fi and email, thanks to the #if and #endif blocks.

Best is to use this code on ESP8266(Wemos D1) to make use of Wi-Fi and E-mail. The Wi-Fi manager makes it easy to connect to your Wi-FI router.

E-Mail Setup Steps:

  1. Line 30 sender_email: is the E-mail address you going to use to e-mail out.
  2. Line 31 sender_name: The name of the sender
  3. Line 34 sender_password: This is not the normal Gmail password. You need to login to the gmail account and go to setting. Get an app password. Looks like this - yaknlkenkonkdnsk
  4. Then Line 35 & 36 is the address where you sending the e-mail to.

WI- FI Setup Steps:

  1. Search new HOT SPOT called 'SolarProtection', change this in the Setup function, LINE 69 about.
  2. If you connected, open browser and put IP 192.168.4.1 into address bar.
  3. In the page select you Router Hot Spot. Put in your Password and save it.
  4. The ESP8266 will restart and connect to your WI-FI route.
  5. You will get a greeting email if all goes well. Change that message in Setup Function. Line 73 - 77
  6. Warning e-mail message you can change in sentMessageNow Function Line 182

Line number may change a bit as i will update code.

BEFORE UPLOADING CODE, YOU HAVE TO DISCONNECT GRAVITY MODULE FROM WEMOS OR UNO!

Please add comments, let me know where I can in proof this.

#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <ESP_Mail_Client.h>
#endif

/*
* EARLY WARNING SYSTEM TO PREVENT THEFT OF SOLAR or FARMPROTECTION
*
* 1. YOU CAN MAKE CAPS TO PUT WIRE IN, THEN GLUE THAT TO UNDERSIDE OF SOLAR.
* 2. CONNECT IT THE READER.
* 3. POWER DEVICE. SELECT SOLAR HOTSPOT. ON BROWSER GOTO 192.168.4.1
* SETUP YOUR WIFI DETAIL.
* 4. ON YOUR HOTSPOT ROUTER FIND IP OF OF THIS DEVICE. PUT THAT INTO BROWSER AND OPEN.
* 5. CUT WIRE OR BENDING IT TO MUCH WILL SET ALARM OFF
*
* RELAY END CAN BE CONNECTED TO HOUSE ALARM. I WILL PUT IT ON PANIC BUTTON
*
*/

#if defined(ESP8266)
// Set web server port number to 80
WiFiServer server(80);

// Email
#define SMTP_server "smtp.gmail.com"
#define SMTP_Port 465 // or 587
#define sender_email "XXXXXXX@gmail.com" // You sent from this Email
#define sender_name "Early Warning by ADJ" // Name of sender
#define sender_subject "WARNING BOT" // The subject
// Normal gmail will not work. goto settings in google and get app password
#define sender_password "xclnllenkonkdnsk" // You will need app password
#define Recipient_email "xxxxxxxxx@gmail.com" // Where to will you sent email
#define Recipient_name "xxxxxxx" // Name of recipient email
SMTPSession smtp;
#endif

// Variable to store the HTTP request
String header;

String inputString = ""; // String to hold incoming serial data
bool stringComplete = false; // Whether the string is complete
String codeSent = "XXXXX"; // String to sent over fiber. does not matteer whar you sent

#if defined(ESP8266)
int relayPin = D3; // Alarm relay, connect to home alarm.
#else
int relayPin = 12; // Alarm relay, connect to home alarm.
#endif

void setup() {
pinMode(relayPin, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);

for (int xx = 0; xx < 30; xx++) {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
delay(100); // Wait 3 seconds before running code
}
digitalWrite(LED_BUILTIN, HIGH); // Keep LED off

Serial.begin(112500);
// reserve 200 bytes for the inputString:
inputString.reserve(200);

#if defined(ESP8266)
WiFiManager wifiManager; // Start wifi manager
wifiManager.autoConnect("SolarProtection"); // Hotspot name
server.begin();
// Not needed, but you will get a email to show email is working.
// Text color can be changed. its all simple html message
String htmlMsg = "<div style=\"color:#00ff00;\"><h1>Hello I am your alarm bot!</h1>";
htmlMsg += "<p>This is the friendly bot at home.</p>";
htmlMsg += "<p>Good news, I just started up and feeling good.</p>";
htmlMsg += "<p>I will be look after your valuebles now....</p>";
htmlMsg += "<p>Go have a great day now and buy me coffee.</p></div>";
SentMail(htmlMsg); // Post the message
#endif
}

unsigned long lastSentTime = 0; // The last time data was sent
unsigned long sentDelay = 500; // Wait time to sent data
unsigned long AlarmReset = 20000; // Wait 20 seconds before checking connection
unsigned long AlarmDelay = sentDelay + 1500; // No connection in this time alarm on
unsigned long lastemail = 0; // The last time email was sent
unsigned long emailDelay = 60000; // Wait time before sending more emails
void loop() {
#if defined(ESP8266)
// This code is disabled. it ony give you a page to look at.
// Will do something with it soon
/* WiFiClient client = server.available();
if (client) { // If a new client connects,
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
// Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #195B6A; border: none; color: white; padding: 10px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println("input[type=\"radio\"]{margin: 1px 10px 10px;}");
client.println(".alignment {display: flex; flex-direction: row;}</style></head>");

// Web Page Heading
client.println("<body><h1>SOLAR EARLY WARNING SYSTEM</h1>");
client.println("<P>This is the amount of times alarm went of: ");
client.println(countalarm);

client.println("</body></html>");

// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
// Serial.println("Client disconnected.");
// Serial.println("");
}*/
#endif
// Some delay before you sent data over fiber
// Data sent is not important. its just to monitor that there are still a connection
if ((millis() - lastSentTime) > sentDelay) {
lastSentTime = millis(); // Reset last sent
Serial.println(codeSent); // Sent data over fiber
}

// Receive loop data back.
if (stringComplete) {
AlarmReset = millis(); // Reset alarm timer
inputString = ""; // Clear received string
stringComplete = false; // Set to false and wait for new data
digitalWrite(relayPin, LOW); // Keeping the Alarm off
digitalWrite(LED_BUILTIN, HIGH); // Just a led to show Alarm on or off
}

// Simple if data was not received, make some noise
if ((millis() - AlarmReset) > AlarmDelay) {
digitalWrite(relayPin, HIGH); // Switch Alarm on
digitalWrite(LED_BUILTIN, LOW); // Just a led to show Alarm on or off
#if defined(ESP8266)
if ((millis() - lastemail) > emailDelay) {
sentMessageNow(); // Sent that email
lastemail = millis(); // This limit to 2 emails in a minute
}
#endif
delay(50);
}
}

#if defined(ESP8266)
void sentMessageNow() {
// Send HTML message
String htmlMsg = "<div style=\"color:#FF0000;\"><h1>Hello from ADJ!</h1>";
htmlMsg += "<p>This is the friendly bot at home</p>";
htmlMsg += "<p>Bad news, someone is where they should not be.</p>";
htmlMsg += "<p>I suggest, call police or get you wapen.</p></div>";
SentMail(htmlMsg);
}

// Dont change anything below. only if you know what to do
void SentMail(String m) {
/* Declare the message class */
SMTP_Message message;
/* Declare the session config data */
ESP_Mail_Session session;

/* Set the callback function to get the sending results */
//smtp.callback(smtpCallback);

/* Set the session config */
session.server.host_name = SMTP_server;
session.server.port = SMTP_Port;
session.login.email = sender_email;
session.login.password = sender_password;
session.login.user_domain = "";

/* Set the message headers */
message.sender.name = sender_name;
message.sender.email = sender_email;
message.subject = sender_subject;
message.addRecipient(Recipient_name, Recipient_email);

message.html.content = m.c_str();
message.html.content = m.c_str();
message.text.charSet = "us-ascii";
message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;

if (!smtp.connect(&session)) return;

if (!MailClient.sendMail(&smtp, &message)) {
Serial.println("Error sending Email, " + smtp.errorReason());
}
}

// Disabled in SentMail Function
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status) {
/* Print the current status */
Serial.println(status.info());

/* Print the sending result */
if (status.success()) {
Serial.println("----------------");
ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
Serial.println("----------------\n");
struct tm dt;

for (size_t i = 0; i < smtp.sendingResult.size(); i++) {
/* Get the result item */
SMTP_Result result = smtp.sendingResult.getItem(i);
time_t ts = (time_t)result.timestamp;
localtime_r(&ts, &dt);

ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients);
ESP_MAIL_PRINTF("Subject: %s\n", result.subject);
}
Serial.println("----------------\n");
}
}
#endif

void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}