Triggering a Relay With an SR04 Ultrasonic Sensor




This isn't the best way to trigger a relay with this sensor but it is a quick and dirty way to do so. I am NOT a professional coder nor do I claim to be. I am still trying to learn C ++ so i would ask that you keep that in mind if you make a comment. I appreciate feedback, however i ask that you keep it constructive. Thank you.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials

All you really need is:

1. A breadboard (

2. an Arduino of any kind(I used an Uno)(

3. Relay module(

4. An SR04 Ultrasonic sensor(

5. Jumper wires(

Step 2: The Connections

Connections are as follows:

Pin 11: Relay Output

Pin 7: link to pin 6

Pin 6: link to pin 7

Pin 4: Echo

Pin 3: Trigger

That is all other than 5v and Gnd but those are self-explanatory. Feel free to modify and republish the code, all i ask is that you link this instructable in if you re-publish it.

Step 3: The Code

Sorry it took me so long to upload this. But here it is !

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    7 Discussions


    3 years ago

    If this works and I am smart enough to figure it out, you will be responsible for an awesome Halloween this year.

    1 reply

    Reply 3 years ago

    No problem :) If you have any issues just let me know :)


    3 years ago

    Thank you. Cool project


    3 years ago

    Thank you.

    please send me code.

    1 reply

    Reply 3 years ago

    Sorry about that. I completely forgot to upload the code for some reason but it is there now. Also thank you for reading my instructable :)