YES! I suggested that in post#5Look up astronomic timer. Given lat/long (I think just one), it "computes sunruse" and sunset".
If you want to do it using analogue methods google "window detector".
Les.
Hi thank you soo much the window detector is what i needed but it pluses high (11) for both charging and discharging (output pins of both opamps are not connected). I want to be able to distinguish between the pulses give charging 00 and discharging 11.I feel a need to apologize for some of the comments.
But beyond that, while your question is clear, you have not thought it all the way through. From the point of view of a single sensor circuit, sunrise and sunset are transient events, moments in time when the environment changes from one steady state to the other. Day and night are the two steady states. A LDR and one comparator will give you a signal that is (for example) high during daytime and low during nighttime. When properly adjusted, the illumination when the circuit output changes state will be in the middle of the transition periods when night is transitioning into day (sunrise) and vice versa. So one comparator gives you four signals:
Positive-going edge: sunrise
Steady state high: daytime
Negative-going edge: sunset
Steady-state low: night
It is up to the downstream circuits or PIC to interpret and act on these conditions.
The next layer of complexity could be one of several options, such as have the circuit make a pulse output during sunrise and sunset. Or, with the window comparator mentioned above, have a signal line that is high only during the sunrise period between full nighttime and full daytime.
Saying that you want to "detect states" is not enough. Expand your description of how you want the circuit to behave, how many output signals you want (such as separate signals for day and night), and what downstream circuits these signals are going to drive.
ak
Hi how can I use the window comparator to do detemine if the last state was dark or light . I initially left the two outputs of the window comparator open to do this but I get weired simulation results. My simulation results are not similar to the pictures I uploadedYou need to know whether the last "state" was dark or light before you can determine whether some intermediate light level is dawn or dusk.
You also need to worry about shadows, clouds, fog, rain, etc that will affect the amount of light hitting the LDR.
If you want to know the last state (day or night), then you need a latch. But if you want to know the current state, the two individual window comparator outputs (before they are combined) show the day/night state.Hi how can I use the window comparator to do detemine if the last state was dark or light .


Hi,If you want to know the last state (day or night), then you need a latch. But if you want to know the current state, the two individual window comparator outputs (before they are combined) show the day/night state.
A very common way to grow a window comparator is with two open-collector-output comparators, such as two sections of an LM393 or LM339. Because they are open-collector outputs, they can be tied together directly to a single pull-up resistor to form the "window" signal.
BUT, if you use opamps instead, and combine the outputs through diodes (a diode-OR or diode-NOR circuit), then the separate outputs before the diodes are steady-state day and night signals.
ak
Hi thank you,Use two photo diodes, one facing East the other West, this will detect sunrise or sunset or daytime, use two inputs to the micro..
If East is stronger than the West, then sunrise.
If both equal high daytime.
If West stronger than East, then sunset.
If both equal low, night time.
Thank you,Below is a schematic of a LM339 comparator using two of the four comparators. They are configured as a window comparator. Vsupply in this case is 12 VDC. The lower and upper limits are 4 volts and 8 volts. The outputs are tied as Analog mentions and R4 serves as a pullup resistor since the LM339 outputs are what is known as open collector.
Here is the circuit:
View attachment 200807
View attachment 200808
Comparing Vin and Vout you can see where Vout is only on (high) while the level is inside the window. Vin is just an increasing voltage (blue trace) which gets to 12 VDC, where it sits a few seconds then decreases.
The only way to remember or recall a last state is as Analog mentions, using a latch. The more features you want the more parts you add.
Ron
Show us the schematic and simulation results.When i connect the outputs of both opamps together (with or without a diode) i do not get a pulse like the one in the picture you showed, only small trianle pulses during simultion.
If this is going into a micro which micro? Placing a LDR and a resistor in series makes for a voltage divider. This has all been covered. Why not just run the analog voltage out of the divider into the ADC of the uC? Using a 10 bit ADC like most micro controllers have you simple scale it. All of this can be done simple using code so why are you wanting to use anything else since you plan to feed a micro controller? Again I'll ask which micro controller?why do i need to use diodes on the output if im connecting the output directly to a microcontroller?
I can put lightening in a jar...RE: SamR - in this question seems You are not an expert. As the physicist, environmentalist, captain, astronomer (but not as electronicst) I know better as well there are a crucial difference between those states I named (why then You are not pushing the knob named Goooooooogle??), but yes, You are true that for SIMPLE tasks there are no any BIG difference between those happenings, as the seconds or worst case scenarios few minutes are staying between `em.
My intention was to understand do the author realizes that difference and do his will is exact sub-second accuracy, ot just about choice between "about dark" and "about shiny". As if the will is exact detection, it is impossible on simple light measurement techniques, but the Solar position must be measured geometrically (teleccope, AI analyser etc).
