Introduction: Arduino Laser Detector With Keypad

About: hmm lets see... my name is Thomas, but u call me what you like, Thomas Tom, Tommy, TJ or even THUGALIOUS!! lol. I love to hang out with friends anytime and do stuff with others. I enjoy playing baseball, baske…
Hello everybody!!!
I have been messing around with a few components and my arduino. I figured out this project last week and just had to share it with all of you. What it is, is a laser beam hitting a  photo cell. The arduino reads the photo cell and when it detects the voltage level is below a certain amount, the beam must be broken while sounding an alarm. The alarm stays on until you punch in the code you have set up to the keypad in. Once the correct code is typed in, the arduino turns of the buzzer and gives you 15 seconds ( or what ever you set the delay time to) to reset the laser beam. You are able to change the code if you like. The steps are very easy to follow and i hope everyone makes one!!!

Step 1: Materials

You will need a few components to make this project. Here is the list and the links to were i got them. Everything will cost around $40

http://www.radioshack.com/product/index.jsp?productId=2062599
      1 x 5V regulator
http://www.radioshack.com/product/index.jsp?productId=2062549       1 x red/green LED
http://www.radioshack.com/product/index.jsp?productId=2102845       1 x PC board
http://www.radioshack.com/product/index.jsp?productId=2062347       5 x 10K resistors
http://www.radioshack.com/product/index.jsp?productId=2062281       1 x Project enclosure
http://www.radioshack.com/product/index.jsp?productId=2062395       1 x 5V buzzer
http://www.radioshack.com/product/index.jsp?productId=2062558       1 x led holder
http://www.radioshack.com/product/index.jsp?productId=2062338       1 x 10 Ohm resistor
http://www.sparkfun.com/products/7942                                                      1 x DIP socket 28 pin
http://www.sparkfun.com/products/9217                                                      1 x Atmega328
http://www.sparkfun.com/products/9420                                                      1 x 16MHz resonator
http://www.sparkfun.com/products/9088                                                      1 x Photo cell
http://www.sparkfun.com/products/8653                                                      1 x 12 button key pad
http://www.sparkfun.com/products/8375                                                      2 x 0.1 uF capacitor
http://www.sparkfun.com/products/115                                                        1 x female header
http://www.sparkfun.com/products/8588                                                      1 x Diode


Now were also going to need a laser. I have listed a very GOOD one and VERY cheap in cost laser. You can use any laser you want to, but if you don't have one, these work GREAT!!!
http://cgi.ebay.com/650nm-5mW-Red-laser-module-CROSS-3VDC-9mm-X-20mm-/160341335168?pt=LH_DefaultDomain_0&hash=item2555169c80

http://www.sparkfun.com/products/10356      or     http://www.sparkfun.com/products/8165  get one of these

also some spare wire, small mirrors, hot glue gun, solder, and a soldering iron.


 you can get all theses at Sparkfun and Radioshack

Now if you look at the list, you'll notice there is no switch to turn this device on and off. If there were to be an off and on switch, the person that sets of the alarm would just have to simply turn the device off. That defeats the purpose of the keypad to turn of the buzzer. You can add a switch if you like, but i'm not going to. To turn this off, your going to have to unplug the adapter from the wall.



Step 2: Stand Alone Arduino

Before we even can start programming or hoking up the component, we need to make a stand alone arduino. Get the Atmega328, DIP socket, resonator, PC board and some wire. 


Step 3: Resonator

Next we are going to want to solder on the resonator.

Step 4: Regulator Part 1

now lets solder in the regulator. Put the regulator DIRECTLY under the resonator. 

Step 5: Headers

now the headers lets us reprogram the chip if you have the Arduino USB Serial Board

cut off a 4 pin header and a 5 pin header. Make sure you cut on one extra header ( this will give you some room for mistakes ) then sand off the extra, because it's VERY hard to cut EXACTLY 4 and 5 pins without a mistake.

after you have them cut out, solder them on!!!


Step 6: Power and Ground

this was actually supposed to be done on the 2nd step but i forgot. This is NOT needed, but makes this project easier to do. Color the top power line red and the bottom black.

Step 7: Pull Down Resistors

The next thing to do is install pull down resistors. These are need because when a button on the key pad isn't pushed down, the arduino aromatically makes the pin high. A 10 K resistor pulls the high signal to a low signal. Put a 10 k resistor on pin 6, 7, 8 and 28.

Step 8: Reset Pin Anybody???

now were going to solder the last 10k resistor and the capacitor to the board. These components automatically make the board reset when coding. Solder the 10k resistor to the reset pin to power. Solder the capacitor from the FAR RIGHT pin on the header to an open pin ( I soldered it to the pin next to it )

Step 9: Programming Wires

Now we have all the components into the bread board to have a stand alone arduino. Now the fun part begins. We need to solder jumper wire to all the components to power and arduino pins....fun fun NOT lol. This in my opinion is the boring is part, but it has to get done. This step will start with the headers. We will need 5 jumpers. power, ground, RX, TX and reset pins. I'll have a picture for every wire soldered in. 

