Hi,
I'm trying to use a rotary encoder to track the position of a motor, but I have run into an interesting issue. The output lines of my encoder only put out 0.4v when running the encoder on 12v, and unmeasurable voltage when running on the Arduino's 5v.
The encoder I am using is a two phase magnetic rotary encoder with an operating voltage of 5-24v. I have two of them and they both act identically, so I am fairly confident it is not simply a dead encoder.
Has anyone encountered a similar issue? If not are there any rotary encoders in the $20-$30 range that you have had good experiences with? (Most of the guides online simply plug the encoder's wires directly into the Arduino; something I would love to be able to do).
Originally I ran the encoder off of the Arduino's 5v like all the guides show, but when it wasn't working I checked the output lines with a volt meter and saw no voltage. (After making sure my code was not the issue). I then connected the encoder to 12v and checked again with a volt meter and saw highs of around 0.4v, and lows of 0v. I tried to connect the output line to the Arduino while running the encoder off 12v, because I thought I might be able to use the highs and lows I saw on the volt meter. However, the Arduino read much lower voltages than the volt meter, and they were nowhere near consistent enough to do logic with.
I tried the internal pullup resistor in the Arduino while running the encoder on 5v, with no success. It only read high all the time. I also tried an external 1k pullup resistor once with no success either, but I never tried it again.
If there is any other information I'm missing here, please let me know and I will be sure to add it.
The Amazon page provides no useful information, and I was unable to find a data sheet by following the scant references on the product page. So, what functions did you assign to the different wire colors?
If the outputs are open collector or drain, it should work to power the encoder from the Arduino 5V output, with 10K pullups from the A and B outputs to Arduino 5V.
There really is no point in buying parts without a data sheet. I recommend sending them back to Amazon for a refund, and buying encoders from a reputable supplier who provides the full specifications.
I had green as phase A and white as phase B, with the yellow wire as a Z.
If you mean in the code, right now I am just trying to get enough voltage to be able to do logic, so I'm simply reading the value on analog 0, converting to volts and serial printing.
I agree there is no useful information on amazon, which is part of the reason I am so frustrated by it. I can't find good info anywhere on it either. But I see everyone else using similar encoders with no problem, so I find it hard to believe it is total garbage.
I was wondering about this, but I saw somewhere that putting power on the output lines can damage the encoder, so I've been reluctant to try it. Is there any risk in using a pullup resistor?
The resistor is required to limit the collector or drain current to safe values and to generate the voltage drop that is the output signal.
However, looking further at that Chinese web site, it is pretty clear that the Amazon page is misleading. That particular encoder, with markings E38H8G5-600Z-G24N appears to run on 24V only (the G24N being the key). See the right hand column of this screen shot:
Not sure what you have "read" and if you are going to assert such things on this forum you will absolutely need to be able to give the exact Web citation, but the point is that connecting power - a direct connection to the power supply - to an output line is indeed likely to be damaging. That is why @jremington says:
A pull-up resistor is a completely different matter. It does pull the particular pin up to the supply voltage, but if that pin instead pulls to ground, the resistor strictly limits the current. A 10k resistor to a 5 V supply will limit the current to 500 microamps which is a current that virtually any transistor can manage with consummate ease.
Thank you for the in-depth explanation. I will give the 10k pullup resistor a try.
Just to be clear, I was not trying to "assert" anything. As someone who is completely new to electronics, I was just trying to straighten out some conflicting information.
As a beginner in electronics, you should take to heart that having the manufacturer's data sheet is absolutely essential to making reliable, proper and safe use of the component.
Data sheets are legal documents and should completely describe the component's function, behavior under a range of conditions and options for use.
Connection diagrams and precautions for safe and reliable usage are always provided by reputable manufacturers.
Well, I found an interesting solution to this encoder problem.
So first I tried the 10k pullup resistors, with no success. The arduino only ever saw 5v. I was pretty much ready to give up on this encoder and buy a better one, when I stumbled across someone on another forum with a solution to a similar problem(Link: https://stm32duinoforum.com/forum/viewtopic_f_18_t_4024.html ). He had a similar cheap Chinese encoder, and upon taking it apart, he saw "a 7805 VR, after a bunch of 1k resistors in parallel and a rectf. diode". He said this means "it would NEVER work properly on 5v", because that voltage regulator needs at least 7v. So he bypassed the voltage regulator and ran the electronics on 5v directly from the microcontroller, and said it worked perfectly.
So I decide to open my encoder up, and sure enough there is a 7805 voltage regulator in my encoder as well. I tried his solution and attached a jumper wire from the encoder's Vin to the output of the voltage regulator, and it worked!
I am still using the pullup resistors, and the encoder now puts out perfectly square waves from 0v to 5v like it's supposed to.