# How do I make a DC motor rotate clockwise for a random value, then rotate counter-clockwise for the same amount autonomously? [closed]

For my project I need to build a repeatable vehicle without using any programmable devices (eg: Arduino, microcontrollers etc) After activation, the vehicle needs to move straight towards a wall which is a random distance away, make contact with the wall, and come back as close as possible to the starting point. I have decided to use a DPDT to reverse the motor but I still can't figure out how to make the vehicle stop at the starting point after returning from the wall. The distance between the starting point and the wall ranges from anywhere between 1.4m-4.0m.

edit: the whole project has to be built within a budget of 30£

• So you actually need a way to keep track of time from the beginning to the wall, and use the same time to let the motors running the opposite direction? Feb 11, 2021 at 10:29
• How much Heath-Robinson mechanical engineering are you willing to do? What's the maximum distance? Feb 11, 2021 at 10:46
• Ah, let me see. You need at least the following hardware: (1) A stop watch which consists of the following: (a) a 1Hz astable (eg 555) , (b) a binary counter (eg 74LV393). (c) A micro switch which can stop the binary counter. With this stop watch, you can count the number of seconds that the car has used to hit the wall. Please let me know if this part meets your assignment requirement. :) Feb 11, 2021 at 10:57
• You can obviously use an encoder of some kind (there are many such.) You can also use sensorless approaches (measuring current.) I'd recommend doing a google search on "sensorless methods PWM motor resolution" etc. I haven't read them, but a quick look finds "Review of Sensorless Methods for Brushless DC" and "A Position-and-Velocity Sensorless Control for Brushless DC Motors Using an Adaptive Sliding Mode Observer" as a couple of likely things to look at. I'm actually finding dozens of candidates that avoid the use of an encoder for this. Study up!
– jonk
Feb 11, 2021 at 11:45
• Optical (Transmit) Rotary Encoder Kit For Arduino (20 optical slots per motor shaft revolution)- US\$1.29 nl.aliexpress.com/item/… Feb 11, 2021 at 12:28

Build an odometer.

You'll need the slotted disc and opto-sensor arrangement that's used by old-style computer mice with rotating ball-and-roller sensors. This produces pulses as the wheel rotates.

That pulse train can be sent to a counter. Have the counter run "up" when going forwards and "down" when going backwards. You will need to chain them to get enough counts to measure enough distance accurately.

When going backwards, the point at which the counter flips over from 0000 to 1111 is the point at which it's travelled the same distance as it did when going forwards. At this point, stop.

you could use a reduction gear that trips a limit switch.

You could use a reversable counter to count shaft revolutions, or seconds.

You could time current into and out-of a capacitor.

You could store the measurement on a piece of string, or a microcasette that is spooled and unspooled.

• I really like the casette one: mechanically couple it to the drive shaft, and use the plastic lead-in to determine where the end is. Feb 11, 2021 at 12:40

That would be possible, using electromagnetic relays, with limit switches actuated at either end.

Here's a similar application.

Reversing polarity automatically

An electro-mechanical solution might be good. You could turn a screw one direction as you drive towards the wall and drive it the other direction as you drive in reverse. When it gets back to the initial position it can press a button.

If connecting up to the car's drive is complicated then just use a separate motor to drive the timer.

Run two binary counters (eg CD4040) one for counting shaft rotations in the forwards direction and the other counting the reverse direction.

Connect the outputs together using 1K resistors.

measure the supply current to the pair of counters when it's low (less than 1mA) they both have the same value so that's when you stop the motor.