Components Required with eBay links
Wiring Diagram
Follow these steps to connect the components:
- Connect the anode (+) of the photodiode to the 5V pin on the Arduino.
- Connect the cathode (-) of the photodiode to one side of the 10kΩ resistor.
- Connect the other side of the resistor to the GND pin on the Arduino.
- Connect the junction between the cathode of the photodiode and the resistor to analog input pin A0 on the Arduino.
Code Explanation
The Arduino reads the voltage across the resistor, which is directly related to the current through the photodiode. This current varies based on the light intensity, allowing us to measure the light levels.
Key Functions
analogRead(pin)
: Reads the analog voltage from the specified pin (A0 in this case).map(value, fromLow, fromHigh, toLow, toHigh)
: Maps the input voltage to a corresponding light intensity value (optional).
Arduino Code
Below is the Arduino code to measure light intensity:
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = analogRead(A0); // Read the analog value from the photodiode
float voltage = sensorValue * (5.0 / 1023.0); // Convert analog value to voltage
float lightIntensity = map(sensorValue, 0, 1023, 0, 100); // Optional: map to light intensity percentage
Serial.print("Analog Value: ");
Serial.print(sensorValue);
Serial.print(", Voltage: ");
Serial.print(voltage);
Serial.print(" V, Light Intensity: ");
Serial.print(lightIntensity);
Serial.println(" %");
delay(500); // Wait for 500 milliseconds
}
Upload and Test
- Upload the code to your Arduino using the Arduino IDE.
- Open the Serial Monitor in the Arduino IDE (set the baud rate to 9600) to see the analog values, voltage, and light intensity displayed.
- Change the amount of light reaching the photodiode and observe the changes in the Serial Monitor.
Conclusion
This project demonstrates how to measure light intensity using a photodiode and Arduino. The light intensity readings can be further processed or displayed on an external screen for various applications like automatic lighting systems or light-sensitive devices.