Jumat, 12 Januari 2018

Konfigurasi Sensor Vibration on Rapberry PI

SCHEMATIC:




Python Code:

#!/usr/bin/python
import RPi.GPIO as GPIO
import time

#GPIO SETUP
channel = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.IN)

def callback(channel):
        if GPIO.input(channel):
                print "Gerakan Terdeteksi!"
        else:
                print "Gerakan Terdeteksi!"

GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300)  # let us know when the pin goes HIGH or LOW
GPIO.add_event_callback(channel, callback)  # assign function to GPIO PIN, Run function on change

# infinite loop
while True:
        time.sleep(1)



reff : http://www.piddlerintheroot.com/vibration-sensor/

Konfigurasi Sensor PIR on Rapberry PI

How it Works

PIR (passive infrared) motion sensor detects any movement of objects, human or animals. Mostly they are used in automatically activated lighting and burglar alarm systems.
Every object with temperature above absolute zero emit heat in the form of infrared radiation. PIR motion sensor detects change in the infrared radiation impinging on it. When any object or human passes in the front of the PIR sensor, the temperature in sensor’s field of view will rise from ambient temperature to object temperature and then back again to ambient temperature. PIR sensor converts this temperature change into the change in output voltage and that change in voltage is considered as motion detected.

PIR Sensor

Sensor

Sensor has three pins. Power (VCC), Ground (GND) and output (OUT) pin which gives logic high if motion is detected. It has two potentiometers. One for sensitivity adjustment and second for adjusting the time the output signal stays high when motion is detected.







Python Code : 

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(23, GPIO.IN) #PIR
GPIO.setup(24, GPIO.OUT) #BUzzer

try:
    time.sleep(2) # to stabilize sensor
    while True:
        if GPIO.input(23):
            GPIO.output(24, True)
            time.sleep(0.5) #Buzzer turns on for 0.5 sec
            GPIO.output(24, False)
            print("Motion Detected...")
            time.sleep(5) #to avoid multiple detection
        time.sleep(0.1) #loop delay, should be less than detection delay

except:
    GPIO.cleanup()