Photo Interrupter and Encoder Discs


#1

Hi Guys,
Here is my method for using the wheel encoders with the photo interrupters.
Firstly a warning as I burned out a couple of photo interrupters and as they are infra-red you can’t tell without testing (I will highlight how to test this with a few basic parts and a bread board in another post). Be careful when soldering, put an alligator clip or something metallic on the legs close to the plastic housing to reduce the heat getting to the sensitive part. Thankfully I was able to get replacements through a local electronic store.
I super glued a small washer on to the center of the encoder wheel to give a screw something to hold against. Then I spray painted them black (just cause it seemed like a good idea).


I also use a small rubber ring under the washer to space it out from the axle by about a millimetre to help with spacing and alignment. These rings are listed as Black 4mm x 1.5mm Oil Resistant NBR Nitrile Rubber O Ring Sealing Ring


I also carved out the back and the front of the slot in the base board to give better clearance for the rotating encoder wheel. I marked out the position for 2 small holes on the motor mounting boards that where far enough away from the axle so as to give clearance for the encoder wheel. This is for the cable tie that I have used to hold the photo interrupter. I also had to carve a grove between the holes on the back to take the cable tie.



The wireing colours I used for my photo interrupters is Red for the positive side of the LED and Black for the negative. And Blue and White for the sensor. As shown below.


These hook up to the Photo Interrupter functional block on the Arduino shield as follows:
Red to 5V, Black to connector 2, White to Connector 3 and Blue to GND.
This is just the colour system I went with and is just a suggestion.


I also used Heat shrink over the legs and solder of the connections to insulate them, you could use tape or something else if you like.


Here is the test code I used to compare how far each wheel rotates in one minute (please note I have an offset of 17 on my left motor as it goes faster).

// Pin assignments
#define AIN1 3
#define AIN2 4
#define APWM 5
#define BIN1 12
#define BIN2 13
#define BPWM 11
#define STBY 6
#define WHEEL_LFT A0
#define WHEEL_RGT A1

// Constants for motor control functions
#define STEPTIME 600
#define STRAIGHTSPEED 200
#define TURNSPEED 120
#define TURNTIME 300

// Array to track current PWM values for each channel (A and B)
int pwms[] = {APWM, BPWM};

// Offsets to be used to compensate for one motor being more powerful
int leftOffset = 17;
int rightOffset = 0;

// Boolean (True or False) Flag for left wheel sensor
bool wheelLeft = false;
// Boolean (True or False) Flag for right wheel sensor
bool wheelRight = false;
// Variable to store left wheel flashes
int whlLeftCount = 0;
// Variable to store right wheel flashes
int whlRightCount = 0;
// Value of WHEEL_LFT read
int leftRead = 0;
// Value of WHEEL_RGT read
int rightRead = 0;

// Store the start time
unsigned long startTime = 0;
// 600000 = 1 minute in milliseconds
long interval = 60000; // length of time to run the test

// Function to write out pwm values
void writePwms(int left, int right){
analogWrite(pwms[0], left);
analogWrite(pwms[1], right);
}

// Stop the robot (using standby)
void stop(){
digitalWrite(STBY, LOW);
}

// Arduino setup function
void setup(){
// Initialize pins as outputs.
pinMode (STBY, OUTPUT);
pinMode (AIN1, OUTPUT);
pinMode (AIN2, OUTPUT);
pinMode (APWM, OUTPUT);
pinMode (BIN1, OUTPUT);
pinMode (BIN2, OUTPUT);
pinMode (BPWM, OUTPUT);
// Initialize pins as inputs.
pinMode (WHEEL_LFT, INPUT);
pinMode (WHEEL_RGT, INPUT);
// Initialize Serial Monitor.
Serial.begin(115200);
// Set startTime.
startTime = millis();
}

// Loop (code between {}'s repeats over and over again)
void loop(){

if (millis() <= startTime + interval){
digitalWrite(STBY, HIGH);
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, HIGH);
digitalWrite(BIN1, LOW);
digitalWrite(BIN2, HIGH);
writePwms(STRAIGHTSPEED-leftOffset,STRAIGHTSPEED-rightOffset);

leftRead = analogRead(WHEEL_LFT);
rightRead = analogRead(WHEEL_RGT);
if(leftRead <= 511){
if(wheelLeft != true){
wheelLeft = true;
whlLeftCount ++;
}
} else {
if(wheelLeft != false){
wheelLeft = false;
}
}

if(rightRead <= 511){
if(wheelRight != true){
wheelRight = true;
whlRightCount ++;
}
} else {
if(wheelRight != false){
wheelRight = false;
}
}

// Print wheel counts
Serial.print("Left Wheel Rotation: ");
Serial.println(whlLeftCount);
Serial.print(“Right Wheel Rotation: “);
Serial.println(whlRightCount);
Serial.println(millis());
Serial.println(””);
} else {
stop();
}
}

I hope that helps some of you guys out!

Cheers
Coyote


#2

#3

wrt to not being able to see the IR from the photo interruptors- the CCD in cell phone cameras can typically pick up IR and when the image is rendered on your phone, it’s in a wavelength that your eyes can pick up. I haven’t actually tried this with the LEDs that came with the Thimble kits, but a good way to see this is to point your TV remote at your cell phone camera and press buttons.

It also makes for a neat trick for trying to gauge the temperature of things like a heating element- even if there’s no visible glow (it’s not “red hot”), a cell phone camera can pick up the IR given off.


#4

Wow!
That is really high quality work. Thank you very much!


#5

Hi Guys,
As I said I would give some direction for testing the Photo Interrupter, so here goes.

All you will need is your bread board, some connector wire, 2 LED’s, a 220Ω and a 10kΩ resistors and a battery box.
Basically you use the LED’s to tell when current is flowing through the two different parts of the Photo Interrupter.

Here is my layout on the bread board. The right hand side with the green LED is testing the Infra-Red LED. This should light up as soon as the power is on. If not then the LED is cooked (I know this personally). The left side with the red LED is testing the transistor gate and will light up, then when something is placed in the opening between the Infra-Red LED and the sensor it will go out.



Here is a basic sketch of the layout


And the schematic


I found this worked well a few weeks ago when I was working on this stuff while holidaying and didn’t have my multimeter on hand.

Hope that helps any that are having problems with their Photo Interrupters.

Cheers
Coyote


#6

Hi @Coyote72,

I just used your test setup with a laboraty power supply tuned to 5.3V. The result is that the green LED is shining bright, while the red connected to the photo transistor is glooming so low, that I need to turn of the room light to see it. Are you sure, that 10K are correct? In my data sheet it says the forward voltage is 1.6 to 2 V. I would give it a 220 Ohm too.


#7

Hi DaVinci,
you are totally correct.
I didn’t check from even my photo of my testing a couple of weeks ago. I actually used a couple of 330 Ohm resistors, as that was what I had on hand.
I just used the numbers from the schematic that Thimble has up in the first bot module. My bad.
Good pickup by you.

Cheers
Lindsay


#8

Works! Thanks again for your test circuit and the other hints!


#9

Hello…in my case I haven’t actually tried this with the LEDs that came with the Thimble kits, but a good way to see this is to point your TV remote at your cell phone camera and press buttons.
It also makes for a neat trick for trying to gauge the temperature of things like a heating element- even if there’s no visible glow.

assemblage PCB