I connected it on an analog pin and send result on serial.Into photocelule i roate an object with an hole on it but the result on my serial is wrong.
If i roatate twice i think i must a result on my serial 2 but the result is 34 or 36 or otherelese.
To give meaningful help we need instructions on how the device is/should be connected to arduino. The image just shows VCC,GND & OUT but is it a digital/analogue output, does it need pullup/pulldown resistors.
Maybe a picture of the way your shaft encoder looks. How many fins on the encoder wheel?
A description of how you have the device connected and your sample code (posted using the code (#) tags).
Hi and thanks for yout answer.
I'm not an electronist.
I think it is an analog sensor not a digital one , because if i connect it to a digital pin it doesn't send anything.If i connect on an analog pin it send some value, if it doesn't have any object into optocuplor it send me a 36 alternate 37 values. if i put something into optocuplor it send me values greate than 100.
My code is a simple cod for read an analog pin, because first i want to know what sensor send and after this i need to count it:
int sensorPin = A8;
int sensorValue = 0;
There is a slight error in your code with missing ')' or spurious 'delay('. I don't think you need the delay for testing or it should be on separate line
You say it does not work using digital pin but did the pin stay high or low, ambient light can effect some of these types of sensor. Try it in a darkened room or cover with you hand to mask most of the light and try it. Do you need a pullup/pulldown/inlinee resistor on the out pin? Did you get any datasheet of connection instructions with the device?
Hi and thanks again.
The"delay" it is wrong "copy paste" from my program.
i don't have a datasheet but i contacted the seller and he told me it is a digital pin and it works directly with arduino.
So i think it must write on serial 0 or 1 depends of the state of the optocuplor. Is it correct or not?
Many many thanks again.
tao13:
i don't have a datasheet but i contacted the seller and he told me it is a digital pin and it works directly with arduino.
So i think it must write on serial 0 or 1 depends of the state of the optocuplor. Is it correct or not?
At least we now know what type of signal to deal with. Looking at the board there appears to be 2 visible LED's. One marked power that I suspect is always on when power is applied (I assume your powering the board from the arduino). The other marked sensor I assume lights when the IR sensor beam is blocked or vice-versa. Connect the boards 'out' pin to pin 8 of your arduino and try the below code. When you block/unblock the sensor the value scrolling thru the serial monitor should hopefully change and the sensor LED should also go on/off.
Hi again to all.
This is ok right now.I see on serial 0 and 1.
Now I want to do a track with a slot to see if it can read engine speed but first i'll put on the machine holes.
Many many thanks.