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

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
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
  }

}
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?
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
BTW Eric, the 60 second delay in setup is to allow the PIR to stabilize at LOW so the light sequence is not initiated when the unit is energized. I had a shorter delay and apparently the PIR was reading HIGH and the sequence would run whenever the unit was powered on. The 60 seconds solved this issue.
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
All,
For a buck convertor, I did utilize a circuit like the one below on one iteration of my PCB using the LM7805 regulator, but decided to go back to the MINI360. I was concerned about any heat dissipation or power loss, so went back to the MINI360. However, the circuit did provide 5v as expected. Do you all think I should go back to this approach? Yes, it would be cheaper.... and, would I use an LM2936 or stick with the LM7805?
1768246345205.png 1768246690588.png
 
Last edited:

eetech00

Joined Jun 8, 2013
4,709
Exactly what is Q4, the schematic shows SI2305-DS which is +/-8 Vgs.
Yes Q4, the RVP mosfet.
If you remove the zener/resistor, then both VDS and VGS need to be spec’s greater than 12v, not less or equal to 12 v. if you leave the zener/resistor in, then only VDS needs to be greater than 12v.
The battery voltage can be as high as 14v. I suggest the Si2321 or similar.
 

ericgibbs

Joined Jan 29, 2010
21,464
hi john,
Based on your LDR resistance values for Light and Dark limits, this plot shows the ADC counts for those limits.
E
Note:
These are the actual ADC Count values for 8 LDR's taken this morning at day break.
Note the wide spread in resistance for this sample of 8 LDR's
IMO you will have to do a SOT for the LDRs.

07:54:54.456 -> 785 821 866 899 945 861 874 927
07:55:54.396 -> 772 809 852 889 935 847 863 914
07:56:54.335 -> 751 788 832 874 920 828 844 896
07:57:54.308 -> 761 798 842 883 928 839 853 904
07:58:54.250 -> 761 798 842 882 929 840 855 908
07:59:54.186 -> 764 801 845 885 931 842 856 909
08:00:54.125 -> 754 792 836 877 923 833 848 901
08:01:54.078 -> 751 788 831 874 920 828 842 896
08:02:54.073 -> 737 775 819 865 909 815 829 882
08:03:53.995 -> 704 742 787 840 886 786 800 853
08:04:53.943 -> 676 713 758 817 863 756 774 824
08:05:53.923 -> 658 694 739 802 848 738 755 806



LDR limits1.gif
 

Attachments

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
Yes Q4, the RVP mosfet.
If you remove the zener/resistor, then both VDS and VGS need to be spec’s greater than 12v, not less or equal to 12 v. if you leave the zener/resistor in, then only VDS needs to be greater than 12v.
The battery voltage can be as high as 14v. I suggest the Si2321 or similar.
Thank you sir !!!
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
hi john,
Based on your LDR resistance values for Light and Dark limits, this plot shows the ADC counts for those limits.
E
Note:
These are the actual ADC Count values for 8 LDR's taken this morning at day break.
Note the wide spread in resistance for this sample of 8 LDR's
IMO you will have to do a SOT for the LDRs.

07:54:54.456 -> 785 821 866 899 945 861 874 927
07:55:54.396 -> 772 809 852 889 935 847 863 914
07:56:54.335 -> 751 788 832 874 920 828 844 896
07:57:54.308 -> 761 798 842 883 928 839 853 904
07:58:54.250 -> 761 798 842 882 929 840 855 908
07:59:54.186 -> 764 801 845 885 931 842 856 909
08:00:54.125 -> 754 792 836 877 923 833 848 901
08:01:54.078 -> 751 788 831 874 920 828 842 896
08:02:54.073 -> 737 775 819 865 909 815 829 882
08:03:53.995 -> 704 742 787 840 886 786 800 853
08:04:53.943 -> 676 713 758 817 863 756 774 824
08:05:53.923 -> 658 694 739 802 848 738 755 806



View attachment 361965
Are you recommending going back to the LM393 circuit that was working great using that 15k variable resistor?
 

ericgibbs

Joined Jan 29, 2010
21,464
hi john
No, the same problem will be present whichever method you use.
How many LDR's do you have on the bench to test for their resistance values?
E
 

ericgibbs

Joined Jan 29, 2010
21,464
Hi,
This is a clip of a test I am running using 8 LDR's, showing the ADC count.
The values are sampled once per second and an average of 10 results plotted.

It is a dull and wet day.
Note the difference in the basic LDR resistance, which is giving different ADC values.
E
EG 1969.png
 
Top