georgopanos
Posts: 3
Joined: Fri Apr 19, 2013 8:54 pm

Create Alarm sensing unit when Wire is cut

Fri Apr 19, 2013 9:02 pm

I want to create an alarm. Basically a wire will wrap around the entire fence line which is about 1000 feet and if the wire is cut I want a trigger to send an audible alarm to a speaker and an email notification.

I am new to the rasberry pi so I wanted to know where can I start with this? What will I need to purchase?

Thanks

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Create Alarm sensing unit when Wire is cut

Sat Apr 20, 2013 8:40 am

This is potentially a very simple and very nice first try project.

You can basically just run a wire from the 3v3 pin to a GPIO pin of your choosing; that will make that pin read as "1" or "on". Start with 10cm wire, not 1000 feet :)

Whenever you disconnect this wire, it will go to "0" or "off".

What you need is a bash script or python script that monitors this pin constantly, for example through a loop, and then does something when it reads as 0, like play a MP3 and/or send a mail.

There are lots of little bits in this to get working, start with one of them - like making the GPIO pin read 1 or 0.
I suggest you use gordon's wiringPi executable called "gpio" to read the values, it's quite easy that way.

1000 feet may be too much for the little 3v3 to handle to get a signal through, but then again it may be sufficient. You'll have to try.

PDK
Posts: 1
Joined: Sat Apr 20, 2013 8:12 am

Re: Create Alarm sensing unit when Wire is cut

Sat Apr 20, 2013 8:58 am

Hi,
I would be powering the loop by something like 24V DC to drive a relay (the 24V does not go anywhere near the RaspberryPi, just the relay coil). The normally open contacts of the relay would be connected across the 3.3v supply pin and a GPIO pin and have a pull down resistor between the GPIO pin and the GND pin (or use the internal pulldown resistor). This should give you a fail safe state so that if the 24V supply, or relay fail the alarm still goes off.

You would need to write some code to access the GPIO pins. I would be looking at the Python examples http://elinux.org/RPi_Low-level_peripherals. The relay GPIO pin needs to be set up as an input and the buzzer as an output.

When the relay drops to LOW sound the buzzer and e-mail. You might also need and additional input as an On/Off switch.

Here is a python script that checks a machines public ip address and sends an email to another address. You should be able to hack the sending email part for your project.

Code: Select all

##############################################
#
# The purpose of this code is to identify the
# public IP address and Email the new address
# in the event that it is changed
#
##############################################

#imports for email
import imaplib
import smtplib
import email
from email.mime.text import MIMEText
from email.parser import HeaderParser
from email.mime.multipart import MIMEMultipart

#Imports for IPaddress
from urllib.request import urlopen
import re

##############################################
# Variables
#############
USERNAME = "send email from [email protected]"    #SMTP account
PASSWORD = "password goes here"
HOME = "email address to send to"

IPaddress = "0.0.0.0"


##############################################
# Function to return public IP address
##############################################

def getPublicIp():
    data = str(urlopen('http://checkip.dyndns.com/').read())
    return re.compile(r'Address: (\d+\.\d+\.\d+\.\d+)').search(data).group(1)  

##############################################
# Function to send Email
##############################################
def sendEmail(IP , OldIP):
    TEXT = IP
    msg = MIMEMultipart()
    msg['Subject'] = 'IP address has changed from ' + OldIP + ' to ' + TEXT
    msg['From'] = USERNAME
    msg['To'] = HOME
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.ehlo_or_helo_if_needed()
    server.starttls()
    server.ehlo_or_helo_if_needed()
    server.login(USERNAME,PASSWORD)
    server.sendmail(USERNAME, [HOME], msg.as_string() )
    server.quit()
    print('Email sent')

##############################################
# Main
##############################################
#while True:
ipfile = open('ipfile.txt', 'r')
iptext = ipfile.readline()
ipfile.close()
print('last IP: ' + iptext)
IPaddress = getPublicIp()
print('New IP: ' + IPaddress)
 
if IPaddress != iptext:      #If the ip address has changed send the email
    ipfile = open('ipfile.txt', 'r+')
    print("Address has changed")
    ipfile.write(IPaddress)            
    ipfile.close()                 
    sendEmail(IPaddress, iptext)

print('Complete')    

######################################## Done
Good luck with it
Regards
Phil

User avatar
Burngate
Posts: 6222
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Create Alarm sensing unit when Wire is cut

Sat Apr 20, 2013 9:19 am

As TarjeiB says, quite simple, from the hardware point of view

However, I would point out a couple of elephant-traps.
When the (short) wire is connected, the GPIO pin will be high - 3v3 or "1"
However, when it's disconnected it will float at some unknown voltage unless you have a pull-down resistor to force it to 0v or "0"

That'll be fine with a short wire, but when you have a 1000 ft long wire, you may find you still have a problem.
If the resistor you choose is too low in value, the 3v3 supply may not be enough to pull the GPIO high, given the length of the wire and its resulting resistance
On the other hand, a higher pull-down resistance will let your wire act as an aerial, picking up all sorts of rubbish from BBC Radio 4 to the odd lightning strike or a sheep scratching itself on the fence

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Create Alarm sensing unit when Wire is cut

Sat Apr 20, 2013 10:39 am

Personally I would drive one end of the wire with a known voltage, and the other end into a known resistance to gnd. Even better would be to drive this with a low frequency (a few kHz) AC signal preferably close to sine wave.

Then take the driven end and other end into an ANALOG schmitt trigger comparator with a wide hysterisis to reduce effects of pickup. Take this output to 3V3 conversion into a GPIO port and detect events on BOTH edges.

By comparing both ends with wide hysterisis (preferably about 40% of driven voltage level) you avoid a lot of pickup problems and voltage drop in cable hopefully, if cable and connections are not high impedances. Driving AC signal reduces the losses a bit.

Hopefully you do not have the fence too near any form of radio mast (including TV and mobile phone)
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

danneman
Posts: 19
Joined: Thu Jun 21, 2012 9:57 am

Re: Create Alarm sensing unit when Wire is cut

Sat Apr 20, 2013 11:14 am

Hi.

You probobly have to take care of the EMI aspects because you are having a 300m loop antenna connected.

Perhaps you can use a optocoupler with a TVR and some ferrites to protect your Pi and optocoupler from failure.

/Daniel

User avatar
Burngate
Posts: 6222
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Create Alarm sensing unit when Wire is cut

Sat Apr 20, 2013 12:13 pm

Or go for an optical fibre - no interference problems!

As a matter of interest, what are you trying to guard against?
Cows pushing the fence over? Interlopers cutting through the fence?

georgopanos
Posts: 3
Joined: Fri Apr 19, 2013 8:54 pm

Re: Create Alarm sensing unit when Wire is cut

Mon Apr 22, 2013 3:22 am

BURNGATE:
Not guarding trying to catch a friends neighbor cutting his fence to allow his kids to play on his property. We are going to install video surveillance also but he wants to catch him while he is doing the cutting.

Return to “Automation, sensing and robotics”