SEN136B5B Ultrasonic Sensor printing 0

I'm trying to use a SEN136B5B ultrasonic rangefinder with an arduino nano BLE 33. I'll put my code and the pinout below, but I am receiving no readings and only constant values of 0. I've tried altering the ping delay, but nothing seems to work. Any ideas?

const int pingPin = D6;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  long duration, inches, cm;

  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT);
  duration - pulseIn(pingPin, HIGH);

  Serial.print(duration);
  delay(100);
}

You are going to hate yourself.
That minus sign should be an equal sign

duration = pulseIn(pingPin, HIGH);

Yeah, that was it. Less hate myself, more "Oh my god, how did I miss that."
Thanks, though.

Software is like that.
Sometimes you can stare at it forever but you see what you think it should be and not what it actually is

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.