Should I insert this code into my sketch and see what the real world results are? Or, will you be incorporating it into the code I provided?hi
This is my test code, using a potentiometer in place of the LDR, to simulate light and dark, works OK.
E
C-like:/* LDR Analog Input LDR GL5528 Jan 12 2025 ESP Bench testing the LDR >> ADC >> PIR enable limits */ int ldrPin = A0; // ADC input int adcCount = 0; int adcAvg = 0; int enbPIR = 0; // PIR detection Enabled when = 1 void setup() { Serial.begin(9600); // used for IDE testing Serial.println("ADC Counts for LDR Resistance"); } void loop() { // read the ADC count value created from the LDR voltage // take the Average of 10 readings, set readings delay to suit project for (int i = 0; i <= 9; i++) { adcCount = analogRead(ldrPin); adcAvg = adcAvg + adcCount; Serial.print(adcCount); // test only Serial.print(" "); // test only delay(200); } Serial.print("adcAvg= "); // test only adcAvg = adcAvg / 10; Serial.print(adcAvg); // test only // hysteresis if ( adcAvg > 600) { // dark enbPIR = 1; // Serial.print(adcAvg); // test only } if (adcAvg < 550) { // light enbPIR = 0; // Serial.print(adcAvg); // test only } adcAvg = 0; // clear AVG Count // Select if PIR is enabled or not if (enbPIR == 1) { Serial.println(" Dark"); // test only } else { Serial.println(" Light"); // test only } }






