Combining 339 Dark Sensor Circuit with Counter Circuit

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
As far as the display changing when the LDR is covered, I'd try removing the connection from the LDR circuit to the clock pin of 4553. Put a 10kΩ pull-up resistor on the clock pin and attach a N.O. momentary switch between the clock and ground. Now press the switch. Does the display change?
I have no idea what it means, but IT COUNTS!!!!! with the setup above! Now, what is the big problem with getting the same signal from the 339 output?
 

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
OK, this is what I have now. I have a single, .001 uF capacitor (not electrolytic). I have removed ALL reference LED's from the circuit.

The displays are now responding to the LDR, but not so good. I power up and touch reset to Vcc just to be sure I am starting from zero.

I have a bright light above the LDR that I can switch on/off. The light is obviously on when I power up. I switched the light off/on 5 times and recorded the display.
Power Up (Light On): 000
Off1: 21
On1: 31
Off2: 33
On2: 41
Off3:43
On3: 72
Off4: 119
On4: 136
Off5: 139
On5: 150

I know in one of my previous threads someone mentioned the possibility of the counter registering when the LDR came back lit versus when it was blocked, but this seems to be doing a weird combo of both - and def. not 1 at a time.

Electrolyic caps aren't made that low. Ceramic or mylar are and either will work fine.

As far as the display changing when the LDR is covered, I'd try removing the connection from the LDR circuit to the clock pin of 4553. Put a 10kΩ pull-up resistor on the clock pin and attach a N.O. momentary switch between the clock and ground. Now press the switch. Does the display change?
 

Ron H

Joined Apr 14, 2005
7,063
OK, this is what I have now. I have a single, .001 uF capacitor (not electrolytic). I have removed ALL reference LED's from the circuit.

The displays are now responding to the LDR, but not so good. I power up and touch reset to Vcc just to be sure I am starting from zero.

I have a bright light above the LDR that I can switch on/off. The light is obviously on when I power up. I switched the light off/on 5 times and recorded the display.
Power Up (Light On): 000
Off1: 21
On1: 31
Off2: 33
On2: 41
Off3:43
On3: 72
Off4: 119
On4: 136
Off5: 139
On5: 150

I know in one of my previous threads someone mentioned the possibility of the counter registering when the LDR came back lit versus when it was blocked, but this seems to be doing a weird combo of both - and def. not 1 at a time.
What kind of light is it?
I would use an LED or incandescent light, DC (e.g., battery) powered. AC powered lights have ripple in their outputs. I would leave the light on (switches bounce), and rapidly pass an opaque object, maybe a ruler, over the LDR and very close to it.
What sort of pulse widths do you anticipate at the 339 output? A lowpass filter between the 339 and the 4553 clock input might be appropriate.
 

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
This project is me trying to impress the kids and get a barebones version of a laser maze working. Before I added the counter, I simply had a buzzer hooked up to the 339 output. Every extra mirror in the house was used to bounce our 1 5mW laser around the game room and land on the tiny LDR. The kids would try to get from 1 end to the other without setting off the buzzer. That setup worked well except if the kids blocked the laser very quickly, the buzzer would not sound. (And they would stomp on the ground when they set it off and move a mirror - UGH!).

So, my next big idea was to add this counter to the 339 to basically keep track of how many times the laser was broke on their trip across the room. So, with that background and your suggestion below, I just did the following:
Game room completely dark and the 5 mW laser pointing at the LDR. Reset displays to 000. Even by blocking the laser as fast as I could, the counter still went up by 5 or 6 a pass. HOLY sensitive batman! A few times, I thnk it even decreased 5 or 6?

If the kids are feeling especially ninja, the LDR may not ever go dark. If I happen to make the course harder, it would still be a slow process of getting through/setting off the LDR.

I will search the forums to try to get a quick education on a low pass filter because like I said, I am green, green, green.

By the way, thanks again for your help.

