I wanted a tripwire. This is just the circuit and the code, you can use it for quite a few things, like a trigger for a camera, or you could make it shut down your computer if someone crosses it.
When I have the time, I want to hook it up to an electric airsoft gun with a relay and have it shoot you when you break the beam. I suppose I'll add to the Instructable when that happens.
So let's start!
Step 1: Components Needed
-Arduino
-10k Resistor
-Photo resistor (Practically any value will work, the program will just need to be changed slightly)
-Laser Pointer
-Jumper Cables
-Alligator clips
Step 2: Circuit
Connect one leg of the photoresistor to Analog Input 0, and the other leg to +5v. Then, take the 10K resistor and connect one leg to GND (ground) and the other to Analog Input 0.
Also, I wired an LED to Digital I/O pin 13 to show when the laser beam is broken.
Step 3: The laser pointer
1) Remove the end cap and take out the batteries.
2) Inside there should be a spring, connect one of the alligator clips to this spring.
3) My laser pointer (and all of the others I have seen) have a completed circuit when the end cap is on, so I connected the other alligator clip to the bit of metal on the inside of the laser pointer.
4) Connect one of the alligator clips to GND, and the other to pin 4 (or any pin, so that you can control the laser).
5) Lastly, use masking tape to tape down the button so the laser pointer is always on.
Step 4: The Program
Pin 4 is the laser pointer, pin 13 is the LED, and the Analog Pin 0 is the photoresistor.
void setup() {
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);
}
void loop(){
digitalWrite(4, HIGH);
if(analogRead(0) < 750){
digitalWrite(13, HIGH);
} else{
digitalWrite(13, LOW);
}
}
This program is highly specialized to the room I'm sitting in right now, you will have to calibrate it to work in the lighting conditions you have. To do this, you must read the value of the photoresistor when the laser is hitting it. Then, measure it when the laser is not hitting it.
To do that, you can use this program, and then monitor the Serial Output.
void setup() {
pinMode(4, OUTPUT);
Serial.begin(9600);
}
void loop(){
digitalWrite(4, HIGH);
Serial.println(analogRead(0));
}
When the laser beam hit the photoresistor I had a value of around 850. When I stopped the beam with my finger, I had a value of about 700. So, I made the LED turn on when the value drops below 750 in my program, indicating the beam has been broken.
Step 5: Test! (and troubleshoot)
First off, you have to make sure that the laser pointer is on. If it is not, check the following:
-That the on button really is on.
-That you didn't connect the alligator clips the opposite way they should be. To fix this, change one from GND to Pin 4, and the other from Pin 4 to GND.
I hope this was mildly interesting!
I have a video of it in action below. Excuse the LED bargraph, I use it to display how many emails I have waiting for me and I didn't want to remove it...







































Visit Our Store »
Go Pro Today »




and wont run
please help ?
thanx
If you just copy and paste the code has there, it won't work.
void setup() {
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);
}
void loop(){
digitalWrite(4, HIGH);
if(analogRead(0) < 750){
digitalWrite(13, HIGH);
} else{
digitalWrite(13, LOW);
}
}
void setup() {
pinMode(4, OUTPUT);
Serial.begin(9600);
}
void loop(){
digitalWrite(4, HIGH);
Serial.println(analogRead(0));
}
Those two seperate sections of code need to be combined, as thse are both programs in their own right. From memory it should be something similar to this:
void setup() {
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop(){
digitalWrite(4, HIGH);
if(analogRead(0) < 750){
digitalWrite(13, HIGH);
} else{
digitalWrite(13, LOW);
Serial.println(analogRead(0));
}
}
Please not though that each of those segments of code were designed for a seperate task; one to simply trigger an LED when the beam is broken, the other to send data from the LDR to the computer so that Processing may be used. The combined code does both of these tasks, although you pobably don't need the serial transfer section if you had an error like that that you couldn't fix. Most of the people who will want to try this will be content with the first segment of code; that is, just turn on an LED or similar device when the beam is broken. The second piece of code is for more advanced users who wish to create a monitoring program in Processing (probably not you).
Hope this helped.
-Archive
What I want to achieve is to have a computer screen using the mirror function in Processing and camera that is triggered by a person entering the space. Ideally the camera should track the person so that they can never see their own face in the mirror but that might be a bit ambitious for my skils / knowledge level at present.
Thanks in anticipation,
Frank
from the motion and tracking thing. I bet you could modify his code for what your wanting to do.
http://gallactronics.blogspot.in/2011/11/laser-people-counter.html
Thanks
You're onto a very smart idea to make it frequency dependent. Then there would be a good reason to use the Arduino. (The project as it is can be done with a transistor, trimpot, couple of resistors, LDR and LED)
I do think that's a great instructable though.
Brian Whatcott
Place the sensor at the back end of a black tube to block ambient light.
if(analogRead(0) = analogRead(1)) {
digitalWrite(13, LOW);
it doesnt work though! :S but the principle is close right? lol
And I would turn on the light if they are within a certain percentage of each other, so it would be:
if(analogRead(0) - (.25 * analogRead(1)) < 0) {
digitalWrite(13, LOW);
}
Or at least something like that