• Hi all,

    I have tried following the guide at http://www.espruino.com/HC-SR04 to get the HY-SRF05 module working. From what I understand it is pretty much the same as the SR04, but I am super new at electronics, so maybe it isn't!

    Anyway, I am using pins A6/A7 as I have the Wifi module on A0-A4 and I am always getting an output of between 35 - 45 when I log it in the console regardless of whether something is in front of it.

    Anyone got any ideas on why it might not be working?

  • So yours has 5 pins, and you're not connecting to out?

    One thing it could be is the Pico has slightly different names for power signals than the original Espruino board, which is a bit confusing. You need to connect to the pin marked 'VCC' on the board (the one labelled 5V on the reference card and here). Bat itself is an input for a battery, rather than an output.

  • It looks like you leave Mode disconnected, and then it behaves just like an HC-SR04...

    It does need to be powered off VBat/Vcc (not BAT_IN or 3v3).

  • Ah, right, so I was powering it off 3.3 and that seemed to be the issue. I am now powering it off VBat (which is the equivalent to 5v out when powered from a USB port?) and it seems to be working ok, detecting things that are closer than 4cm.

    It does seem to be maxing out at 4cm ish though, when there is nothing in front of it, but that could just be how it's set up (currently just plugged into a breadboard), or maybe a limitation of the module?

    Thanks @DrAzzy and @Gordon I am really enjoying playing with the Pico.

  • Great, glad it's working(ish).

    VBat (or 5V/Vcc on the Pico) is either the power the comes from USB via a diode (so around 4.5v), or if you've got a battery plugged in it's battery power (without any diode voltage drop).

    It should be enough for the sensor though - it works great for the HC-SR04. It's actually possible the sensor is picking up a reflection from the desktop - if so, 4cm sounds about right.

  • I just did some (un)scientific testing and still can't get the thing to get the right distance. I moved the sensor the the very edge of the desk at the edge of the breadboard and measured some distances using a ruler and the handy Espruino reference card that I got in the kit and got the following values (actual measurement on left, console.log on right):

    1. cm = 1cm
    2. cm = 1.7cm
    3. cm = 2cm
    4. cm = 2.6cm
    5. cm = 3.3cm
    6. cm = 3.7cm
    7. +cm = 4.1

    I am guessing it's probably something to do with my module, but does that kind of pattern make any sense to you? Some kind of resistor needed? Again, apologies for my utter ignorance about this stuff.

  • Strange... I'm afraid it doesn't make much sense to me - it might to someone else I guess. The delay should be proportional to the speed of sound, which wouldn't change depending on the module :)

    And you're definitely not using the out pin, but the echo one as the input?

  • Watch out what you try to use for reflection of the sound... I had my share of surprises on a different medium, but still some material that I expected to work correctly, did not do so. You have also be aware of indirect reflection. To get clear results not only direct sight matters but also what comes or is close to the send receive axis...

  • Hi guys,
    So I tested the sensor on my Arduino Uno and it works as expected using the code from this page: http://www.robot-electronics.co.uk/filesĀ­/arduino_srf04.ino Same environment, breadboard and leads, just plugged them straight out of the Pico into the Arduino.

    I tried the other analog pins I have access to (only A5,A6,A7,B1 as I soldered the shim and wifi module on) and got the same results. Do you think I could have messed something up soldering the wifi module on?

  • An update. I ran the sensor from the 5v/GND lines of the Arduino while pinging the trigger and echo with the pico. I got what I was expecting (although every other line there was a weird enormous number, but I guess that has something to do with the Arduino) so I guess this module needs a full 5v for power.

  • Thanks for the update... That's strange though - most 5v stuff copes just fine with 4.7v or so.

    If you absolutely need that voltage (and you're not planning on using the battery circuitry on the Pico) you can just short out the diode to get full 5v though.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

HC-SR04 / HY-SRF05 distance sensor not working on Pico?

Posted by Avatar for Bennr @Bennr

Actions