0

I am using an RCWL-1601 Ultrasonic sensor, ran off of a Raspberry Pi Pico. According to Adafruit, the sensor is equivalent to the more popular HC-SR04 Ultrasonic sensor. I am trying to use the sensor to measure distance. The output is currently showing 0.The sensor is wired to 3v3 & GND (datasheet for sensor says 3v3 or 5v compatible, I have tried both 3v3 & 5v), with Trig on GPIO3 and Echo on GPIO2. The code compiles and provides the output of "Distance = Out of range" on the serial monitor. I am running the following code through Arduino IDE:

#define trigPin 3
#define echoPin 2
float duration, distance;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);

  // convert the time into a distance
 distance = (duration/2) * 0.0343;

 Serial.print("Distance = ");
 if(distance >= 400 || distance <= 2){
  Serial.println("Out of range ");   
 }
 else{
  Serial.print(distance);
  Serial.println(" cm");
  delay(500);
 }
  delay(500);
}

Output when uploading to Pi: 

Sketch uses 53548 bytes (2%) of program storage space. Maximum is 2093056 bytes.
Global variables use 10232 bytes (3%) of dynamic memory, leaving 251912 bytes for local variables. Maximum is 262144 bytes.
Resetting COM8
Converting to uf2, output size: 142848, start address: 0x2000
Scanning for RP2040 devices
Flashing D: (RPI-RP2)
Wrote 142848 bytes to D:/NEW.UF2


Serial monitor output (Repeating): 
13:35:08.795 -> Distance = Out of range 
13:35:10.294 -> Distance = Out of range 
13:35:11.795 -> Distance = Out of range 
13:35:13.289 -> Distance = Out of range 
13:35:14.791 -> Distance = Out of range 
13:35:16.295 -> Distance = Out of range 

I have verified that the sensor is getting power through measuring the VCC and GND pins on a scope. I have tried multiple of the same sensor. I tried rewiring to different pins on the Pico. On the back of the sensor is a jumper spot for either UART or I2C, with the default being I2C connected. I have tried soldering the UART jumper and disconnecting the I2C jumper.

I believe the issue may be that the echo pin is not going low when it receives the pulse, but I do not know how/why. I have tried multiple different versions of code from Youtube tutorials & forums.

I have tried the Blink example to verify that I can flash to the Pico from the Arduino IDE and that worked fine.

I am on Arduino IDE version 1.8.18. I am using the boards manager package called Raspberry Pi Pico/RP2040 version 3.3.0 by Earle F. Philhower.

  • Are u import arduino module on RPi? – toyota Supra Jul 15 '23 at 01:12
  • 1
    @toyotaSupra , I did import the Arduino Module. When I plugged a HC-SR04 Ultra sonic sensor (Different sensor) in with the exact same set up as the RCWL-1601, it worked just fine. I have learned that the RCWL-1601 sensor needs to be i2c where the HC-SR04 can work as an Rx/Tx set up. So now I need to understand how to interface with the RCWL-1601 using i2c. – Davandjes Jul 17 '23 at 15:55
  • Btw, I don't have RCWL-1601 with me. – toyota Supra Jul 17 '23 at 16:12

0 Answers0