Help needed: controlling one motor using sensors

Hello hello,

I am looking for help in regards to controlling a motor (right now I have a step motor 5V DC) using sensors for an art installation. My goal is for the motor to stop when there is someone standing directly in front of the piece, but to continue working when there is no one there.

Any help with the code or how I would go about controlling the motor with a sensor is much appreciated (and desperately needed please).

I have the Ultrasonic Distance Sensors right now, but have read in other forums that maybe an analogue distance sensor such as SHARP GP2Y0A21YK0F would work better. What is the different between these two and does it matter?

Thank you!! ((-:

You will have to post links to the datasheets for the two sensors if we are to advise you.

A diagram (with dimensions) showing the zone in which you want the system to activate would also help. See this Simple Image Guide

And. exactly what stepper motor are you using? If it is a 28BYJ-48 then there are dozens of Threads on the Forum about them.

If it is a different motor then please post a link to its datasheet.

Stepper Motor Basics


Yes it is the 28BYJ-48 Step Motor. Can I run it as a 'regular' motor since I only want it to go in one direction or will it be easier for me to just get a new motor?

I have attached a diagram. The zone should be around 4 feet (willing to make it less) when directly in front of the piece.


Stepper motors are usually chosen because they allow accurate positioning. However there is nothing to prevent you from running one continuously in one direction. They have the advantage over a DC motor that you can choose the speed while retaining the full torque of the motor.

Your Original Post said

someone standing directly in front of the piece

which led me to think that you do not want it to activate if the person is standing close but to one side. However your diagram suggests that I was mistaken.

Based on your diagram I think the simple ultrasonic that is widely used in Arduino projects should be suitable.