Leds with ultrasonic sensor

Hi
I want to make leds with ultasonic sensor, i want to when sensor see something leds turn on or turn off permanently, not for a second or something like that. I have stuff but i dont know how to write this code. If somebody know please tell me.
Thanks

Welcome to the group.

Please try and explain exactly what’s needed.


Before asking questions:


If your sketch was generated with an AI like ChatGPT or by someone else tell us in your post.


  • Questioners know what their hardware and software looks like but the volunteers here do not; you need to fully explain what’s not working, and how it is supposed to work.
  • Please read all the posting guidelines before asking your questions; follow these guidelines in your post.

  • As always, show us a good schematic of your proposed circuit.
  • Show us good images of your ‘actual’ wiring.
  • Give WEB links to major components.

  • In the Arduino IDE, use Ctrl T or CMD T to format your code, then copy the complete sketch.
  • Use the < CODE / > icon from the ‘posting menu’ to attach your copied sketch.

When you follow the posting guidelines, volunteers can be more effective.

I mean i want to turn on leds with ultasonic sensor an then turn them off

  • As always, show us a good schematic of your proposed circuit.
  • Show us good images of your ‘actual’ wiring.
  • Give WEB links to your major components.

And we have to guess what stuff you have?
No thanks.

I have relay module, ultrasonic sensor, 12v white led strip, 12v power supply and the arduino

can we have the reference of the components:
because there are a lot of type of relay module, a lot of type of ultrasonic sensor and so on.

Ultrasonic sensor-HC-SR04
Relay module-songle srd-05vdc-sl-c

thank you very much

for the code, the first thing you should do is an algorhytme.
Do you have one ?

No, can u help?

Have you worked through any of the simple introductory examples in the IDE?

here is the algorhytm I'm thinking about:

1: LED OFF

2: IF THE SENSOR RECEIVES DATA
THEN TURN ON THE RELAY MODULE
ELSE GO BACK TO THE BEGINNING

3: IF THE SENSOR RECEIVES DATA
THEN TURN OFF THE RELAY MODULE
ELSE GO BACK TO THE PREVIOUS STEP

but for the code it will be more difficult because i am also a beginner but I can give it a try later.

An ultrasound ranger will typically "RECEIVE DATA" or it will timeout.

(Please don't SHOUT)

Thanks for help!

Have you discovered Wokwi yet??
HC-SR04 Ultrasonic Sensor Example

have fun.. ~q

I'm curious - does the simulator mimic late returns from the previous ping, if you ping too frequently?
Is it a configurable option?

only param i see on it is initial distance..
wokwi-hc-sr04
No idea, I don't have a paid account, so maybe there's more??

sorry.. ~q

So, I'm guessing no correction for ambient temperature either.

I'm a beginner in prog

2 Likes