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.