The ONLY wire on the 5 pin header that needs a jumper is the one with the capacitor. Run a jumper form the end of the capacitor to the reset pin on the arduino.

The first pin on the 4 pin header goes to the third pin on the arduino ( the TX ).

The second pin on the 4 pin header goes to the second pin on the arduino ( the RX ).

The third pin on the 4 pin header goes to power.

The last pin on the 4 pin header goes to ground.

Step 10: Power

The next thing to make the standalnoe arduino is to hook up power to the thing. Pins 7, 20, 21 go to power. Pins 8, 22 go to ground. The picture really doesn't show you step by step so just give power to the pins i listed above.

Step 11: Resonator

when the words on the resonator are FACING you, the left pin goes to pin 10 on the atmega. the middle one goes to ground. The right one goes to pin 9. SOLDER THEM!!!

Step 12: TEST RUN

Time for a test run!!! First put in the atmega on the dip socket. Then plug in you usb board into the headers of the board and plug it into your computor. Put a basic code to blick an led on pin 13. Upload it and put the contacts of the led to the board. If it blinks, you did everything correct...if not, then you messed up. If you messed up, go back and look at the step again. You might have a short out, or put the atmega in the wrong way.

Step 13: Regulator Part 2

We are now going to go back to the regultor again. Now when the words on the regulator are FACING you, the left pin is the input, the middle is ground, and the right one is your output. First solder the middle pin to ground. Then solder the right pin ( output ) to the diode. Then the other end of the diode to an open pin. NOTE: In the picture i soldered the diode right to power. However, when i went to go test it it didn't work. So just solder your diode to an open pin, NOT POWER.

Step 14: Grounding

Now were are going to want to ground the resistor we put in earlier.

Step 15: Enclosure

We are now done with the board until we get enclosure ready. The enclosure is going to have the buzzer on top, the keypad in the middle, the led on the bottom left and the phot cell on the bottom right. First thing we have to do is find to middle of the box. Simply draw to lines form corner to corner. Once you find the middle, put the cover the long way up. Then messure left and right 2.5 cm on both side to give you 5cm total. Then messure up 3cm top and bottom to give you 6cm total. After you have toses, start cutting it out.

I first put 4 holes ( using a drill ) in the corners. This makes it super easy to cut out. 

after you get th keypad cut out messur down 1.5 cm. Then messuer over 1.5 cm on both side. On the left side, drill a 1/4 in hole for the led holder. On the right side, use your smallest drill bit do drill two holes 0.5 cm apart. Now time for the buzzer. Go 1 cm up form the key pad and put a little mark. Then form that mark go up 1.5 cm and put another little mark. Then messure 1.2 cm on the left and 1.2 cm on the right for a total of 2.4 cm. The cut it out again. I have a picture at the bottom of what it should look like when your done. Make sure that your CONSTANTLY trying to put in the buzzer and key pad every so often for you don't make the sure a little bit to big.

Step 16: Glue

Now it's time to start gluing everything together. Glue in everything BUT not the key pad yet. First glue in the led holder, then put the led in it and glue that in to. Then glue in the photo cell. Finally glue in the buzzer. Once every thing is glused in but the key pad, let it dry for a minute or two. Now were going to add some wire leads on the key pad. Cut up 7, 5in wires. and solder them to your keypad.

Note: The first and last pins on the key pad do nothing, so don't solder a wire onto them.

Step 17: More Glue

Now glue in the keypad.

Step 18: Solder in Those Numbers

Now we are going to solder in the keypad. 

pin 1 on the key pad goes to pin 14 on the atmega
pin 2 on the key pad goes to pin 11 on the atmega
pin 3 on the key pad goes to pin 13 on the atmega
pin 4 on the key pad goes to pin 14 on the atmega
pin 5 on the key pad goes to pin 6 on the atmega
pin 6 on the key pad goes to pin 5 on the atmega
pin 7 on the key pad goes to pin 4 on the atmega

Step 19: Lights

Now cut 4 5in wires for your led, and the photo cell. Then solder them on to the components. Then glue them all down so they don't short.

Note: It doesn't matter how it look because nobody will see it anyways.... as you see in mine there is a LOT of glue lol.

Step 20: Almost Done With the Wiring

Now solder on of the photo cells leads to power and the other to pin 28. Solder one of the led leads to pin 13 and the other to pin 12. Now final solder the red lead of the buzzer to pin 11 and the black wire to ground.

Step 21: Power Source

Now we need some way of powering this bad boy. First we need some way of getting the cord into the box, so cut a small hole in the bottom of the enclosure. Now strip the end of the wall adapter and feed the wire into the enclose. Now this are the last 2 leads were going to solder. YAH!!!  Solder the ground wire to ground and the power wire into the input of the regulator. Now the last thing we need to solder is the little cap. Just solder one lead to power and the other to ground.

Step 22: CODE!!!

now it time to add the code to the micro!!!! 



