SW420 vibration sensor LOPY4
-
Hy,
I am trying to make a vibration sensor (SW420) work with the LOPY4 board.
Here is the code currently used in the main file:
import socket import machine from machine import Pin import pycom import time def pin_handler(channel): channel=1 print("Detection d'une vibration " ,channel()) pir = Pin("P2", mode=Pin.IN, pull=Pin.PULL_UP) try: pir.callback(Pin.IRQ_RISING, pin_handler) while 1: # create a LoRa socket s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) # set the LoRaWAN data rate s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) # set the LoRaWAN port number for transmitted packets s.bind(7) #s.send(struct.pack('d', pir())) time.sleep(1) except KeyboardInterrupt: print(" STOP")I would like to analyze the vibration of an equipment to define on-off moments. Ideally, I would like to retrieve the first change in value (from 0 to 1) tell the number of 1 (vibration) in a period (for example 5 seconds) if the number of 1 is greater than 5 for example, I go back to a state (ON or 1).
And the same thing in the other direction, if there is no more operating state for 5 seconds, go back to an end state (OFF or 0).
Do you have any ideas ?Thanks for your help.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login