0

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.

2
  • 1
    The Pi's GPIO are 3V3. It is not safe to use a device with 5V outputs. What is Vth used for? Don't use pass, use time.sleep(0.001).
    – joan
    Jun 24 at 16:16
  • Vth is the threshold voltage, I set its duty cycle at 10% at the start of the program (which I would assume is 0.33V). By changing pass to sleep there are no changes to the output. Jun 25 at 8:05
0

I've just got one of these but I've not plugged it in yet, just reading up on it first. The datasheet mentions:

  • powered with 5V on Vcc (4.5 to 5.5V, desirable to have less than 30mV ripple)
  • mentions Vth values of 0.5V but frustratingly doesn't describe its purpose - a guess would be this scales the output value (pulse count per second)
  • shows block diagram with OUT1 and OUT2 and some 3k internal resistors to Vcc

For Vth a PWM signal with 10% duty cycle is not an analogue signal so it's going to be unpredictable/undefined as to what the device will do it you stick that down Vth. I would go with a potential divider on 3.3V, perhaps a 560ohm (or 1k pot set to 0.56) and 100ohm resistor pair to get ~ 0.50V out of 3.3V to match the datasheet value. If you want to vary this you could try some RC filtering of the PWM to get a fairly constant Vth but I'd be inclined to check that with an osciloscope with the device connected.

It looks like putting a 4.7k on each output to GND will keep the voltage in the safe 0V-3.3V range for the Raspberry Pi GPIO inputs. If you've got an oscilloscope (and a dusty room) you can check this...

Once you've got it working it might be worth comparing Pi's 5V power with having the sensor powered by some battery cells (not a power pack) to see if the stability of the Pi's 5V power affects it. I use four NiMH AA's for this sort of testing.

I suspect Figure 2 on Omron: Development of air quality sensor for air purifier is either for the B5W-LD0101 or similar devices. It shows that a PWM signal for threshold voltage Vth is going to give very strange output!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.