PHOTODIODE
CIRCUIT
By increasing and decreasing the lightning, we change the current that is prodused by the photodiode. This changes the voltage in the circuite, giving us a different analog input. When the light very dim there are 0 volts going to the pin, and we read 0. When the light is very bright there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
Code
(The following code will print in the serial the light measured by the Sensor)
(The following code will print in the serial the light measured by the Sensor)
int sensorPin = A0;
int sensorValue = 0; void setup(void) { Serial.begin(9600); pinMode(sensorPin, INPUT); } void loop(void) { sensorValue = analogRead(sensorPin); Serial.println(sensorValue); } |
Selects the input pin for the photodiode
Variable to store the value coming from the sensor Opens the serial gate Declares the sensorPin as an INPUT Reads the value from the sensor Prints in the serial the value the sensor measured |