int val, i, k, pwcount=0;
char password[] = "1", entry[10];  //this is were you can choose your code. Right now the code i 1
int codesize = 1; // once you have a code, you need to put the number of numbers here. if the code was 1324, this number would have to be 4 since there are 4 numbers in the code

int A = 8;
int B = 7;
int C = 6;
int D = 5;
int E = 4;
int F = 3;
int G = 2;
int RED = 12;
int GREEN = 13;
int BUZZ = 11;


void setup()
{
  Serial.begin(9600);
  pinMode(A, INPUT);
  pinMode(B, INPUT);
  pinMode(C, INPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(RED, OUTPUT);
  pinMode(BUZZ, OUTPUT);

  digitalWrite(RED, LOW);
  digitalWrite(GREEN, HIGH);
}


void loop()
{

    reset();

    val = analogRead(5);
    if (val < 600){
      digitalWrite(RED, HIGH);
      digitalWrite(GREEN, LOW);
      digitalWrite(BUZZ, HIGH);
      Serial.println(val);
    }

  digitalWrite(D, HIGH);

    if(digitalRead(B)==HIGH){
    blinker();
    entry[pwcount] = '1';
    pwcount++;
   delay(150);
Serial.print('1');
}
if(digitalRead(A)==HIGH){
blinker();
entry[pwcount] = '2';
pwcount++;
delay(150);
Serial.print('2');
}

if(digitalRead(C)==HIGH){
blinker();
entry[pwcount] = '3';
pwcount++;
delay(150);
Serial.print('3');
}

digitalWrite(D, LOW);
digitalWrite(E, HIGH);

if(digitalRead(A)==HIGH){
blinker();
entry[pwcount] = '0';
pwcount++;
delay(150);
Serial.print('0');
}

if(digitalRead(B)==HIGH){
blinker();
delay(150);
pwcount = 0;
Serial.print('*');
}


digitalWrite(E, LOW);
digitalWrite(F, HIGH);

if(digitalRead(A)==HIGH){
blinker();
entry[pwcount] = '8';
pwcount++;
delay(150);
Serial.print('8');
}
if(digitalRead(B)==HIGH){
blinker();
entry[pwcount] = '7';
pwcount++;
delay(150);
Serial.print('7');
}

if(digitalRead(C)==HIGH){
blinker();
entry[pwcount] = '9';
pwcount++;
delay(150);
Serial.print('9');
}

digitalWrite(F, LOW);
digitalWrite(G, HIGH);

if(digitalRead(A)==HIGH){
blinker();
entry[pwcount] = '5';
pwcount++;
delay(150);
Serial.print('5');
}
if(digitalRead(B)==HIGH){
blinker();
entry[pwcount] = '4';
pwcount++;
delay(150);
Serial.print('4');
}

if(digitalRead(C)==HIGH){
blinker();
entry[pwcount] = '6';
pwcount++;
delay(150);
Serial.print('6');
}
digitalWrite(G, LOW);
digitalWrite(E, HIGH);


if(digitalRead(C)==HIGH){
blinker();
delay(250);
Serial.println('#');
for(k=0; k<=codesize; k++){
if(k==codesize){
Serial.println("Access Granted");
delay(100);
for (i=0; i<20; i++) {
delay(5);}
delay(100);
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);
digitalWrite(BUZZ, LOW);
delay(15000); // This number is the ammount of time you have to reset the laser beam after it's been broken. it is set at 15 seconds
digitalWrite(GREEN, LOW);
digitalWrite(RED, LOW);
delay(200);
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);
delay(200);
digitalWrite(GREEN, LOW);
digitalWrite(RED, LOW);
delay(200);
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);


break;
}
if(password[k] != entry[k] || pwcount > codesize){
Serial.println("Denied");
break;
}
}
for(k=0; k<10; k++)
entry[k]=0;

pwcount=0;
return;

}
digitalWrite(E, LOW);
}


void blinker(){
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);
delay(75);
digitalWrite(GREEN, LOW);
digitalWrite(RED, LOW);
delay(75);
digitalWrite(GREEN, LOW);
digitalWrite(RED, HIGH);
}

void reset(){
int j;
for(j=6; j<=8; j++);
}

Step 23: Close Up

Now put the curcit  board in the enclose. Now you just have to simply screw it up and your done!!!

Step 24: Laser

now just take your laser beam and hook it up to power. Now if you want to use mirrors, aim the laser so it hits the photo cell. Now put it on your wall and ENJOY!!!


NOTE: as you see in the picture i made another enclosure for the laser beam. I I bought the second smallest case at radio shack. I then dilled a hole for the laser and a hole for the switch. I used a 9V bat or wall power

NOTE: these lasers can take any wear from 3V to 12V and not burn out, so if you could find just the right wall adapter, a regulator is not needed.

Step 25: Completion

We are now done and time to use our home made Adruino laser detector with keypad. Remember you can change the code at any time. This detector is VERY accurate. 

Microcontroller Contest

Participated in the
Microcontroller Contest