# Combining 339 Dark Sensor Circuit with Counter Circuit

#### Ron H

Joined Apr 14, 2005
7,063
@Coach - Any comments on post 118?

#### CoachKalk

Joined Sep 20, 2011
141
@Coach - Any comments on post 118?
Ron - I have your circuit printed and ready. After wrestling practice tonight it is on like Donkey Kong!!!!!!

#### Ron H

Joined Apr 14, 2005
7,063
Ron - I have your circuit printed and ready. After wrestling practice tonight it is on like Donkey Kong!!!!!!
I was afraid you had missed it.

#### CoachKalk

Joined Sep 20, 2011
141
Here is a circuit I would like you to try. It has hysteresis, which causes the comparator to ignore non-monotonic changes in resistance when the LDR goes from light to dark and vice-versa, up to a point. If the fluctuations are too large, the circuit will still put out spurious pulses during light transitions.

In the attached circuit, when the LDR is illuminated, the voltage Vldr will be somewhere between 2.8V and 5.4V, depending on the amount of illumination (this is using your 300k and 800k measurements). The threshold at this time will be Vth(hi)=8.9V, because the comparator output is high.
When the LDR goes dark, Vldr=10V. This is considerably above Vth(hi), so the comparator output will go low, causing the threshold voltage to change to Vth(lo)=6.5V. When the LDR is next illuminated, the voltage will have to go below 6.5V before the output can again go high, which, of course, makes the threshold go back to 8.9V.

Another way of looking at it:
When the LDR resistance starts low and is rising, the comparator will switch when Vldr=Vth(hi). This will happen when the LDR resistance rises to about 2.9Meg.
When the LDR resistance starts high and is falling, the comparator will switch when Vldr=Vth(lo). This will happen when the LDR resistance falls to about 1.2Meg.

Therefore, variations in LDR resistance between 1.2Meg and 2.9Meg, up or down, will cause no change in the comparator output. Without hysteresis, changes in LDR resistance which cause the LDR voltage to cross the threshold multiple times during light transitions will cause spurious clock transitions.

If you use multiple LDRs and comparators, you will need a separate reference divider (R2, R3, R6) for each comparator, due to the feedback.

I have to say that I am not comfortable running the LDR at such low illumination levels. I seem to recall that it takes a long time for the LDR resistance to reach its final value, and I am concerned about consistency between units. You might need selected resistors R2, R3, and R6 for each comparator.
I come bringing news ... but not good news! I changed my circuit per your hysteresis circuit and this is what I saw:
1. The LDR was not nearly as sensitive to laser blocks. It wouldn't necessarily be a show stopper if all else was good, but I wanted to let you know how it compared to the other setup.
2. This is where the news goes south. The counters were jumping all over the place. Both on the laser block and laser clear. I was going to note the readings, but they were crazy - literally all over the place.
3. I used the same setup and fed it back into the 555 just to see the response, and it counted as expected. As long as the laser block was < RC Time everything was good. Still no count on quick blocks.

I am not saying I didn't mess up the connections, but I checked it many times and then fed it to the 555 as well.

#### Ron H

Joined Apr 14, 2005
7,063
Are you sure you didn't get the 339 input pins swapped?

#### CoachKalk

Joined Sep 20, 2011
141
Are you sure you didn't get the 339 input pins swapped?
Let's play a game of pretend.
And then let's pretend I was like "D'oh, forgot to even look at that, I was just changing/adding resistors - double checking locations!"
So, since we are pretending, let's say I went and switched the input pins and tested the circuit again.

I am not saying that is what happened, BUT if it did happen that way - I would come back and report your hystersis circuit is GOLD BABY, PURE GOLD!

THANK YOU!!!!!!

With your circuit, even though the 555 isn't needed for bounce now, could I still use it for a timed siren response? If I can and I have it set for say 3 seconds, would the counter still record counts if the kids blocked the laser during the siren?

#### thatoneguy

Joined Feb 19, 2009
6,359
With your circuit, even though the 555 isn't needed for bounce now, could I still use it for a timed siren response? If I can and I have it set for say 3 seconds, would the counter still record counts if the kids blocked the laser during the siren?
Glad that worked out OK for you!

For the Siren, yes, you can use the 555 to drive the siren ONLY. Just don't run the output of the 555 to the counter in addition to the siren, and you can set the siren to run for however long you'd like without affecting the counting circuit. Assuming it doesn't add noise to the power line, but you should have enough bypass caps in the circuit now so it shouldn't be an issue at all.

Try that, and report back on how it all works.

