top of page

EPIC DIY 3D Printed Laser Trip Alarm

See the DIY Laser Alarm in Action!
Tested to work at 25ft+!

"Even if you never plan on making this, you can still understand how this technology is used and works; making you smarter than your friends.

You could apply the same concepts to maybe an analog version that uses flowing water instead of a laser. You get the idea..."

Why Make This?

Do you like the Mission Impossible movie series as much as I do?

Sure, the whole thing pivoted quickly from classic Cold War Era Espionage and gadgets to a more octane fueled action ride but if it didn't we may not have the series like we do now.

I have always been a HUGE fan of the original 1996 release since I saw it in theaters as a kid and immediately fell in love with the pacing and style of the movie that featured strange but feasible gadgets and methods.

We won't be hanging on the side of a C-130 in this tutorial but we will be making a 3D Printed Laser Trip Alarm that you can stick pretty much anywhere!

The inspiration for this came to me when a new puppy kept sneaking around the house and peeing on the bed.

Memory foam is expensive and difficult to wash and dry by foot!

So, I whipped up this concept that uses cheap materials and is easy to solder together and have included the STL files but you are going to have to read the tutorial because I hid them...in a sneaky, spy kind of way.

Even if you never plan on making this, you can still understand how this technology is used and works; making you smarter than your friends.

You could apply the same concepts to maybe an analog version that uses flowing water instead of a laser. You get the idea...

mission impossible laser scene

CONCEPT

  • Laser emits from a box on one side

  • Another box across from it has a Light Dependent Resistor connected to a chip That varies the flow of electricity into a pin on the chip based on the amount of light hitting it

  • Piezo Speaker vibrates when the electricity coming in on that pin is below a value we choose in our code

pet laser trip alarm

Electronic Components

If this is your first time learning electronics make sure to check out my explanations of the components here.

There are 2 parts to this Laser Alarm Build:

  1. The laser box

  2. the LDR box

Scroll down to See the schematics and sketches

for pictures of components

                       *Click Each Item to Find Where to Purchase*

LASER BOX

 

LDR BOX

Tools and *Optional Materials

  • Hot Glue Gun

  • Super GluE (I used the gel type)

3d printed laser alarm

The LDR Box Code for ATMEGA328P Chip

Study the //notes, Don't worry too much about the code.
Focus on how the Microchip does the job!

 

#include <avr/io.h>              //Files we need to turn the pins on and off
#include <util/delay.h>          //Files we need to make the chip wait some time
#include <avr/interrupt.h>    //Files we need to make an interrupt trigger ( ISR )

#define noteDuration  8000          //How long we want the note to play for

//First We Set up the Rules for the Trigger


void interruptEnable(void)  {
   EIMSK |= (1 << INT0);      
 //ISR enabled on INT0 pin which is PB0
    EICRA |= (1 << ISC00);        //triggers on any change in voltage
    sei();                        //enables global interrupts
    
}

/*Next we set up a Function to scan the amount of analog voltage coming in on our
pins connected to the analog to digital converter*/


uint16_t readADC(uint8_t channel) {      /*ADC value will be a 10 bit number made of 2x 8 bit numbers                                                                                   from each ADC pin we can call "channel" */
    ADMUX = (0xf0 & ADMUX) | channel;    //Conversion process
    ADCSRA |= (1 << ADSC);                 //Signal that it is busy doing conversion
    loop_until_bit_is_clear(ADCSRA, ADSC); //Keep at it until the job is done and all clear is given
    return(ADC);                           //give us that new digital value from that pin we scanned
}

/*The playNote function is confusing but you will better understand it if you play around with one value at a time*/

void playNote(uint16_t wavelength, uint16_t duration) {              /*this is a function that will vibrate the

                                                                                            piezo speaker based on wavelength and duration*/
  uint16_t elapsed;                                             //to remember how much time has passed during each note
  uint16_t i;                                                            //a counter
  for (elapsed = 0; elapsed < duration; elapsed += wavelength) {        

                 //This For Loop puts limits on the duration in order to create a wavelength
                                                                        
   
for (i = 0; i < wavelength; i++) {                                    //This For loop with delay selects the pitch
      _delay_us(1);
    }
    PORTB ^= (1 << PB1);                                     
//We alternate the pin on and off each loop to make it vibrate
  }
}

uint8_t x;                //Container for a value in our loop later

/*MAIN Staging Part of our code*/


int main(void) {
   
   uint16_t adcValue0;        
//Like a container to hold our adcValue for later
    interruptEnable();      //Tell the interrupt to get ready
    DDRB |= (1 << PB1);     //The speaker is connected to pin PB1 and it's negative leg to a capacitor which connects to the Ground of the chip
    DDRC |= (1 << PC5);        //Turns on the pin connected to one leg of the LDR sensor, it's other leg connects to the positive voltage of the chip
    

/*This is the loop of code the chip runs over and over and over*/
while(1) {                        //while the chip is running...

    
   adcValue0 = readADC(5);        
/*set that adcValue container to hold the value that pops out from the 

                                                       readADC function on ADC pin 5 (PC5) */
    _delay_us(10);                //wait 10 microseconds for it to complete
    
   
if (adcValue0 < 20) {        //if the adc voltage value for the LDR is less than 20 then do...
                            //20 seems like a nice piercing pitch on our 8mhz chip (timing and speed changes sound)

         for (x = 0; x < 50; x++) {    //count up to 50 total but only add 1 each time through this loop    
       playNote(30, noteDuration);    
//using our playNote function for the wavelength and duration
        PORTB ^= (1 << PB1);       // Alternate the speaker pin on and off to make it vibrate during this process
                                        
           }
                                   
         }
       
 
   else {                         //Otherwise...
        PORTB &= ~(1 << PB1);  //we keep the speak pin PB1 OFF and quiet
    }
}
   

return (0);                //This is just here, don't worry about it
}

Simple LDR Schematic 

Terrible LDR Connection Sketch

ldr alarm_bb.jpg

UGLY LDR Soldered Concept
in 3d Printed Box

Yikes...I know. Concepts are always ugly.

You can make it prettier later with small improvements over time.

However you do it, stick to the schematic and you will be fine.

I flashed the program to my chip first.

If you want to see how to do all that you have to check out my Programming of this Atmega328P chip video that now has nearly 25,000 views!

Simple LDR Schematic 

Now, let's take a look at the MUCH simpler Laser side!

Satisfying Laser Connection Sketch

UGLY Laser Soldered Concept
in 3d Printed Box

Need to learn how to solder quickly? Check out this short video!

WHEW! What a complicated Build for such a simple concept!

Want a FULL Explanation Video?
I got you...right below!

advice I wish I had learning Electronics

This was pretty challenging and if you made it to the end, I want to let you know that
you are different.
This is going to become easier and easier.


You have the potential to learn how to create some amazing inventions and gadgets.
NEVER GIVE UP!

do SOMETHING with electronics every single day, especially day dreaming concepts!


I have an
Exciting announcement coming up in a video soon, make sure to subscribe with the linked video below!

See you in the next video!
Stay Grounded!

bottom of page