EDIT: We now have a laser tripwire kickstarter campaign up and running:Tripwire Kickstarter
Thanks for looking at my instructable. I'll be submitting this to the Mad Science Fair Contest, so if you found this document useful, please vote and rate!
This device is an extremely sensitive laser detection circuit that uses extremely little hardware, and very few lines of code. The user can shine a laser beam into the on board photo resistor (LDR - Light dependent Resistor) when the module is powered on. From there, when the push button is pressed, a small delay occurs, at which point the device becomes active. However, the circuit is not looking for a change in voltage caused by the change of resistance on the light dependent resistor, but rather a fast change in light (A breach in the laser beam, for example). Let me be more specific...
The typical LDR circuit uses a voltage comparator circuit. When the LDR is exposed to a lot of light, then the resistance across it will be very small; typically 10-1000 Ohms. When the LDR is exposed to darkness, the resistance typically becomes very high (Mega Ohms). When placed in series with a resistor of fixed value, such as a 10k resistor, you have a voltage divider circuit. From there, the voltage to the comparator circuit will read different voltages based on how much light is hitting the LDR. That method requires more hardware than I would like. I've been there, and I've done that. I wanted to be a little more original.
This method employs a coupling capacitor and an ADC (Analog to Digital Converter). The ADC is a feature included in the microprocessor that I'm using, which is the PIC10F222. I'll get to that in a minute. By coupling, I mean that when a sudden change in light occurs along the LDR, a tiny AC signal will be sent across a capacitor to the input of the ADC. This capacitor acts to block DC, and will only couple AC signals. This signal is always very small (In the millivolts), which is awesome!
This signal is then changed into a digital binary sequence that is then compared to a value in the programming. Once the circuit is active, the ADC is sampling thousands of times a second, waiting for a change on the line. When someone breaches the laser, the coupled signal hits the input of the ADC, and WHAM! Detection!!! BEEP BEEP BEEP! You'll have to see the video =)
When the the circuit catches someone breaching the laser beam, the on board buzzer will beep, and continue to beep until the user pressed the selection button again. The beeps are quite loud! There is a routine in programming that makes sure that when the user presses the button, that he/she must let go before activating the circuit again. The code is very simple, and you can change the sensitivity very easily by changing the value in the compare register.
I WILL TALK MORE ABOUT THIS IN THE SCHEMATIC DIAGRAM SECTION!!! Please see the demonstration below.
Step 1: Parts List
2x 10k Resistors
1x 100k Resistor
2x 0.1uF Capacitors
1x 10uF Capacitor
1x 7805 or 78L05 5v Regulator IC
1x PIC10F222 MCU
1x 2-Pin Terminal Block
1x 3v AA Battery Holder (For the laser)
1x 3v Laser (Any laser will do)
1x PCB (Empty)
1x LDR (Light dependant resistor, or photo resistor). Any will do for this application.
1x Monetary tactile Switch
1x 7v-25v power supply. A 9v battery will do just fine!
1x 5v Piezo Buzzer (Not seen in picture)
Step 2: Schematic Diagram
The Voltage Regulator:
You gotta love the voltage regulator. Most of my circuits work on 5v, so I need a chip that will step down the input voltage to a steady 5v. In this case, I've used the 78L05, which is a tiny 5v@500mA regulator. If you look at the 78L05 circuit, you will see a power connector on the left which is our input voltage source connection. The voltage here can be anywhere from 7VDC to 25VDC. You can actually have a higher input voltage, but I don't like to challenge the upper limits of the regulator capabilities. When you place a voltage higher than 7VDC at the input, the output will be a steady 5v. There is a smoothing capacitor (10uF) on the input line, and a decoupling capacitor (0.1uF) on the output line. The decoupling cap is used to shunt high frequency spikes to ground. Consider it a filtering cap. If you're using a battery to power this device, the input 10uF cap isn't really all that necessary. It is just good practice! Notice that the output has an arrow pointing up that is called VCC. This means that anywhere on the schematic where you see the same arrow will be 5v.
The LDR Circuit:
We have a 10k resistor (Fixed) tied to our VCC line. In series with that resistor is our LDR. The other end of the LDR is connected to ground. Notice that there is a 0.1uF coupling capacitor placed between the LDR circuit and a 100k resistor that is connected in parallel to ground. This resistor is used to ensure to bleed off any electronic noise. This is a pull down resistor. The second side of the coupling capacitor is also connected to pin#5 of our PIC10F222 microprocessor. That is our ADC pin. When a fast change in light hits the LDR (Breach of a laser beam) an extremely small AC signal will be coupled across the capacitor and into the ADC input pin. The capacitor cannot couple DC, only AC, so you don't have to worry about the DC component coming from the LDR circuit.
The Selection Switch:
Pin#8 of the PIC10F222 is connected to a 10k pull-up resistor, and also to a selection switch. When the switch is pressed down, the signal on pin#8 goes from HIGH to LOW. The pull-up resistor does two things. It keeps the input pin (Pin#8) at HIGH logic until the button is pressed, and it protects from short-circuiting. If you neglected the pull-up resistor, and you tied the left side of the button directly to the VCC line, when you pressed the button, your 5v source would short circuit to ground, which would likely hurt your power supply, and shut the circuit down completely. So the pull-up resistor acts to keep the input pin HIGH until you press the button, at which point the signal to the input line would go LOW. As well, it acts as a current limiting circuit to ensure that the circuit won't fail when you press the button.
The PIC and the Buzzer:
Pin#2 of the PIC is connected to VCC (5v), and pin#7 is connected to the ground line. This is the power supply to the PIC10F222. Pin#4 is an output that is dedicated to our 5v piezo buzzer. When that output goes high, power is sourced to the piezo, and it emits a loud warning. See the video for an example.
Pretty simple, no?
Step 3: Software
That file is here: http://electroniclessons.com/Laser.txt
However, I'm going to also comment on the main code, which is below. Try to follow along!
INITIALIZE ; START-UP ROUTINE
MOVLW B'1001' ; GPIO0=ADC-IN - GPIO1=BUZZER - GPIO3 = BUTTON INPUT
TRIS GPIO ; INITIALIZE
MOVLW B'01000000 ; ADC CONFIGURATION
MOVWF ADCON0 ; INITIALIZE
CLRF GPIO ; CLEAR ALL I/O
MOVLW B'00001000' ; NOT IMPORTANT TO THIS CODE
CALL LOOP3 ; CALL SHORT DELAY
BTFSC GPIO,3 ; WAIT FOR BUTTON TO BE PRESSED
GOTO START ; IF NOT, CAN AGAIN
CALL LOOP3 ; IF YES, A SERIES OF THREE DELAYS BEFORE SCANNING FOR A CHANGE IN LIGHT
MOVLW B'01000001' ; TURN ON ADC
MOVWF ADCON0 ; INITIALIZE
BSF ADCON0,GO ; TAKE ADC READING
BTFSC ADCON0,GO ; poll for reading to complete
GOTO WAITADC ; if not done, keep polling
MOVLW B'00000011' ; place 03H in compare register (Compare against roughly 60mv)
SUBWF ADRES,C ; compare instruction
BTFSC STATUS,C ; if ADC reading is more than 03H, a breach has been detected
GOTO NEXT ; if breach has been detected, to go NEXT routine
GOTO SCAN ; if not, take another ADC reading
BSF GPIO,1 ; turn on buzzer
CALL LOOP3 ; series of two delays
BCF GPIO,1 ; turn off buzzer
CALL LOOP3 ; series of two delays
BTFSC GPIO,3 ; has the button been pushed?
GOTO NEXT ; if not, beep again
; if yes, goto wait state
BTFSS GPIO,3 ; check to see if button is still being pushed
GOTO WAITSTATE ; if yes, check again
CALL LOOP1 ; if not, call a short delay, then reset
; LOOP3/4 work together as a long delay routine
Step 4: Kit Available
http://www.engineeringshock.com Just look for the kit section.
I design kits on the side, and I enjoy contributing to instructables.com. I hope that you found this instructable fun and interesting! Again, if you liked it, please vote and/or rate!
Thanks everyone! =)