Dark sensor circuit using LM393 question.... unstable OFF/ON... flickering

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
R2 is not needed and would suggest replacing the mini 360 with a linear regulator since the load is miniscule.
Yes, I had done that on one iteration of my board and it provided a stable 5.0 v. I don't recall why I decided to go back to the mini.... Maybe the others can chime in on that ?? I will remove R2.
Thx
John
 

ericgibbs

Joined Jan 29, 2010
21,464
hi john,
As posted earlier:

While the LDR senses that it is Daylight in the monitored area, the main section of the unit will be dormant

Let's assume that it becomes Dark and the PIR is enabled, what sequence of events are triggered in the unit?

Then the PIR detects movement, what sequence of events are triggered in the unit and for what duration?

I am trying to build an idea of a flow chart for the unit coding.

E
 

ericgibbs

Joined Jan 29, 2010
21,464
hi johm,
Using the 8 Analogue pins of an Arduino Nano MCU and 8 off GL5528 LDR's with series 15K resistor, these are the readings, for room lighting.

The spread in the readings indicate that some method of adjustment or select on test will be required.
RED Max, GREEN Min values

I will run dawn/dusk tests asap.

The hysteresis function program works well on a Uno, but defining the Set Max/Min limits will require more work

E
EG 1962.png
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
hi john,
As posted earlier:

While the LDR senses that it is Daylight in the monitored area, the main section of the unit will be dormant

Let's assume that it becomes Dark and the PIR is enabled, what sequence of events are triggered in the unit?

Then the PIR detects movement, what sequence of events are triggered in the unit and for what duration?

I am trying to build an idea of a flow chart for the unit coding.

E
Hi Eric. My code is actually working perfectly (lacking hysteresis), but here is what happens:
Dusk falls
Unit is energized by LDR circuit
PIR ready, but not triggered yet
RA red LEDs turn on at 125 PWM
3UP LED illuminates very dim (PWM)
Unit remains in this state until motion is detected by PIR.
When motion is detected, RA LEDs blink at 255 PWM several times over 5 seconds, then return to solid at 150 PWM. Then the 3UP LED slowly brightens over 90 seconds to 243 PWM brightness. The 3UP holds at 243 PWM for 2 minutes (30 seconds are added if motion is detected during that 2 minutes). The 3UP then slowly fades back down to very dim and the sketch loops.
This sequence will loop each time motion is detected throughout the night. All function is disabled by LDR at dawn.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,464
When motion is detected, RA LEDs blink at 255 PWM several times over 5 seconds, then return to solid at 150 PWM. Then the 3UP LED slowly brightens over 90 seconds to 243 PWM brightness.
hi,
What is the purpose of this lighting sequence, who is going to see it?

You did say earlier that the project was to deter hog poachers.:)

E
 

sghioto

Joined Dec 31, 2017
8,634
Maybe it does.
The code tells when to activate the PIR when getting dark, it must have a line of code to deactivate when it gets lighter outside.
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
Maybe it does.
The code tells when to activate the PIR when getting dark, it must have a line of code to deactivate when it gets lighter outside.
Not in my current code. The LDR energizes the unit and enables the PIR at dusk and disables it at dawn. The PIR going HIGH initiates the code sequence outlined earlier.
 

sghioto

Joined Dec 31, 2017
8,634
Yes I understand that.
I don't fully understand the code posted as I'm not an Arduino user but it appears to me in the code posted that it simply enables the PIR when the LDR input pin is a digital High and disables the PIR when a digital Low which provides the hysteresis.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,464
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
  }

}
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
I know my light is unusual, but the dimming, brightening and blinking of the LEDs all have a specific purpose, which is irrelevant. I would love to eliminate several components as I am placing these parts by hand using a stencil, solder paste and a hot plate. If we can easily use the attiny for hysteresis using code, great, but if it creates new issues and headaches, I am fine with using the LM393 circuit established earlier as it worked just fine. I can't tell you how much I appreciate everyone's assistance in this effort.
John
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
Yes I understand that.
I don't fully understand the code posted as I'm not an Arduino user but it appears to me in the code posted that it simply enables the PIR when the LDR input pin is a digital High and disables the PIR when a digital Low which provides the hysteresis.
Are you referring to Eric's test code?
 
Top