Of course, photos and the laser in a fog machine would be cool. As well as the working circuit/display.

And to answer an unanswered question you asked earlier: YES, Very Often LED Displays are covered by 50% or more Window Tint to make the numbers "Stand Out" more against a solid black background, in addition to attenuating any slightly dim elements.

#### Ron H

Joined Apr 14, 2005
7,063
Let's play a game of pretend.
And then let's pretend I was like "D'oh, forgot to even look at that, I was just changing/adding resistors - double checking locations!"
So, since we are pretending, let's say I went and switched the input pins and tested the circuit again.

I am not saying that is what happened, BUT if it did happen that way - I would come back and report your hystersis circuit is GOLD BABY, PURE GOLD!

THANK YOU!!!!!!

With your circuit, even though the 555 isn't needed for bounce now, could I still use it for a timed siren response? If I can and I have it set for say 3 seconds, would the counter still record counts if the kids blocked the laser during the siren?
Excellent!
I have another suggestion for the siren: If the laser is blocked for longer than the siren timeout, the siren will sound until the laser is unblocked. This is because you have (I assume) the 339 connected directly to pin 2 on the 555.
If you want to limit the siren to the RC timeout value, do it as in the attachment. This differentiates the trigger, so it will be gone long before the 555 times out.
NOTE THAT R1 HAS BEEN CHANGED TO 2.7K.
This is to minimize the effect of loading by the 555 circuit.

#### Attachments

• 33.1 KB Views: 17

#### CoachKalk

Joined Sep 20, 2011
141
Excellent!
I have another suggestion for the siren: If the laser is blocked for longer than the siren timeout, the siren will sound until the laser is unblocked. This is because you have (I assume) the 339 connected directly to pin 2 on the 555.
If you want to limit the siren to the RC timeout value, do it as in the attachment. This differentiates the trigger, so it will be gone long before the 555 times out.
NOTE THAT R1 HAS BEEN CHANGED TO 2.7K.
This is to minimize the effect of loading by the 555 circuit.
OK Ron, I am not saying this is as good as that guy on the news that paid $1100 for a storage unit and scored 500K in coins and gold, but let me tell you, it is really coming together. I have the RC Time @ 5 sec. and if the kids break the laser while the siren is going off, they get rung up again on the strike counter. I know you guys are probably pretty bored since I haven't been bothering you with a bunch of questions, so I figured I would throw one more out ... you know ... to ease your boredom! First, I will preface this question by saying the current set-up was/is good enough to make my 15 yo daughter laugh/cry under the pressure of the course - and she acts like nothing I do is cool! After seeing her go through the course, she mentioned and I also noticed that she did get away with what looked like a few significant blocks and the LDR didn't pick them up. I had commented when I first tried the hysteresis circuit that it wasn't as sensitive and without having someone go through the course it seemed fine. So, my question is - does the hystersis have any wiggle room to make the LDR more sensitive - or will that bring that stinky noise back in? Also, I am trying to figure out a good way to take a pic of the room filled with fog and the laser on, but it seems like cameras really prefer light to function so everything I have tried so far looks kind of like a black blob! #### Ron H Joined Apr 14, 2005 7,063 Going back to what I said in post 118: When the LDR resistance starts low and is rising, the comparator will switch when Vldr=Vth(hi). This will happen when the LDR resistance rises to about 2.9Meg. When the LDR resistance starts high and is falling, the comparator will switch when Vldr=Vth(lo). This will happen when the LDR resistance falls to about 1.2Meg. Keep in mind that, in this circuit, the counter only advances when the LDR makes a transition from below 1.2Megs to above 2.9Megs. This is because the counter advances on negative TRANSITIONS (remember that the comparator inverts). If the laser is interrupted, and the counter advances, she could walk the entire length of the beam, keeping it blocked, and the counter would never trigger again. You should really have an LED monitoring the clock input (maybe you do?), to see if it is remaining low after the transition. You can play around with the hysteresis by changing R6 to a 100k resistor in series with a 1Meg pot, but you won't be able to change the actual mean threshold voltage (the average of the upper and lower thresholds). We could probably design a more sophisticated circuit which has independent control of threshold "center" voltage and hysteresis, but it would require more parts, and some more design work. #### thatoneguy Joined Feb 19, 2009 6,359 Could always make different/"cheater" alarm go off if the output of the 339 was held low for over 5 seconds and add 100-ish to the score. (Add another 555...) Also, that scope is now$40, in case you were making a Christmas list, there's a new link.