What kind of light is it?
I would use an LED or incandescent light, DC (e.g., battery) powered. AC powered lights have ripple in their outputs. I would leave the light on (switches bounce), and rapidly pass an opaque object, maybe a ruler, over the LDR and very close to it.
What sort of pulse widths do you anticipate at the 339 output? A lowpass filter between the 339 and the 4553 clock input might be appropriate.
 

Ron H

Joined Apr 14, 2005
7,063
LDRs are really slow, on the order of 50 to 100 milliseconds. I don't know if that works for you or against you. You might want to try phototransistors. You might also want to add a lot of hysteresis to each comparator. I think you are getting multiple pulses at the edge of darkness, you should pardon the expression.
 

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
I was not sure what to do and I don't like doing nothing, so I hooked up the buzzer at the 339 output since the counter was at least being triggered. The buzzer is rated at 12V so it wasn't very loud and had the same delay as mentioned before, but I was able to get the counter to count 1 "LDR block" at a time with the buzzer hooked up. I did have to cover the laser slowly though, so the LDR may not be the best option if it is so slow to respond.

I will look into phototransistors, but I not familiar with those at all. I am not going to lie, I have no idea what you mean/how to accomplish adding hysteresis to each comparator. Would you be willing to offer a quick and dirty explaination on how that would be done and the possible benefit? I am just trying to figure out the next step. Hopefully I do not have to start from scratch - but I guess my 4553/4543 1" displays are working - as long as I can figure out some way to control those bad boys!


LDRs are really slow, on the order of 50 to 100 milliseconds. I don't know if that works for you or against you. You might want to try phototransistors. You might also want to add a lot of hysteresis to each comparator. I think you are getting multiple pulses at the edge of darkness, you should pardon the expression.
 

Ron H

Joined Apr 14, 2005
7,063
I was not sure what to do and I don't like doing nothing, so I hooked up the buzzer at the 339 output since the counter was at least being triggered. The buzzer is rated at 12V so it wasn't very loud and had the same delay as mentioned before, but I was able to get the counter to count 1 "LDR block" at a time with the buzzer hooked up. I did have to cover the laser slowly though, so the LDR may not be the best option if it is so slow to respond.
That's pretty strange. Will the counter count 1 at time when the buzzer is removed, if you block the LDR just as slowly? And what does "slowly" mean, in terms of actual numbers?

I will look into phototransistors, but I not familiar with those at all. I am not going to lie, I have no idea what you mean/how to accomplish adding hysteresis to each comparator. Would you be willing to offer a quick and dirty explaination on how that would be done and the possible benefit? I am just trying to figure out the next step. Hopefully I do not have to start from scratch - but I guess my 4553/4543 1" displays are working - as long as I can figure out some way to control those bad boys!
Is it the case that only one LDR can possibly be blocked at a time? If so, then we should be able to add hysteresis fairly easily.
In the actual maze, will the LDR actually be blocked as much as it is when you are testing it? Won't there be ambient light on it, or do you have each LDR mounted at the end of a black tube?
 

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
I will set up the buzzer and time the rate, but just sitting here at the puter and estimating, I would say I was covering/uncovering the laser about once per second. I guess that doesn't seem slow saying it like that, but I was comparing it to blocking it as fast as I could before.

Actually, I thought I stumbled onto something so I took the buzzer out and copied my procedure. No luck. The counter went crazy again.

I am not positive, but I am pretty sure when I had it set up with the 10k resistor and switch, the counter responded very well - 1, 2 ,3 ,4 etc... I was quite excited to see it working and do not remember the number jumping all over. Maybe my 339 is toast?

The current circuit only has 1 LDR setup, all other pins to ground for the sake of simplicity. I have checked it out with 2 setup and it worked fine (back when I was just using the buzzer only).

In the maze, only 1 LDR would be blocked at a time. I plan to use 4 because I am not confident I can reflect just 1 5mW laser across enough space. I want to have the ability to have up to 4 LDR's with 4 lasers if necessary. I am able to cover a fair amount of space with just our one, but I am limited with respect to setting level of difficulty with just 1 laser (too hard for my 8 yo, way too easy for my 16 yo).

