Blocking -VDC

I am working on a project and I need to read what direction a shaft is spinning, I am not sure how to do this. I have found some information on rotary encoders but have not found one that seems like it will be durable enough. I think, and this is where I need some one to weigh in, that if I use a small 3V max dynamo I can connect the positive leg to a digital pin through a diode. If I am right the diode will allow positive current to pass through to the pin but not negative current. I then know if the pin reads HIGH it is spinning one way and if it reads LOW it is either spinning the other way or standing still. paired with the speed sensor I just built I can then know if I get LOW reading and a speed greater then zero I am spinning in the opposite direction. I am fairly positive the logic is right but am worried about the connections to my Arduino ( i am not in the mood for "sizzle-pop")

If someone could let me know if this is correct that would be great

*I tested the concept with a small servo and my multimeter and I do read zero volts in one direction and 3 - 5 volts in the other ( no negative reading still wondering if this setup would be safe for the arduino. also thinking I would need a diode on both legs so I don't dump +VDC onto the ground

A 3V dynamo or DC motor used as a generator with a diode should work, but you also have to make sure that the input voltage to any pin, digital or analog, on the Arduino does not exceed 5V (or 3.3 V if you are using a 3.3V version). Alternatively if the voltage does exceed the Arduino supply voltage, only a very small current can be allowed to flow. One way to ensure that is to put a protective resistor in series with the input pin, as shown in the attached. It is also a good idea to have a load on the generator to help reduce noise spikes. I’ve put in a 1K ohm resistor for that.

Finally, connect the grounds together.

sensor.png

i think i understand, the 1K is just for eating up noise and the other to prevent the current from going over 5V. other then that my setup should work.

I understand this method may seem a little "coconut radio" and I am sure there is a simpler way to do this so if you or anyone else wants to make any suggestions I am all ears.

twelch: I need to read what direction a shaft is spinning ... I have found some information on rotary encoders but have not found one that seems like it will be durable enough

A rotary encoder seems like a much more obvious solution than a motor/dynamo etc. What environment will it be in? I would have thought that even simply putting an encoder wheel wherever you were proposing to put the motor would give you a simpler and more reliable solution, but depending what you are trying to measure the rotation of there may be even better possibilities open to you.

How about a photo of the motor.

I have not purchased any actual hardware yet. This project is in its planning phases. What I am actually trying to do is build a device that demonstrates the principles of generating electricity. Our core audience is children under the age of seven so the device needs to present a robust reaction to even the smallest user. My thought is to build a device that has a wheel on it for the children to turn, the arduino can measure the RPM and direction of the wheels shaft and through the magic of mathematics convert that to the proper output so that different light and motors and bells all light up brighter, spin faster, or sound louder based on the direction and speed of the hand wheel. I have the physical design pretty much work out but I am a novice at best when it comes to micro electronics. I can in my mind see a device that I have encountered in the past that I think is what I want but do not know its name or what it actually does. I managed to build a sort of tachometer last night that can track RPM's but determining the direction is still an issue. The rotary encoders that i am able to find don't look like they could handle being spun all day everyday by 500-1000 small children.

*kudos to PeterH for using the term I was missing "encoder wheel". After a quick google search I realize I have encountered these before and that the "tachometer" I mentioned above is basically a primative version of this. I think the encoder wheel is the way to go but, again, my lack of experience haunts me. any suggestions on what type of encoder/wheel combo would be awesome.

Encoder wheel setups use some sort of emitter/detector (photo interrupter, magnet/hall sensor,,,,) to generate pulses which are used by subsequent circuitry (to, say, measure rotational velocity, or positioning). Make it easy and consider a photo interrupter and an encoder with just one shadow (or window, depending upon trigering strategy,, we'll use a shadow). When the shadow passes through the interrupter fixture, it blocks the I.R. beam and provides for the generation of a pulse (for simplicity forget about the second pulse when the shadow leaved the slot). You count that pulse over time and get a rudeementary rotational velocity. End of Encoders 101 class.

If you place two interrupters along the wheel, you can detect which gets interrupted first, and determine direction of rotation, and some other stuff, like speed and velocity changes,, all kinds of goodies. It just takes a little logic.

opto interupter (OPB704 or similar) or photo resistor (QSE114 or similar), or some such.
It will send out a light and that can be reflected and sent to a receiver.
use two receivers and a reflector on the shaft.
the receivers will signal the passing of the reflector.
the reflector could be white paint and the rest of the shaft painted black, or some such.

it will report A then B, then pause until the shaft rotates.
if it is running reverse, it will report B then A, then a pause.

all you need to know is which turns on first.

and, if you measure the time for one of the sensors, you can also know RPM.

all you need to know is which turns on first.

Wouldn't you also need to know which turns on second because you don't know the initial position or initial direction? INITIAL CONDITIONS. moving CW , A precedes B (IF AND ONLY IF STRIP NOT IN BETWEEN A & B on start up) moving CCW , B precedes A (IF AND ONLY IF STRIP NOT IN BETWEEN A & B on start up)

CASE 1: strip is clockwise of the B sensor but not in between A & B. moving CW, A is first. moving CCW, B is first. CASE-2: strip is in between A & B moving CW, B is first moving CCW, A is first

A can be first in both scenarios depending on initial direction.

I just finished up a rough version of my speed sensor, It uses a magnetic proximity switch and a magnet on the shaft. The build was easy, the programming took some work as I had to find away to debounce the input without slowing down the program it self in order to get relatively accurate results. Now accuracy is not a huge factor as everything is relative, If the program says 300 RPM's is the fastest I can go then that will be the point where I "conduct" the most "electricity" it doesn't mater what the actual speed is as long as I have consistency. I threw in the LCD screen from my starter kit and now I am mobile. I am going to build a stronger housing for a crank and shaft so I can have actual kids see how fast they can go and use those numbers for my baselines.

The remaining challenge is finding direction, the thing that I can't wrap my head around is using only two sensors to find this. as stated by raschemmel, the starting position will change the reading. now it has occurred to me that polling the sensors several times could provide a decipherable result but I need something that can provide a result in a single rotation. I think if I use three or four sensors I can create something similar to a rotary indexer and by polling all sensors twice I can determine direction.

assuming three sensors, If i take an initial reading of LOW,HIGH,LOW, i know on the second reading if the sensor 1 is HIGH its left or if sensor three is HIGH its right. there are only three possible starting points so it shouldn't be to intense to code.

You just need to use boolean flags to keep track of which sensor was first and which was second by setting the FIRST flag to TRUE after one of them is detected and setting the SECOND flag to TRUE when the second was detected. By using my previous post, IF FIRST flag ==TRUE AND IF SECOND flag ==TRUE, SENSOR detected = SECOND.

IF B==FIRST AND A==SECOND, DIR =CW IF A==FIRST AND B==SECOND DIR =CCW Then you have to check for first three detected sequence Is it B,A,B==> intitial positiion = between sensors A,B,A ==> initial position CCW of A , CW of B

Instead of asking the sensors (polling), what about having the sensors alert you (interrupts)?

Just commenting on the idea of using a motor as a generator to determine direction:

Connect one terminal of the motor to a voltage divider at Vcc/2. Connect the other, through the appropriate resistors and diodes to protect the Arduino and capacitor to smooth the signal, to an Analog input pin.

Motor spins one way, voltage>2.5V. Motor spins the other way, voltage<2.5V. You could connect a second Analog input to the voltage divider to get an accurate read of zero speed voltage.

Load the motor down with the right resistor across it, and you can probably get a reasonable indication of speed, too. The resistor should go right across the motor.

I just realized you can't do it with only two sensors because you can't distingquish direction without knowing initial position. If you have three sensors: that read A,B,C IF AND ONLY IF DIRECTION = CW

CASE-1 :INITIAL POS=CCW from A .CW from C A, B, C,==> DIR=CW CASE -2 INITIAL POS = CW from A, CCW from B B,C,A==> DIR = CW A, C,B===> DIR =CCW CASE-3 INITIAL POS = CW from B , CCW from C C,A,B====>DIR = CW B,A,C===> DIR =CCW CASE 4 INITIAL POSITION CW from C, CCW from A A,B,C==>DIR=CW C,B,A ===> DIR =CCW

First prize to Polymorph for thinking outside of the box!!

A rotary encoder is just two switches. It works by having the switches get activated in quadrature.

If you look at the output:

http://playground.arduino.cc/Main/RotaryEncoders

You can set up your own quadrature rotary encoder. Two optical disks rotated so as to be 90 degrees out of phase with each other.

I turned the box inside-out.

First prize to Polymorph for thinking outside of the box!!

DOOOHH !

Sort of a Wheatstone bridge reversed.

polymorph:
Just commenting on the idea of using a motor as a generator to determine direction:

Connect one terminal of the motor to a voltage divider at Vcc/2. Connect the other, through the appropriate resistors and diodes to protect the Arduino and capacitor to smooth the signal, to an Analog input pin.

Motor spins one way, voltage>2.5V. Motor spins the other way, voltage<2.5V. You could connect a second Analog input to the voltage divider to get an accurate read of zero speed voltage.

Load the motor down with the right resistor across it, and you can probably get a reasonable indication of speed, too. The resistor should go right across the motor.

That doesn’t sound right to me. A DC generator to turn in both directions must cause the voltage to change polarity, so voltage output of your ‘simple method’ would be some positive voltage in one direction depending on speed, and the same voltage but negative if driven in the opposite direction at the same speed. And as arduino analog inputs can not measure negative voltages, how could it work?