primetime
Posts: 5
Joined: Sat Sep 24, 2016 7:42 am

Panic Button (315Mhz)

Tue Sep 27, 2016 6:51 am

Hey guys,

I just wanted to share with you my first project on my Raspberry Pi. It's basically a Panic/Help Button for my mom, so that I or my dad get notified if she needs anything.

It consists of the following parts:
  • Raspberry Pi 2
  • Adafruit Simple RF M4 Receiver - 315MHz Momentary Type
  • Adafruit Keyfob 4-Button RF Remote Control - 315MHz
I wrote up a quick diagram of what I have:
Image

And here's the code:

Code: Select all

#Time functions
from datetime import datetime

# GPIO functions and modeset
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)

# Push Notification setup
from pushetta import Pushetta
API_KEY="pushettaapikeythatisreallylong"
CHANNEL="PUSHETTAALERT"

# Define which 'physical' GPIO pins are to be used for the buttons
buttonA=11
buttonB=12
buttonC=15
buttonD=16

# Set up the GPIO pins to be pull-down so that they are triggered when 
# current from the corresponding RF receiver goes through
GPIO.setup(buttonA,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(buttonB,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(buttonC,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(buttonD,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)

def pushMsg(channel):
	presstime = datetime.now().strftime('%A, %d %B %Y at %H:%M:%S %Z')
	button = getButton(channel)
	msg = 'Button %s pressed on %s'%(button,presstime)
	p=Pushetta(API_KEY)
	p.pushMessage(CHANNEL_NAME, msg)
	print pressmsg
	print msg
	

def getButton(channel):
	return{
		11: 'A',
		12: 'B',
		15: 'C',
		16: 'D',
	}[channel]


# Add event detection to GPIO pins
GPIO.add_event_detect(buttonA, GPIO.RISING, pushMsg, bouncetime=50)
GPIO.add_event_detect(buttonB, GPIO.RISING, pushMsg, bouncetime=50)
GPIO.add_event_detect(buttonC, GPIO.RISING, pushMsg, bouncetime=50)
GPIO.add_event_detect(buttonD, GPIO.RISING, pushMsg, bouncetime=50)

print "Waiting for button press"
try:
	raw_input('Press <Enter> key to exit\n')
except KeyboardInterrupt:
	GPIO.cleanup()
GPIO.cleanup()
This is my first project using the Raspberry Pi and I'm pretty much a noob at this. If you guys have any suggestions and comments, I'm all ears as I want to make this better so that it would help my family out!

Return to “Other projects”