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.
#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