Simple question

I want to use the voltage going to a dc motor as a digital input on my arduino.

The motor is a brushed (2 wire) 12v dc motor.

If the motor only span in one direction then I know how to step down the voltage to 5v using resistors.

My problem is the motor runs in both directions i.e. the wires can be both live and ground depending on which way the motor is spinning.

How can I use the signal? I need to know which way the motor is turning.

Feed the voltage into opto isolators with voltage connected opposite on each. Only one will operate for each direction.

Weedpharma

I had considered that but thought it might blow the LED inside when the current is running backwards?

Check the specs to be sure but I would think 12v would be ok.

Weedpharma

I'm struggling to find one which would be suitable.

Most seem to be 6v reverse.

if you have a limiting R from the motor to the input of the opto, you can put diode opposite to that of the LED so that when the motor is reversed, the current flows though a forward biased diode. That will mean the voltage across the LED will never get too high.

The LED only needs a small (5mA) current to work so little current is wasted if the right R is chosen.

Weedpharma

Is that the same principal as this?

As I have 12v a 2k2 resistor would give approx 5mA

(12V - (Vf protection diode) - (Vf LED)/resistor = current
Assuming Vf's of 0.7V and say 2.2V yields
(12V - 0.7V - 2.2V)/2200 ohm = 4.1mA

Ah ok, the motor actually gets between 10-11v so maybe a 1k resistor would be better.

Is the schematic correct? I would have thought the diode goes on the other side of the LED?

It does not matter which order you arrange components, in a simple circuit like that.

If you want to know when the motor is on, regardless of which direction it is rotating, use a bidirectional optocoupler like the LDA110. Data sheet at http://www.ixysic.com/home/pdfs.nsf/www/LDA110.pdf/$file/LDA110.pdf

My suggestion actually was to have the protective diode across the LED but reverse direction. When voltage is forward, LED lights, when reverse, diode conducts to limit reverse V on LED.

JRemington, the bidirectional will not allow determining direct as requested in OP.

Weedpharma

weedpharma:
Feed the voltage into opto isolators with voltage connected opposite on each. Only one will operate for each direction.

Precisely that.

Connect the optocoupler LEDs "back to back" with a common resistor. Rather like this diagram:

But with two optocouplers and you only need one resistor with the value that suits (1k for 12V) - no reason to split it as here.

I had not actually thought of the second LED being the reverse diode!

Good idea.

Weedpharma

weedpharma - thank you for clarifying, I understand now.

So if i use 2 opto isolators but have them connected 'back to back' then I won't need diodes as eachothers LEDs will act as a diode? Is that correct?

As I don't have any opto isolators to hand but I do have LEDs and LRDs, I've mocked up my own opto isolator for the forward direction and it's working nicely!

I don't have any diodes to hand to test the reverse direction but following on from above, if I mount my second led 'back to back' with the first will they protect each other when the current reverses?

"if i use 2 opto isolators but have them connected 'back to back' then I won't need diodes as eachothers LEDs will act as a diode? Is that correct?"

Yes. A conducting LED will have a voltage across it less than 3 volts ( assuming basic red LED). Use a limiting resistor of 1 k or more.

Simply turn your "sensor" around to confirm it is okay in reverse.

Weedpharma

Great, thanks.

My test setup is working nicely. Hopefully get my hands on some opto isolators tomorrow to test it properly.

Another full-wave bridge opportunity missed.
(You could get one that looks like an IC, so it'd be sexier and worthier that way.)

I guess there's a direction divination design goal.
Had the idea that only whether was important (Reply #11?)
Assuming you have "control" over the thing, you should know which direction it's going.
What's to be accomplished here?

Surely the opto isolator solution is better as they also isolate the circuits for added protection.

I've not come across full-wave bridges before. It does seem a neat solution.

Bear in mind.

He does want to know in which direction the motor is powered.

Is the output from an opto isolator digital or analog?

When the motor is running it draws around 11v but sometimes it draws around 9v when stationary and the rest of the time its at 0v.

On my test set up using an LED and LDR I can easily set the threshold in my code as the LDR is analog. Will I be able to do the same with an opto isolator?