Posts: 20
Joined: Fri Sep 02, 2016 5:11 am

Using ultrasonic sensor to trigger a relay

Fri Sep 02, 2016 5:27 am

I'm working on a project where I'll be having and device rolling across the floor. What I want to do is use an ultrasonic sensor to detect a gap in the devices path. When the gap is detected I want the device to trigger a relay that turn the motor off so that the device will stop. I've got the code to get the pi to turn on the sensor, emit a pulse & calculate the distance. It then will display the distance on the screen. What it like to do is if the pi detects a sudden change in distance that it sends a signal to one of the gpio pins. That way I can use that gpio pin to trigger a relay to cut the power to the device. I'm pretty good with physical electronics. Relay, resistor, diodes etc... but I'm not the greatest with coding. Can somebody help me figure out how to accomplish this?

Thank you,

Return to “HATs and other add-ons”