Photodiodes are semiconductor devices that convert light into electrical current. They are fundamental components in many optical sensing applications.
// Photodiode light measurement
const int photoPin = A0;
int lightLevel;
void setup() {
pinMode(photoPin, INPUT);
}
int measureLight() {
lightLevel = analogRead(photoPin);
// Convert to lux
float voltage = lightLevel * (5.0 / 1023.0);
float lux = voltage * 100.0;
return lux;
}