Piezo Vibration Sensor without hat

Dear all,



as my vendor did not have any Grove hats for Raspberry Pi available, I was wondering if I could get the Grove Piezo Vibration Sensor to work without the hat.



I have followed <LINK_TEXT text=“http://wiki.seeedstudio.com/Grove-Piezo … on_Sensor/”>http://wiki.seeedstudio.com/Grove-Piezo_Vibration_Sensor/</LINK_TEXT> Tutorial (except the part of the hat of course), and am receiving the error message:

,



The pins are all connected correctly according to the wiring of the hat. Is there a way to bypass this / adjust the code from the grove library to make it work in my setup?



Thank you very much for your help in advance.



Best regards,

David

Hi there,

The code in Wiki is used with hat. if you don’t have any hat, you can connect Piezo Vibration Sensor’s OUT to RPi’s digital pin, such as pin 2, and try the code below:
[code]
import time
import RPi.GPIO as GPIO

SENSOR_PIN = 2

GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PIN, GPIO.IN)

while True:
if GPIO.input(SENSOR_PIN) == GPIO.HIGH:
print(“Detected”)

time.sleep(0.1)

[/code]

Best regards,

Blu

Hi Blu,



Thank you a lot for response. Indeed, I could detect the sensor that way.



By modifying your code, I have tried to use the RPi.GPIO Documentation to get an output:

[code]
import time
import RPi.GPIO as GPIO

SENSOR_PIN = 2
SENSOR_POUT = 3

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PIN, GPIO.IN)
GPIO.setup(SENSOR_POUT, GPIO.OUT)

while True:
if GPIO.input(SENSOR_PIN) == GPIO.HIGH:
print(“Detected”)
print(GPIO.output(SENSOR_POUT, GPIO.HIGH))

time.sleep(0.1)

[/code]

The output I get is:

The “None” is showing up independently if there is vibration or not. Is there a way to get any value out of the sensor as an output, that I can correlate to vibration?



Best regards,

David

Hi David,



The “None” is the print output of GPIO.output() function, because the function have no return value.



Sensors are used only as input usually, if you want to “see” the vibration, you can connect a display Grove – like Grove - Red LED to your Raspberry Pi. Suppose the Grove - Red LED connected to Raspberry Pi’s pin 3, to make LED lights up when vibration detected, the code looks like this:

[code]
import time
import RPi.GPIO as GPIO

SENSOR_PIN = 2
LED_PIN = 3

GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PIN, GPIO.IN)
GPIO.setup(LED_PIN, GPIO.OUT)

while True:
if GPIO.input(SENSOR_PIN) == GPIO.HIGH:
print(“Detected”)
GPIO.output(LED_PIN, GPIO.HIGH)
else:
GPIO.output(LED_PIN, GPIO.LOW)

time.sleep(0.1)

[/code]

Best Regards,

Blu