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

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
hi john,
Please post a copy of your Tiny Code, I assume you used the Arduino IDE to create the coding??
If that is the case, I could write and post the switching point and hysteresis limits code for the Nano, which you could then convert to suit the Tiny,

I am now using a Nano for testing the GL5528 LDR's.
You stated earlier that the LDR resistance was centred around 35k at the Dark/Light switching point.?
Determine the resistance switching for On Dark and Off Light, and I will use those values in the Coding.

E

View attachment 361874
Hi Eric. That would be awesome! Yes, it is all done using Arduino. I upload the compiled code to the attiny chips using the Arduino IDE and a USB module for that purpose. No "Arduino" board like a nano is used. I believe the LDR resistance I measured was 80k, hand measured with FLUKE meter outside. I want to remeasure the resistance for both conditions one more time and will let you know. I will post the code shortly !!!
 
Last edited:

sghioto

Joined Dec 31, 2017
8,634
The voltage across the LDR is measure using an ADC input on the ATtiny which converts it to a number between 0 -255 on a 8 bit resolution input.
As the resistance of the LDR increases when dark the ADC number gets higher until it reaches a trip point in the code.
Lets say that number is 100 which instructs the micro that it's dark enough now to activate U2 when triggered by the PIR.
To add hysteresis instruct the micro to deactivate U2 when the ADC number falls below lets say 95.
It's basically the same as adding the hysteresis using the LM393 except it's done digitally.

I see a problem on the schematic, Pin5 on the micro with R2 is shown connected to the 5 volt supply on pin8.
 
Last edited:

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
hi john,
Please post a copy of your Tiny Code, I assume you used the Arduino IDE to create the coding??
If that is the case, I could write and post the switching point and hysteresis limits code for the Nano, which you could then convert to suit the Tiny,

I am now using a Nano for testing the GL5528 LDR's.
You stated earlier that the LDR resistance was centred around 35k at the Dark/Light switching point.?
Determine the resistance switching for On Dark and Off Light, and I will use those values in the Coding.

E

View attachment 361874
The code is attached. Thank you!
 

Attachments

ericgibbs

Joined Jan 29, 2010
21,464
hi john,
The Tiny85 has a10Bit ADC ie: 1023 counts.
What action do want to happen at the Dark to Light detection, operation and also at the reverse Light to Dark detection moment.?
E
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
The voltage across the LDR is measure using an ADC input on the ATtiny which converts it to a number between 0 -255 on a 8 bit resolution input.
As the resistance of the LDR increases when dark the ADC number gets higher until it reaches a trip point in the code.
Lets say that number is 100 which instructs the micro that it's dark enough now to activate U2 when triggered by the PIR.
To add hysteresis instruct the micro to deactivate U2 when the ADC number falls below lets say 95.
It's basically the same as adding the hysteresis using the LM393 except it's done digitally.

I see a problem on the schematic, Pin5 on the micro with R2 is shown connected to the 5 volt supply on pin8.
Thx for the information and I will take a look at the schematic discrepancy mentioned above.
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
hi john,
The Tiny85 has a10Bit ADC ie: 1023 counts.
What action do want to happen at the Dark to Light detection, operation and also at the reverse Light to Dark detection moment.?
E
I simply want the unit to power on at dusk and power off at dawn. Little or no power consumption and no light functions during daylight hours. Is that what you were asking?
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
The voltage across the LDR is measure using an ADC input on the ATtiny which converts it to a number between 0 -255 on a 8 bit resolution input.
As the resistance of the LDR increases when dark the ADC number gets higher until it reaches a trip point in the code.
Lets say that number is 100 which instructs the micro that it's dark enough now to activate U2 when triggered by the PIR.
To add hysteresis instruct the micro to deactivate U2 when the ADC number falls below lets say 95.
It's basically the same as adding the hysteresis using the LM393 except it's done digitally.

I see a problem on the schematic, Pin5 on the micro with R2 is shown connected to the 5 volt supply on pin8.
Better? Good catch, thx!!

1768150432720.png
 

ericgibbs

Joined Jan 29, 2010
21,464
I simply want the unit to power on at dusk and power off at dawn.
hi,
You cannot power down the unit, else the LDR D/L would not be working.
Do you mean you want the LDR detection circuit to be active 24/7 and the main unit to be dormant during the daylight hours?
ie: not to react to any external events?
E
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
hi,
You cannot power down the unit, else the LDR D/L would not be working.
Do you mean you want the LDR detection circuit to be active 24/7 and the main unit to be dormant during the daylight hours?
ie: not to react to any external events?
E
Yes sir, exactly !
BTW, I will be including a fuse as you recommended, but it will be on the + lead connecting to the battery. Thus, it is not included in the schematic. What size fuse (amperage) should I plan to use?
 
Last edited:

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
If this circuit is battery powered I see a lot of design changes that can lower the standby current significantly.
It will typically be powered by a standard "feeder" battery, which is a 12v 9Ah+/- battery like the Mighty Max ML9-12 below:
I have been powering the units with this type of battery with no issues. It uses a solar panel and controller for recharging during the day. The initial current is generally around 1 amp (stand by) and around 2 amps (cyclic). This will vary depending on the specific battery used.

1768153938482.png
 

eetech00

Joined Jun 8, 2013
4,709
I simply want the unit to power on at dusk and power off at dawn. Little or no power consumption and no light functions during daylight hours. Is that what you were asking?
Suggestion:

If "off" during the day, then just use a 24 Hour timer and motion detection, and not use a LDR?
Just set the timer for a repeating "on" duration (duty cycle).
The timer can be implemented in the ATtiny and used to "sleep" the unit. No LDR required.
 

Thread Starter

johnaustinkaty

Joined Jul 16, 2021
284
Suggestion:

If "off" during the day, then just use a 24 Hour timer and motion detection, and not use a LDR?
Just set the timer for a repeating "on" duration (duty cycle).
The timer can be implemented in the ATtiny and used to "sleep" the unit. No LDR required.
I prefer to keep the LDR as light levels should control instead of time.
 
Top