turn on two leds with hc-sr04

how can I turn on 2 LEDs with a hc-sr04 sensor in the ide. the truth is I don’t have an idea of ​​how to do this problem as easy as it will be for some

This is a XOD forum, so you probably won’t get much help programming in IDE here.

Before you can even start on a program, you need to know EXACTLY what you want it to do. “Turning on 2 LEDs with a range sensor” is NOT an exact description. Do you just want to light both LEDs when the sensor is active? Do you want one LED turned on when something is within 10cm and both turned on when something is within 5cm? EXACTLY what you want to do will determine how it should be done…

Most likely, you will want to use the built-in XOD node xod-dev/hc-sr04/hc-sr04-range-meter to read a distance from the sensor, then compare the output to determine actions. One gotcha that you will run into with the range-finder is that it needs time to recover from each ping, so you should NOT leave the sensor node in loop mode; there should be some trigger to take a reading only when needed (which could be a point in your program, or could just be every couple seconds using a clock node).

Without more information about what you are trying to do, it is impossible to provide any more help, but there are several example nodes in xod-dev/hc-sr04 that will show how the sensor can be used.


I try to give an idea if you mean something like this, I tried this in some of my projects, maybe it can help a little

You can’t really use equal to compare analog output because it will almost never be exactly equal. A value of 0.200001 is not equal to 0.20, even if watch node displays it as 0.20 because it is rounding the value before display. One alternative would be to check for greater than 0.15 AND less than 0.25 (or 0.19 and 0.21, or 0.1 and 0.3, or… depending on how narrow a range you want to include)

I tried to apply this to my project, I tried to measure the watch value from 0.00 to the sensor limit, I tried less than 4 meters,
so my benchmark only takes 2 digits behind zero ,
I tried to implement this on Carbot Follow me.
sir Gwimer, can anyone visit my youtube, I use your library and I use equal as above to drive the motor for the carbot project followme