const int LDR = A0; // analog pin to which LDR is connected const int LED = 13; // pin to which LED is connected const int sensitivity = 50; // setting the light sensitivity int LDRValue = 0; // variable to store LDR values int threshold; // light sensitivity threshold float voltage; // variable to store voltage void setup() { Serial.begin(9600); // start the serial monitor with 9600 baud pinMode(LED, OUTPUT); // configure LED pin to behave as output threshold = analogRead(LDR) - sensitivity; // set light sensitivity threshold } void loop() { LDRValue = analogRead(LDR); // read LDR value Serial.print("Raw Rate: "); // print text Serial.println(LDRValue); // print value to serial monitor float voltage = LDRValue * (5.0 / 1023.0); // convert analog reading (which goes from 0-1023) to a voltage (0-5V) Serial.print("Voltage: "); Serial.println(voltage); Serial.println(); if (LDRValue <= threshold) // if the LDR reading is lower than the threshold { for (int i = 0; i <= 50; i++) { // blink LEDs digitalWrite(LED, HIGH); delay(50); digitalWrite(LED, LOW); delay(50); } delay(1000); threshold = analogRead(LDR) - sensitivity; // set light sensitivity threshold delay(1000); } else { digitalWrite(LED, LOW); } }