PWM Sensor not working with Bluz



I have a PWM sensor. The code I am using is below.

It is working perfectly with Arduino but not working with Bluz as I am getting (pulseWidth =0).

Any help is appreciated.


LIDARLite Arduino Library

This example shows how to read distance from a LIDAR-Lite connected over the
PWM interface.

LIDAR-Lite 5 Vdc (red) to Arduino 5v
LIDAR-Lite Ground (black) to Arduino GND
LIDAR-Lite Mode control (yellow) to Arduino digital input (pin 3)
LIDAR-Lite Mode control (yellow) to 1 kOhm resistor lead 1
1 kOhm resistor lead 2 to Arduino digital output (pin 2)

(Capacitor recommended to mitigate inrush current when device is enabled)
680uF capacitor (+) to Arduino 5v
680uF capacitor (-) to Arduino GND

See the Operation Manual for wiring diagrams and more information:


unsigned long pulseWidth;
char stringOne[16];

void setup()
  Serial.begin(9600); // Start serial communications
  Particle.variable("stringOne", stringOne);

  pinMode(2, OUTPUT); // Set pin 2 as trigger pin
  digitalWrite(2, LOW); // Set trigger LOW for continuous read

  pinMode(3, INPUT); // Set pin 3 as monitor pin

void loop()
  pulseWidth = pulseIn(3, HIGH); // Count how long the pulse is high in microseconds
  Particle.publish("Results", String(stringOne) );
  // If we get a reading that isn't zero, let's print it
  if(pulseWidth != 0)
    pulseWidth = pulseWidth / 10; // 10usec = 1 cm of distance
    Serial.println(pulseWidth); // Print the distance