For a couple of days I've been trying to make this B5W-LD0101 particle sensor work (https://www.digikey.it/it/datasheets/omron-electronics-inc-emc-div/omron-electronics-inc-emc-div-en_b5w-ld0101-1_2). I've connected OUT1 to GPIO23, OUT2 to GPIO22, and Vth to GPIO27. (In the code, though, I will only be testing OUT1). This is the code:
from time import sleep import math import RPi.GPIO as GPIO PIN = 23 VTH = 27 cntP1 = 0 def switch_callback(gpio_pin): global cntP1 if gpio_pin == PIN: cntP1 += 1 GPIO.setmode(GPIO.BCM) GPIO.cleanup() GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(PIN, GPIO.FALLING, switch_callback) GPIO.setup(VTH, GPIO.OUT) p = GPIO.PWM(VTH, 100) p.start(10) time.sleep(5) def StartPulseReader(): global cntP1 while True: ftime_e = math.floor(time.time()) + 1 while time.time() < ftime_e: pass print(cntP1) cntP1 = 0 if __name__ == '__main__': StartPulseReader()
When I run it, it returns extremely high values (around 100) and the sensor doesn't seem to react if I stimulate it. Any tips? Kind regards.