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.

Step 1: Materials

All you really need is:

1. A breadboard (http://www.amazon.com/Solderless-BreadBoard-tie-points-power-rails/dp/B005GYAIES/ref=sr_1_1?ie=UTF8&qid=1442695282&sr=8-1&keywords=breadboard)

2. an Arduino of any kind(I used an Uno)(http://www.amazon.com/Arduino-UNO-board-DIP-ATmega328P/dp/B006H06TVG/ref=sr_1_1?s=electronics&ie=UTF8&qid=1442695333&sr=1-1&keywords=arduino+uno)

3. Relay module(http://www.amazon.com/Indicator-Light-Channel-Module-Arduino/dp/B00P7QDJD2/ref=sr_1_5?s=electronics&ie=UTF8&qid=1442695315&sr=1-5&keywords=relay+module)

4. An SR04 Ultrasonic sensor(http://www.amazon.com/niceEshop-Ultrasonic-Distance-Measuring-Sensor/dp/B00F167T2A/ref=sr_1_4?s=electronics&ie=UTF8&qid=1442695299&sr=1-4&keywords=sr04+distance)

5. Jumper wires(http://www.amazon.com/Wosang-Solderless-Flexible-Breadboard-Jumper/dp/B005TZJ0AM/ref=sr_1_2?s=electronics&ie=UTF8&qid=1442695342&sr=1-2&keywords=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 !

<p>If this works and I am smart enough to figure it out, you will be responsible for an awesome Halloween this year.</p>
<p>No problem :) If you have any issues just let me know :)</p>
Thank you. Cool project
<p>Thank you. cctvdph@gmail.com </p><p>please send me code.</p>
<p>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 :)</p>
<p>Cool project.</p>
thank you

About This Instructable




More by rianc:Triggering a relay with an SR04 ultrasonic sensor 
Add instructable to: