Using Arduino Uno to Monitor DC Motor Activation and Rotation Direction

I apologize ahead of time if this post is incorrectly formatted. I am working on 2 projects. Could really use some fresh ideas as I feel I am having some kind of mental block :slight_smile: :astonished:

I have 4 dc motors, all four share a common lead, and the remaining leads all go back to a switch bank. They run on 12Vdc. Only 1 motor can be actuated at a time in either forward or reverse direction. Assuming none of the leads maintain a consistent state of V+ or GRND between actuation's, what would be the best way to monitor this. Basically I just need to be able to create a "truth table" style logic when monitoring the analog inputs to determine which motor is on and in which direction it is turning....

My considerations are I only have A0 to A5 open... would prefer to keep it simple without opamp or multiplexers...

Common -------------------------------------------
l l l l
motor motor motor motor
l l l l
Motor1-----------------l l l l
Motor2---------------------------l l l
Motor3-------------------------------------l l
Motor4----------------------------------------------l

I am open to any ideas... Please help.

Thanks,

I'd suggest 8 optocouplers, or 2 IC like this Optoisolator - 4 Channel - COM-00784 - SparkFun Electronics, connected to 8 digital inputs. You can save on resistors, activating internal pull-ups. Look at the drawings.

Connect the motor power supply ground to Arduino ground and then use five digital inputs to detect whether each of the motor controls is high or low.

You can compare the state of the individual feed for each motor with the state of the common feed to determine whether that motor is stationary, moving forwards or moving backwards. There are various different ways to do the comparison. The simplest approach would be to stick the four individual boolean states in an array and use plain old if-else logic to do the comparison. Depending what you intend to do with the answer, other approaches might work better. For example you could stuff the five bit values into a byte and produce nine possible numeric values for the nine possible states and use a switch statement to decide what to do with the result. Since I don't know what you're planning to do with the result, I can't advise which approach would work best for you.

If it is practical for the Arduino to share a common ground with the 12v motor supply, then I'd use the approach suggested in reply #2. I'd connect a 220K resistor between each of the 4 motor connections and the corresponding Arduino input, and I'd connect a 0.1uF capacitor from each Arduino input to ground. Similarly for the motor common connection. The resistor will limit the current to a safe value when the protection diode in the Arduino pin limits the input to 5v, and the capacitor will suppress noise pickup.

If it is not practical to use common grounds, or you're not sure, then I would use the approach suggested in reply #1.

Thanks for all the suggestions... some more details that may help...

I can connect to the power supply ground, but do not have any open digital pins (its part of a bigger project)

shy of getting a mega, any other ideas.... I was thinking about some form of a MUX resistor array..... but its just in my head for now...

Thanks again for reading. :slight_smile:

You can use the analog inputs A0 to A5 as digital inputs. If you want to use fewer than 5 pins, then you could use a resistor network (e.g. R-2R ladder network) and read analog values instead, however you may then have to compensate for any variation in the 12v supply and in the voltages appearing at the motor terminals.

so the plot thickens guys....

all leads to the motors (4 individual and 1 common) are held high in resting state (no motors moving).

When a motor needs to move, the corresponding static 3 go low or high to equal the common, while the motor being actuated goes opposite.

soooo, I tried to set up a resistor network, but to no avail... This is what I plumbed up...

as I was drawing it I now understand why it won't but for some reason I think that it could with ******* (insert secret recipe here :slight_smile: )

I think that scheme could work. The 4 resistors to the motors should be in the ratio 1:2:4:8. Alternatively, use an R-2R network (see http://www.avr-asm-tutorial.net/avr_gra/r2r.gif), then you need only 2 different values of resistor. Either way, use a resistor to ground to limit the analog input to a little under 5v when all 4 motor connections are at 12v. You will get 16 different analog readings depending on which of the 4 inputs are high. You may need to use another analog input to measure the 12v supply so that you have a reference.

dc42 - that works!!! awesome.

I put a switching diode between the motor signal and the R2R network to prevent any feedback to the motor drivers (not sure if they are protected or not).

So last question, values for resistors. I tested with a ton of 10k resistors (in series and such to get the 2R) but with my input volatge at about 13v, my output was 12.884... I need it lower than 5V for arduino...

any good pointers to some calculators or explanations on how to calculate....

Thanks,

Diodes between the motor signal and the R-2R network inputs will change the behaviour of the network by denying a path to ground when the input is low. So I'm not sure they are a good idea, and they only protect against transients in one direction. I would instead use higher value resistors (say 100K for the 2R and 2 x 100K in parallel for the R) and rely on the input protection diodes in the Arduino mcu. If you like, you can connect Schottky diodes between the Arduino analog input and the +5 and ground lines as well.

To reduce the input to the 0 to 5V range, just connect a load resistor between the output of the R-2R network and ground. A value of around half R should be about right. Also connect a capacitor in parallel with this resistor (around 0.1uF should do) to smooth out any transients.