The room will only be lit with a black light on 1 end. It will be quite dark with just the lasers and some fog from our new cheapo fog machine(yeah for after Halloween sales!!). I plan to have the LDR's behind some sort of reflector, hopefully allowing for some forgiveness with the laser.


That's pretty strange. Will the counter count 1 at time when the buzzer is removed, if you block the LDR just as slowly? And what does "slowly" mean, in terms of actual numbers?

Is it the case that only one LDR can possibly be blocked at a time? If so, then we should be able to add hysteresis fairly easily.
In the actual maze, will the LDR actually be blocked as much as it is when you are testing it? Won't there be ambient light on it, or do you have each LDR mounted at the end of a black tube?
 

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
Missed this answer last time. I am not sure if you mean will it really get as dark (blocked from light) or the number of times it will be blocked?

My trials with the room coompletely dark and just using my laser will be close to real conditions. The number of times will depend on how ninja like my kids are and how tough the course is.

In the actual maze, will the LDR actually be blocked as much as it is when you are testing it?
 

Ron H

Joined Apr 14, 2005
7,063
Missed this answer last time. I am not sure if you mean will it really get as dark (blocked from light) or the number of times it will be blocked?

My trials with the room coompletely dark and just using my laser will be close to real conditions. The number of times will depend on how ninja like my kids are and how tough the course is.
I meant the amount of background light. You answered that question. I am baffled as to why it works better with the buzzer than without. Does the 339 drive the buzzer directly? Do you have a link to a datasheet, or do you know how much current it draws?
 

thatoneguy

Joined Feb 19, 2009
6,359
I was not sure what to do and I don't like doing nothing, so I hooked up the buzzer at the 339 output since the counter was at least being triggered. The buzzer is rated at 12V so it wasn't very loud and had the same delay as mentioned before, but I was able to get the counter to count 1 "LDR block" at a time with the buzzer hooked up. I did have to cover the laser slowly though, so the LDR may not be the best option if it is so slow to respond.
Can you show a quick schematic of how exactly you added the buzzer to make it work?

What is the brand of the buzzer, just a Radio Shack piezo buzzer? It may have something to do with the load of the buzzer puling the output of the comparator all the way high or all the way low, which could eliminate the extra counts when the LDRs are partially lit by ambient light.

Just a thought before I sleep, sometimes they are good, sometimes they were already asked and answered. Thought I'd write it down just in case.
 

elec_mech

Joined Nov 12, 2008
1,500
Okay, so if the switch worked, you've learned the problem is in the LDR circuit, not the display circuit. This allows us to better narrow in the problem.

I can't explain it well, but hysteresis is a type of feedback from the output of the circuit to the input and is often used in op-amp circuits. For lack of a better explanation, the feedback is used to help the circuit perform better.

As others have mentioned, it appears you're either getting a bunch of pulses sent from LDR in one change of state (light to dark transistion) when you only expect one. This could be due to the op-amp or noise is being generated on the output line somewhere.

I suggest removing all but one LDR and op-amp from the output line going to the 4553. In your last posted schematic, you have four LDRs and four op-amps. Remove three of the op-amp outputs so you're left with one. Try your test again and let us know what happens. All I'm trying to establish is reducing the number of variables as much as possible so you can locate the problem.

It is possible you're triggering one op-amp, but the one or more of the other three is sending signals making your display appear to show random numbers. If you continue to have this problem after limiting yourself to one op-amp, look into adding hysteresis (what is the op-amp part number again?), but until you get one op-amp working correctly, keep the other three op-amp outputs disconnected.
 

Ron H

Joined Apr 14, 2005
7,063
I will set up the buzzer and time the rate, but just sitting here at the puter and estimating, I would say I was covering/uncovering the laser about once per second. I guess that doesn't seem slow saying it like that, but I was comparing it to blocking it as fast as I could before.

Actually, I thought I stumbled onto something so I took the buzzer out and copied my procedure. No luck. The counter went crazy again.

