You're welcome. I have a few questions.
- Is it so hard to provide link to the encoder, so we can better evaluate your solution?
-you say the input goes to pin 2 and pin 3. Why two pins?
-an optical encoder often has a LED. How are you limiting the current to it (actually, you act as if it doesn't exist, which is suspicious)
-what is biasing the phototransistor part of your optical encoder?
-are you sure that the supply current of the optical encoder has not exceeded the capacity of the Arduino pins that you have chosen to power it with?
-Since your connections are unconventional (you made no mention of it until now), can you post your software and a hand drawn schematic, so we can verify that it does what it should?
-Here's the link.
-Two pins because I have two encoders, one for each.
-Mine doesn't seem to have any? Well, it doesn't emit any light at least.
-Well, this is what I'm trying to figure out, I think I have too much light coming sideways when I try to use the encoder with the robot. I'll do further tests after my exam tomorrow.
-No, I'm not, I followed an advice from a friend who used arduino for multiple projects.
-I didn't make any mention of it because at the start of the post (one week ago), I was trying to figure out how to make the wheel encoder work. I had only one encoder, supplied correctly to the 5V pin of the arduino and GND. A few days ago I used a ruler to block the light and it worked well. My programmation seemed good too. When I put back the arduino on the robot, I put back the motorshield on the 5V pin letting me with no supply for the encoders. My friend then told me to use another pin for supply because encoders draw so little current that it should be fine.
Also for this post, I wanted to know if I should have used INPUT or INPUT_PULLUP. I was wondering if it could bring me some issues. I wanted to do further tests on the encoder before posting again about it if it couldn't make it work.
This is my motorshield.
Here's the montage, I put some pictures cause I figure out it's maybe gonna be simpler to look at since I don't have other wires connected to the arduino than the one for the encoders. The blue ones are the output of the encoders. The red ones the supply. The black one the ground.
cattledog:
The output of your device is never floating, so INPUT will work, but the major problem is that your led emitter/sensor encoder is not really a digital device.
Pay attention to reply #4.
Some of your difficulties with these encoders were covered in your earlier thread
Issue encoder - #8 by MaxiMax07 - Sensors - Arduino Forum
I would recommend that you either get external hardware like a Schmitt trigger to process the output, or change the encoders for different led pair encoders which have built in digital conversion, or change over to magnetic(Hall Sensor)encoders.
I look for the definition of Schmitt trigger and it looks great. However I don't know where to buy one in Canada. I'll try, first of all, to make it work with blocking the light coming from sideways. Maybe paint the white piece of plastic with the holes. Then testing with the resistors to drop the voltage. If nothing works or if you tell me I should just get the trigger and not messing with the resistors, I'll go for it.