/*connection diagram
----------5v
|
|
resistor (10K)
|
|
----------A0
|
|
LDR
|
|
GND
*/
const int transmitInterval = 1000; // Time interval for transmitting data (in milliseconds)
const int ldrPin = A0; // LDR connected to A0
void setup() {
// Setup Serial Monitor for debugging
Serial.begin(115200);
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value
float voltage = (5.0 / 1023.0) * ldrValue; // Convert the analog value to voltage
int lux = (250.0 / voltage) - 50.0; // Convert voltage to lux (adjust these values according to your LDR and lighting conditions)
Serial.print("Lux: ");
Serial.println(lux);
delay(transmitInterval);
}