I am not positive, but I am pretty sure when I had it set up with the 10k resistor and switch, the counter responded very well - 1, 2 ,3 ,4 etc... I was quite excited to see it working and do not remember the number jumping all over. Maybe my 339 is toast?

The current circuit only has 1 LDR setup, all other pins to ground for the sake of simplicity. I have checked it out with 2 setup and it worked fine (back when I was just using the buzzer only).

In the maze, only 1 LDR would be blocked at a time. I plan to use 4 because I am not confident I can reflect just 1 5mW laser across enough space. I want to have the ability to have up to 4 LDR's with 4 lasers if necessary. I am able to cover a fair amount of space with just our one, but I am limited with respect to setting level of difficulty with just 1 laser (too hard for my 8 yo, way too easy for my 16 yo).

The room will only be lit with a black light on 1 end. It will be quite dark with just the lasers and some fog from our new cheapo fog machine(yeah for after Halloween sales!!). I plan to have the LDR's behind some sort of reflector, hopefully allowing for some forgiveness with the laser.
I just remembered seeing this post.
I highlighted a portion of the quote above. Grounding both inputs of a 339 will not disable it. Both inputs are still active, and since they are at the same voltage, the comparator(s) may be generating noise. To disable a comparator, ground ONLY the pin connected to the LDR. Leave the other pin connected to the pot.

EDIT: If you want to try hysteresis, this might help prevent multiple triggers on the same event.
 

Attachments

Last edited:

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
I am sorry about the delay getting back to this thread. I was away all weekend, but I am now back to pester you with my problems and beg for help.

It appears as though the report of my display circuit success was highly exaggerated. When I rewired the circuit using the NO Switch at the clock pin to verify my results, the displays showed the same "jumpy" advancement as when the LDR circuit was used to trigger the clock. I have added the display circuit only - just as tested with the NO PB and pull-up resistor. The displays advanced when the button was pushed, not when released OR when help down (did not continue to count). I wanted to note that point because of a repsonse I found with the siren added to the LDR circuit.

Here is the display circuit - as tested with NO PB.


Okay, so if the switch worked, you've learned the problem is in the LDR circuit, not the display circuit. This allows us to better narrow in the problem.

I can't explain it well, but hysteresis is a type of feedback from the output of the circuit to the input and is often used in op-amp circuits. For lack of a better explanation, the feedback is used to help the circuit perform better.

As others have mentioned, it appears you're either getting a bunch of pulses sent from LDR in one change of state (light to dark transistion) when you only expect one. This could be due to the op-amp or noise is being generated on the output line somewhere.

I suggest removing all but one LDR and op-amp from the output line going to the 4553. In your last posted schematic, you have four LDRs and four op-amps. Remove three of the op-amp outputs so you're left with one. Try your test again and let us know what happens. All I'm trying to establish is reducing the number of variables as much as possible so you can locate the problem.

It is possible you're triggering one op-amp, but the one or more of the other three is sending signals making your display appear to show random numbers. If you continue to have this problem after limiting yourself to one op-amp, look into adding hysteresis (what is the op-amp part number again?), but until you get one op-amp working correctly, keep the other three op-amp outputs disconnected.
Ron - I am not sure I understand what you are saying here. In all tests before this post, I have had ALL inputs/outputs of the non-used comparators tied to ground. I jumped in and tried the following - just becuase I had nothing else to try - I hooked the pot to the other 3 comparators and kept the planned LDR inputs (when they will be used) to ground. The results were the same, but based on the PB test of the display circuit, it seems to be with that portion, maybe not the 339 portion.
I just remembered seeing this post.
I highlighted a portion of the quote above. Grounding both inputs of a 339 will not disable it. Both inputs are still active, and since they are at the same voltage, the comparator(s) may be generating noise. To disable a comparator, ground ONLY the pin connected to the LDR. Leave the other pin connected to the pot.
I have made a short video that will hopefully explain what I am trying to describe below, but it will take awhile to upload so I will also describe it here.
The follow 12V Pulse Siren was added to the 339 circuit.

Heavy Duty 12V Pulsed Output Sounding Siren, Ideal for Outdoor
Mounting and with very attention getting Sound.
Part Code: DSS110MP12VIP67B
Rated Frequency: 3,000Hz
Operating Voltage: 8 - 15Vdc
Tone: Pulse
Sound Pressure Level(30cm): 110dB @ 12Vdc
IP (Waterproof) Rating: IP67

The siren was added directly to the 339 output pin. Red wire at output pin and black wire to ground.

Here are the results:
Quick cover of LDR - siren make quiet tone, no response from displays.
Slower cover of LDR - siren makes same quiet tone, but also a "cracking" sound. Everytime the siren makes the cracking sound, the display counts by 1.
LDR Covered for Extended Time - siren would cycle through the "pulse" and generate the toone/crack each time. The display counted each "pulse" without the jumping around noticed with the NO switch at the clock pin.

I know my description is not the best, but when the video is finished uploading I will update this thread with a link.

Basically, it seems as though my display circuit is messed up, but that is the one almost straight from the 4553 datasheet.

Comments? Suggestion? No, telling me to go away is not allowed.
Thanks in advance for your help.
 

thatoneguy

Joined Feb 19, 2009
6,359
Do you have a 0.1uF cap between power and ground on every IC

Here's Why

The way you describe the behavior, the comparators are changing states rapidly unless there is a load on the output. To verify, try a 330Ω resistor in series with an LED to ground the 339 output. See if the behavior changes.

Also, ensure you have a largish (470uF) cap across your power supply lines.

What could be happening is when the 339 switches, the voltage it is receiving drops, causing it to switch again, when adding a load, you are adding a form of stabilization on the 339 by drawing a lot of current. Adding a 0.1uF cap across the power pins may help (comparators and display ICs, all ICs), as well as the hysteresis schematic RonH posted above.
 
Last edited:

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
All of the IC's have the bypass caps in place.

I am not sure where you are suggesting the 470 uF cap across the power supply? Is this in addition to the bypass caps at the IC's?

I def. plan to add the hysteresis schematic Ron H provided, but it seems like my display cicuit (even without the 339 portion) is somehow way hyperactive on a single press of the NO push button. Unless you guys (everyone helping me on the forum) suggest otherwise, I just hope to get the display circuit working with the NO push button on the clock pin of the 4553. THEN, hopefully/maybe the 339/LDR circuit can replace the NO push button and I can roll on down the highway.

Here is the video. I know I just talked about leaving the 339 out until the display circuit is working, but this video shows the effect of the pulse siren.

Do you have a 0.1uF cap between power and ground on every IC

Here's Why

The way you describe the behavior, the comparators are changing states rapidly unless there is a load on the output. To verify, try a 330Ω resistor in series with an LED to ground the 339 output. See if the behavior changes.

Also, ensure you have a largish (470uF) cap across your power supply lines.

What could be happening is when the 339 switches, the voltage it is receiving drops, causing it to switch again, when adding a load, you are adding a form of stabilization on the 339 by drawing a lot of current. Adding a 0.1uF cap across the power pins may help (comparators and display ICs, all ICs), as well as the hysteresis schematic RonH posted above.
 

thatoneguy

Joined Feb 19, 2009
6,359
With the pushbutton setup to test the counter, try adding an RC circuit to debounce the switch and see if it counts multiple times on each press then.
 

Ron H

Joined Apr 14, 2005
7,063
LM339 is not capable of driving a high-powered siren. Ditch that Idea.
You may need more than an RC circuit to debounce your test switch.
 

Thread Starter

CoachKalk

Joined Sep 20, 2011
141
The siren would be great, but def. not necessary. I just wanted to show what I was using and the effect it had on the 339 circuit/display circuit interaction. I was hoping the results would spark an idea about what the siren was doing to the display circuit to cause it to count by 1's. I will search out RC cicuits next ... the journey continues ...

LM339 is not capable of driving a high-powered siren. Ditch that Idea.
You may need more than an RC circuit to debounce your test switch.
 
Top