--ETA: While I am editing, move some things over from anti-tamper burglar alarms. Something like a spinning disc in front of the laser emitter that has a couple slots, 180 degrees apart. The motor would spin fast enough that the beam would look solid, but it would be a train of pulses. Then add in a missing pulse detector between your comparators and counter (yeah, another 555 project), but it would prevent somebody from standing still and blocking it. When the pulse stream stops, alarm goes off as long as beam is blocked or 5 seconds, whichever is less.

FIRST, I guess we can get this one going, and you can add the other stuff later, after Santa Arrives. Without a scope, you wouldn't be able to tell if the LDR is reacting fast enough for the pulses, and would have to ... ahem.. start over, with phototransistors.

ETA2: On second thought, you wouldn't need to change much at all. Just change the alarm timer to continually go off (re-trigger) as long as the light is blocked.

Last edited:

#### CoachKalk

Joined Sep 20, 2011
141
Going back to what I said in post 118: Keep in mind that, in this circuit, the counter only advances when the LDR makes a transition from below 1.2Megs to above 2.9Megs. This is because the counter advances on negative TRANSITIONS (remember that the comparator inverts). If the laser is interrupted, and the counter advances, she could walk the entire length of the beam, keeping it blocked, and the counter would never trigger again. You should really have an LED monitoring the clock input (maybe you do?), to see if it is remaining low after the transition.
Funny you should mention the option of blocking and walking through! She tried to do her best Jedi light blocking moves to do that exact thing! That feature if actually ok - on several different levels. First, it would be obvious if someone was trying to be a cheater to do that on a regular round. Second, if the kids get too good at the regular course, I can switch it up and MAKE them try to get through by blocking the lasers!

You can play around with the hysteresis by changing R6 to a 100k resistor in series with a 1Meg pot, but you won't be able to change the actual mean threshold voltage (the average of the upper and lower thresholds). We could probably design a more sophisticated circuit which has independent control of threshold "center" voltage and hysteresis, but it would require more parts, and some more design work.
Honestly, this is NOT a huge problem. After some more thought, it may even be caused a bit by the fact I am still using 1 laser for the entire course. In the final version, each laser will be stronger, where now after the first 4, the rest start dimming (maybe dirty mirrors as well). I would hate to have you spend more time on a more complicated circuit when you have helped so much on this and it working. I will look into the option you mentioned and see what happens. Make no mistake, I am not going to far from what I have now - I don't want to screw something up!

#### CoachKalk

Joined Sep 20, 2011
141
Could always make different/"cheater" alarm go off if the output of the 339 was held low for over 5 seconds and add 100-ish to the score. (Add another 555...)
Holy out of my league Batman! That would be very cool, but remember, I am a NOOB!!!!!

Also, that scope is now \$40, in case you were making a Christmas list, there's a new link.
Hmmm .... I may be able to do that ... Thanks for the link!

--ETA: While I am editing, move some things over from anti-tamper burglar alarms. Something like a spinning disc in front of the laser emitter that has a couple slots, 180 degrees apart. The motor would spin fast enough that the beam would look solid, but it would be a train of pulses. Then add in a missing pulse detector between your comparators and counter (yeah, another 555 project), but it would prevent somebody from standing still and blocking it. When the pulse stream stops, alarm goes off as long as beam is blocked or 5 seconds, whichever is less.

FIRST, I guess we can get this one going, and you can add the other stuff later, after Santa Arrives. Without a scope, you wouldn't be able to tell if the LDR is reacting fast enough for the pulses, and would have to ... ahem.. start over, with phototransistors.

ETA2: On second thought, you wouldn't need to change much at all. Just change the alarm timer to continually go off (re-trigger) as long as the light is blocked.
Again - some of this sounds WAY over my head!!!!! I really think I can make the current one work. You guys that KNOW what you are doing can make REALLY cool stuff! Lucky dogs!

#### CoachKalk

Joined Sep 20, 2011
141
I know this thread has been dormant for many months, but the wrestling season is now over and I have got back on the horse. I did not give up, but I am not skilled enough to just dabble. I have to have time to let everything SINK in.

I have update my total circuit to reflect the hysteresis Ron H provided in post 118. I will try to get it uploaded here to let any new eyes get a feel for the project and also remind everyone else who has already helped me what in the world I was working on.

I am in the process of remaking the circuit on a larger proto board with the hopes of getting the entire project on one board. Hopefully I can manage to "remake" the circuit and have it work as before.

I apologize in advance for the many questions/problems I am sure I will be bothering you with in order to finally get to the finish line.