Introduction: "You've Got Mail" Detector (aka Using a Photo-resistor)
Like most modern creations, this circuit was designed for complete laziness. I hated walking out to check my mail when either: 1) The mail person had not been to the house yet, or 2) They came and I got nothing. So, to fix this "problem" I connected a Photocell to an LED and a switch so that when the mailbox is opened, the LED will light up, and only by clicking the button will it turn off. So, please enjoy the video of it in action, and if you are interested in creating one yourself, here is how you can do it.
- Push Button N.O.
- 4013 Flip-Flop (or similar)
- Prototype board
- 2 - 10K Ohm Resistors
- 10 Ohm Resistor (for pull-down)
- NPN Transistor (I used a BC33716, but a NP2222 will do the job as well)
- 3 pairs of wire screw downs connectors
- Prototype board
- Power (I'm using 3-AAAs)
Step 1: Flip-Flops - They Are Not Just Cheap Footware
This is just a quick overview of what a flip-flop is. If you want more detail, please use your favorite search engine and "google" the heck out of it.
In short, Flip-Flops are a digital storage mechanism for a single bit. You can set the flip-flop to HIGH, and it will continue to output HIGH until you change it to LOW...thus, you are flipping and flopping the signal. There are several different types of Flip-Flops out there, and different flavors of each type. For example, you have a D-Type, T-Type, JK-Type, and others. Some have specific "set" pins to force a HIGH and some have "clear" pins to force a LOW.
A Flip-Flop uses a "clock" signal that tells the circuit to set the output signal to that of the input signal. A D-Type is called an edge trigger, which basically means the signal will change when the clock goes from HIGH to LOW, or LOW to HIGH (once again, depending on what type you have). T-Types simply toggles the signal on the clock cycle. A JK Flip-Flop basically has a truth table of how the J (set) and K (clear) signals. Definitely going to leave that to google.
So, with all of that said, I am using a 4013 D-Type Flip-Flow with a set and clear pin. Why? Because I did not have any others in my collection of parts. When I first created version 1.0 of this project, I had wired the output of Not-Q to the input of D. This basically makes the Flip-Flop behave as a Toggle when the clock cycle was sent. However, this was not working for me because if the photo-resistor was "activated" twice, the LED would turn off. (I use the term "activated" now, but the next step will cover the photo-resistor to understand what I mean, because that term is used very loosely.) So basically, if the mailbox was opened, it would turn the LED on, if when placing the mail into the box, the photo-resistor went dark and light again, the LED would turn off. Doh! That is not good. So, instead of using the photo-resistor to control the clock cycles, I changed it to use the SET pin. Now the photo-resistor will set the Flip-Flop to HIGH when it activates, and there is no way for it to set it back to LOW...that's what the push-button is for.
So, if you are familiar with Flip-Flops, you can change to the JK-Type and use it...as I mentioned, I only had the D-Type, so I used it.
Step 2: Photo-Resistors - LDR - Light Detecting Resistor - Photo Cell
There are so many different names for this little device, but they all refer to the same thing...it is a variable resistor whose resistance is varied by how much light hits the top panel. That's it!
When light hits the panel, magic happens, and the resistor will go lower in value, thus allowing the current to flow easier. When the resistor is in the dark or low light, the resistance is extremely high, so current will barely make it through. These little guys can go to 20k Ohms or more down to around 600 Ohms, so there is a very big swing.
So the trick to using them is to figure out how to use them as a gate-keeper to control the current. Now, when you think gate keeper, you instantly think "transistor" and "voltage divider" don't you?
This is why I used the term "activate" on the previous step. The circuit will need to sit idol until the photo-resistor gets enough light to cause the circuit to get enough voltage to the transistor, thus lighting the LED (or, activate the LED). See...very loose usage, but I think it gets the point across.
I'm not going to go very deep into explaining transistors and voltage dividers in this article, sorry.
Now let us start assembling this beast.
Step 3: Starting With the Push-button
The first step is the easiest. We are going to wire up the push-button that will control how the LED is turned off.
So, on your breadboard, push your push-button (normally open) into it. Normally open means that the circuit is "open" until the button is pushed. While the button is pushed, the current will flow through the closed circuit until the button is released.
These buttons typically have two pair of pins, one pair on opposite sides. So, simply attach the positive to one of the pins and the second pin put a wire in it, as it will go to the 4013 chip.
One issue we have is that the wire that goes into the 4013 that is dangling on your breadboard is going to be in a "floating" state...since the circuit is not closed, there is nothing going across that wire, so the IC will not know if it is supposed to be HIGH or LOW...because it is nothing. This is what the small 10 ohm resistor is for. You can use practically any resistor here, but I had a 10 Ohm handy. Connect it to the second pin to the negative.
So, what is basically happening is when the switch is open, the resistor is allowing the IC to get a LOW signal, so it is now no longer floating. When the button is pushed, then the positive will flow through and go to the IC pin (via the path of least resistance), thus sending a HIGH signal. Once the button is released, it goes back to the LOW. So this little resistor does a big job in keeping the IC input from floating.
Ok, so that was a lot of typing for just a push button...now let us take a look at wiring up the 4013.
Step 4: Connecting in the Flip-Flop and the LED
Now that we have the push button in place, it is time to wire up the Flip-Flop. So, add the chip to the board, and wire up pin 7 to ground and 14 to positive. As stated earlier, the 4013 is a pair of Flip-Flops, and we will only be using one. I picked the one on pins 8 to 13.
The 4013 has a pin that will "Reset" the Flip-Flop, which means that the output will enter the LOW state. So now take that dangling wire from your push button and connect it to the "Reset" pin 10. Now, when the button is pushed, the Reset pin will receive a HIGH signal and force the output to be Reset to LOW.
Additionally, the 4013 has a pin that will "Set" the Flip-Flop. So when this gets a HIGH signal, the output of the chip will be "Set" to HIGH. Thus, put a wire in Pin 8 (purple one in the picture) and let it dangle for awhile, we have to build what sets the pin.
Typically, a D-Type Flip-Flop is used as something triggered off of a clock cycle, however, I am not using it in this manner. I checked the rule books, and it doesn't say that you have to follow the rules! So, I just connected pin 11 for the clock directly to ground. This is to keep the IC from ever triggering the Flip-Flop to change.
Additionally, to keep the IC happy, the Data pin should have something going to it to keep it from floating. An old trick to turn a D-Type Flip-Flop into a T-Type is to take the NotQ output and connect it to the Data pin. Then when the clock cycle hits, the Flip-Flop output state is just toggled. And, since we do not like floating inputs, I just went ahead and connected Pin 9 directly to Pin 12.
The final step for the 4013 is to connect the output to the LED. So when the output is HIGH, then the LED will shine. So add an LED to your breadboard and connect pin 13 to the LED's anode and then connect the cathode to ground.
That's it..the IC is all set up, we just need to build the circuit that controls that one wire you have dangling from Pin 8 that sets the IC's output to HIGH and turns on the LED...
Step 5: Adding the Photo-Resistors, Resistors, and Transistor
The last step is to now create the part of the circuit to activate the SET pin on the Flip-Flop. On the 4013 IC, for an input to be considered HIGH, it must be more than 1/2 of the voltage going into pin 14. So if we divide the voltage in half, then the IC will think it is HIGH, so it needs to be just slightly offset from half, so that it will be LOW by default until something happens to sway the divider to push more voltage into the IC to make it HIGH.
To power the IC chip, we are going to use an NPN Transistor. Basically, an NPN Transistor is designed to work on the ground side of the circuits, which to new users will cause some confusion because they are typically working in the positive mind-set.
For the transistor, connect the emitter directly to ground. This is so that when the base gate opens, the circuit will close and the laws of physics are maintained.
Connect a 10k Ohm resistor to positive on one side. On the other side to the transistor's collector and also connect that last dangling wire from pin 8 of the IC. In the picture, this is the bottom resistor.
Now, connect the other 10k Ohm resistor to positive on one side, and on the other side connect it to the transistor's base and to ground. If you connect the batteries now, you'll see that the LED will be on. This is because the base and collector are both receiving the same amount of voltage. For the IC to have a LOW input, it must be less than 1/2 of the voltage.
So, on the breadboard, remove the ground on the top resistor and connect one lead of the photo resistor to the 10k Ohm resistor where the wire is going to the transistor's base, and then the other lead of the photo resistor to ground. You should have something like the picture above.
What you just created is what is called a voltage divider. The voltage going into the transistor is now split at two points, where the two resistors meet, and at the end of the two resistors. So what does this mean? It means that, while the photo-resistor is in the dark, the resistance is 20k Ohms or more, which means that the amount of voltage that is going to the transistor is not enough to activate the base to let the current be amplified to activate IC as a HIGH state, so it get's a LOW signal. Now, when the photo-resistor is exposed to light, the resistance of the photo-resistor drops, allowing more voltage to go to the base, which then allows more to go to the ICs pin, thus pushing the IC input as a HIGH state. When pin 8 goes HIGH, then the flip-flop is "Set" and the output goes HIGH, thus the LED goes on.
Now, it is important that I note why I used the both resistors at 10k Ohms. This is because I wanted the circuit to live on the edge of activating, which means that a lower light level is able to activate the LED. If you want a less sensitive circuit, then you would offset the two 10k Ohm resistors to different values, thus requiring the photo-resistor to receive more light, to lower the resistance to an even lower amount to turn the base on.
Whew, I know if you are new to all of this, it can be very, very confusing. I tried to make it easier to understand, but it just takes practice and a lot of reading. But, if you follow the design of the breadboard in the picture, you will have a working project!
Step 6: Done, Finally!
Now that you have put the breadboard together, give it some power and see how it works. I have embedded a video of the breadboard in action. The ambient light was low in my office, so I had to use a flashlight to activate the photo-resistor. Ignore my bad aiming of the flashlight, as I was holding the phone recording and blocking my view of the photo-resistor, so I could not see that I was missing it with the flashlight....Oh well, I hope you find it entertaining.
I've also included a prototype board that I put together for what is actually attached to my mailbox. The top screws are to go to the push button, the middle screws go to the photo-resistor, and the bottom screws go to the LED...they are the only one where the polarity matters.
I hope this project works for you, and I hope you have learned something new or have tweaked your interest into learning more on something.