Pages: [1]   Go Down
Author Topic: Help with Photo Diode  (Read 1158 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,

I need help with connecting a photo diode to my arduino-mega (atmeg1280).
I'm using a photodiode form thorlabs http://www.thorlabs.com/thorProduct.cfm?partNumber=DET36A.
The problem I'm encountering is that when there is no light being pass through the photo diode I would like it
to output a value of 0 to the arduino.  However when I check the serial monitor it shows me that its receiving some sort of light.
I have connected the photo diode to analog pin 0 and ground. 

Code:
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
int diodePin = A0;    // Assign analog pin value A0 to diode pin
int diodeValue = 0; 
int intensity = 0;
int desiredValue = 75;
int pos = 0;
int differance = 0;

void setup()
{
  myservo.attach(10,650,2400);  // attaches pin 13 to the servo object with min period
  Serial.begin(9600);           //Set baud rate to 9600
 
 
}
 
void loop()
{
 
  delay(1000);
  do {
      diodeValue = analogRead(diodePin);                 // reads the value of the photo-diode (value between 0 and 1023)
      intensity = diodeValue;
      diodeValue = map(diodeValue, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
      intensity = map(intensity, 0, 1023, 0, 100);       // scale diodeValue between 1 - 100 for intensity of light         
     
      differance =(intensity - desiredValue);            // calculate the differance between desired value and actual value.
     
      Serial.print("Differance = "); Serial.print(differance);
     
      if (differance>0)                                 
        pos=constrain (pos+1,0,180);                   //rotate clockwise by 1 degree
      else if (differance<0)
        pos=constrain(pos-1,0,180);                    //rotate anti-clockwise by 1 degree
       
      myservo.write(pos);                              // sets the servo position according to the scaled value
      delay(150);                                      // waits for the servo to get there   
    Serial.print("      Servo position = "); Serial.print(pos);      Serial.print("             Diode  = "); Serial.println(intensity,DEC);
  } while (desiredValue!=intensity);                   //run while the intensity is not the same
 
   Serial.println("ACHIEVED");
   digitalWrite(13,HIGH);
   delay(5000);
   digitalWrite(13,LOW);
   delay(5000);
}

Thanks
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26248
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However when I check the serial monitor it shows me that its receiving some sort of light
The device is sensitive well into the infra-red spectrum - are you certain that the device isn't receiving any light?
How is the device wired?
You've shown a sketch that has lots of extraneous stuff like a servo - where is the basic test sketch and what does the output look like?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The photo diode is covered with a cap.  That's why I assume that there is no light going through.

The serial output that I receive is the following.
Code:
Differance = -6      Servo position = 0             Diode  = 69
Differance = 5      Servo position = 1             Diode  = 80
Differance = -6      Servo position = 0             Diode  = 69
Differance = -6      Servo position = 0             Diode  = 69
Differance = -6      Servo position = 0             Diode  = 69
Differance = 11      Servo position = 1             Diode  = 86
Differance = -6      Servo position = 0             Diode  = 69
Differance = -6      Servo position = 0             Diode  = 69
Differance = -5      Servo position = 0             Diode  = 70
Differance = -5      Servo position = 0             Diode  = 70
Differance = -5      Servo position = 0             Diode  = 70
Differance = -4      Servo position = 0             Diode  = 71
Differance = -4      Servo position = 0             Diode  = 71
Differance = -3      Servo position = 0             Diode  = 72
Differance = 14      Servo position = 1             Diode  = 89
Differance = -3      Servo position = 0             Diode  = 72
Differance = -3      Servo position = 0             Diode  = 72
Differance = -3      Servo position = 0             Diode  = 72
Differance = -2      Servo position = 0             Diode  = 73
Differance = -2      Servo position = 0             Diode  = 73
Differance = -1      Servo position = 0             Diode  = 74
Differance = -1      Servo position = 0             Diode  = 74
Differance = 1      Servo position = 1             Diode  = 76
Differance = 6      Servo position = 2             Diode  = 81
Differance = 7      Servo position = 3             Diode  = 82
Differance = 5      Servo position = 4             Diode  = 80
Differance = 4      Servo position = 5             Diode  = 79
Differance = 5      Servo position = 6             Diode  = 80
Differance = 4      Servo position = 7             Diode  = 79
Differance = 3      Servo position = 8             Diode  = 78
Differance = 8      Servo position = 9             Diode  = 83
Differance = 2      Servo position = 10             Diode  = 77
Differance = 1      Servo position = 11             Diode  = 76
Differance = 1      Servo position = 12             Diode  = 76
Differance = 1      Servo position = 13             Diode  = 76
Differance = 1      Servo position = 14             Diode  = 76


The purpose of this project is to reduce the intensity of a laser with a polarized lens.  The lens is connected to a servo motor which allows it to rotate.  The photo diode records the intensity of the laser after it passes the lens.  It will then compare the actual intensity to the desired intensity and rotates the lens until the desired intensity is reached.  The photo diode has 2 wires one which is connected to the analog pin and the other is connected to ground.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26248
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is the device wired?
Quote
That's why I assume that there is no light going through
Ever seen a Wratten 87 filter?
Looks opaque to the eye.
Not to IR.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a way to change the sensitivity so that it only detects visible light?
The way device is wired is the servo is connected to pin 10, power and ground and the photodiode is connected to analog pin 0 and ground.
Logged

USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 90
I’m no expert, but I play one on the Internet…
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

According to the datsheet (http://www.thorlabs.com/Thorcat/13000/13051-S01.pdf)the sensor will output 0 to 10V, which is too high for the Arduino input pin to measure directly (5V max), so you will need to build a voltage divider or similiar method to lower the output down to something less than 5V. Check out the voltage divider tutorial over at Sparkfun for more info : http://www.sparkfun.com/tutorials/207.

FYI - I think you should also clear up your code and print out the actual values you are reading from the input pin and not the mapped ones:
Code:
Serial.print("             Diode  = "); Serial.println(intensity,DEC);

should be
Code:
Serial.print("             Diode  = "); Serial.println(diodeValue,DEC);

It will be better to see the 0-1023 when troubleshooting.

willnue
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 29
Posts: 2590
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you connected load resistor 50 K ohm?
Input impedance analog pin is 100 M ohm. Dark current of the diode 0.6 nA
V = R x I = 0.06 V.
So , what you measuring right now, is just a "high" load off-set.
Voltage divider 25 k + 25 k would solve the problem.
« Last Edit: July 09, 2011, 07:32:22 am by Magician » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26248
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Have you connected load resistor 50 K ohm?
The Rload in the catalogue is 50 ohm.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Montreal
Offline Offline
Faraday Member
**
Karma: 29
Posts: 2590
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you are right, 50 ohm. Thanks.
Value is pretty low.
It'd make sense, if OP doesn't need fast response time (which isn't required to move servo),
to increase R up to 50 k ohm , may be more.
For high value resistors, susceptibility to EMI and higher noise level have to be considered.
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For the app cited, a filter (of the optical kind) would make sense... one that passes just light of the colour of the laser. This would reduce stray effects from...

lights on or off in room
sunlight coming in windows
etc.
Logged

Pages: [1]   Go Up
Jump to: