Laser Tripwire

by emham in Circuits > Lasers

270 Views, 0 Favorites, 0 Comments

Laser Tripwire

21DE6D12-F3BE-40D1-BF08-45D784C7F6E7.jpeg

This project is a laser tripwire utilizing a lot of cardboard, a laser diode, and an photoresistor with a Particle Argon microcontroller. The premise of the project is to use a wall-mounted laser diode to fire a laser constantly at a photoresistor, which is connected to the Argon microcontroller. This effectively creates a tripwire. When the laser is crossed, blocking the light from reaching the photoresistor, the code is triggered to send a notification to my phone using the If-This-Then-That (IFTTT) iPhone application. There is a disengage function for when I cross the laser to not send a notification to my phone, which is triggered from my phone using Particle webhooks and the Particle Console webpage. The mounting is non-intrusive, using Command Strips to mount both the housing unit for the Argon as well as the laser diode and attached battery pack. To power the project, I connected the Argon to my chromebook and set the chromebook on the floor while the project ran. Any USB type-A power source would work for this project.

Supplies

Supplies for Argon apparatus

  • Particle Argon x1
  • SG90 Micro Servo x1 (or servo of similar size and power)
  • Photoresistor x1
  • 10 ohm resistor x1
  • Breadboard x1

Supplies for Laser Diode and Battery Pack

  • 3 prong switch x1
  • AA Battery x3
  • Laser Diode
  • Solid Core wire

General Tools

  • Glue Gun
  • Soldering Iron

Argon Configuration

maxresdefault.jpg

Configuring the Argon isn't part of this tutorial, but it's quite simple. The attached documentation runs through the entire setup:

https://docs.particle.io/quickstart/argon/

Once you've set up your argon and attached it to the breadboard, you can begin wiring the photoresistor and servo in the following steps.

Device ID and Access Token

Screenshot 2023-01-29 231851.png
Screenshot 2023-01-29 232016.png

For parts of this project, you will need to expose a part of your particle code to be called from your computer or mobile device. To do this, you'll need the device ID from your Argon as well as an access token.

To access your device ID, enter the particle IDE and go to the "devices" tab on the left side with an icon that looks like a gun scope from a video game. You should see your device listed there. Click on it, and copy the device ID. Save it in a google doc or any way you would prefer to copy it down.

To retrieve an access token, access this page: https://docs.particle.io/reference/cloud-apis/access-tokens/

Use the create a token (browser based) tool to generate an access token that lasts 90 days. You can choose how long the token lasts before it expires by selecting from drop down in the tool. Similar to the device ID, copy this down and save it through your preferred method.

Wiring the Photoresistor

IMG_4252.jpg
IMG_4250.jpg
IMG_4249.jpg

To start, I used a 10 ohm resistor to connect a negative rail and ground, to ground the entire rail. I used a jumper wire to connect one end of the photoresistor to the grounded negative rail. For the same prong that I connected to the negative rail, I used another wire to connect it to the analog pin A0. Finally, I used one more wire to connect the non-grounded prong of the photoresistor to the 3.3 volt pin (3v3 on the Argon).

Wiring the Servo

unnamed.png
76C611E0-5DFB-4EC5-90E7-FFA0493D1B24.jpeg
82FC55CC-159B-419D-AAF7-163BB63BEB6A.jpeg

There will be places on the servo to make specific wiring connections. You will want to wire the servo to ground, the USB pin on the microcontroller, and to a digital pin. For this specific model:

  • Orange = digital pin
  • Red = USB
  • Brown = ground

Using jumper wire, connect the orange slot on the servo to D2. Connect red to the USB pin, and connect brown to the grounded rail.

Laser Diode Battery Pack

60678F2A-9A46-4661-A236-045735F30C50.jpeg
339B720F-7CAD-454C-B8D0-4FFA3FF5155F.jpeg
3C7D63D2-914C-45CE-B49E-7B87444B9AB8.jpeg
7A99928E-5DCC-4D8F-B0D2-57CEC68FC84E.jpeg

One thing I learned through this project is how ridiculous laser diodes can be with enough power. 3 AA batteries are enough to make the laser strong enough to shine halfway down a city block, so it's more than enough to get the laser to shine across the width of my hallway. In order to get to that power, I needed to wire the batteries in series. This essentially stacks the voltage of the battery by wiring the positive end of one battery to the negative end of another, and so on.

I used cardboard and solid core wire to create a makeshift battery pack. I used two batteries and laid them next to each other to see how wide I needed to make the base, and used hot glue to make walls to put around the batteries. The base was about 7x4 centimeters and the walls were about 6.5x4 lengthwise and about 3.5x4 for width. I left a little space by the positive and negative covers of the batteries in order to coil the wire there to make the connection. Once the pack was put together, I poked holes to fit wire through by the positive and negative ends of each battery. I stripped the wire so I was able to coil the end after putting it through the hole. Once the batteries and wires are in, you should have a wire connected to the negative end of a battery and a wire connected to the positive end of a battery sticking out.

Once the batteries are in the pack, it's time to attach the switch.

Attaching the Switch

3CCF75A7-0E2A-48AC-ACC9-7B57112D07B0.jpeg

I used a three pin switch for this project. From my perspective looking at it, imagine there is a left, right, and middle pin. Do not change this orientation. Using a soldering iron, I connected the negative wire coming off the battery to the middle pin. I then soldered the negative wire from the laser diode itself to the right pin. I also soldered the positive wire coming from the battery pack to the positive wire on the laser diode. Once the connection is made, I glued the laser diode to the pack and used masking tape to clean up the wiring.

Encasing the Argon

8D98F6C1-75A6-4597-B663-F0D19C06A7EB.jpeg
70F7837A-0D78-4021-921E-AF6FD4F52A98.jpeg
97FB4DAE-CD3A-4AF1-900E-30FC850210C6.jpeg

Creative liberties can be taken with this part. All you really need to do here is create a housing unit for the Argon so that you can attach the servo to the housing unit to block off the photoresistor from outputting values. I created a trapezoidal shape, leaving open ends for the USB-A cable to connect to a power source and also so I could have easy access to removing the argon from the unit. It's pictured above.

The big thing here is cutting a hole so that the laser can hit the photoresistor, and also to keep the argon stable in the housing unit so the photoresistor is always in the same spot.

The process for making my housing unit:

  • Cut out a cardboard base about 11x10 cm.
  • I put my argon in the middle of this cardboard piece, and cut out two small cardboard pieces which I hot glued to the base to keep it in one spot. They were about 11x1 cm and were glued to the base so they would run alongside the argon lengthwise.
  • Cut out two pieces of cardboard about 4 inches wide and the length of the base. I hot glued these pieces to the edge of the base.
  • Then, I cut out a cardboard piece that was about 10x6 cm. I held it above the argon to approximate where the photoresistor was, and then cut out a hole in the roof piece for the laser to shine through. I then glued the roof piece to the side pieces.
  • Once all that is done, put the argon inside of the cardboard case.
  • Now to attach the servo to the case. To start, I mapped the servo to 10 degrees to figure out where the carboard fin that would cover the photoresistor would be while it's not engaged. After I did that, I cut out a cardboard piece approximately 1x3 inches. I glued it to the plastic servo fin. I glued the servo to the cardboard so that when the disengage function is engaged, the cardboard fin covers the photoresistor. Orientation is picture above.

IFTTT

Screenshot 2023-01-29 232445.png
Screenshot 2023-01-29 232511.png

If-This-Then-That (IFTTT) is the software that I used to send notifications to my phone whenever the laser is tripped. It's compatibility with Particle software makes it particularly useful here.

First you want to set up an IFTTT account, if you haven't already. Here is the link the the webpage if you're not setting it up through the app: https://ifttt.com/explore

Once you create an account, you'll want to go to the "My Applets" tab. Click create, and use webhook integration. For the "if" trigger, select "receive request with JSON payload." Make the event name "unknown_subject." For the "then" action, select send a notification from the IFTTT app.



Particle Code

Screenshot 2023-01-29 232231.png

During Argon setup in the first step, you should have encountered the Particle IDE. Access it and create a new document. Here is the code you will need:

SYSTEM_THREAD(ENABLED);


SerialLogHandler logHandler;


int photocellPin = 0;

int analogvalue;

const pin_t SENSOR_PIN = A0;

Servo myServo;



void setup() 

{

   

  Particle.variable("analogvalue", analogvalue);


  Particle.function("unknown_subject", unsub);

   


  Particle.function("disengage", disengageSensor);

   

   

  myServo.attach(2);

  myServo.write(110);

   

   

}


void loop() 

{

  analogvalue = analogRead(SENSOR_PIN);


   

  Log.info("analogvalue=%d", analogvalue);

   

  if(analogvalue < 1000)

  {

      Particle.publish("unknown_subject", PRIVATE);

  }

  delay(1000);

}


int unsub(String extra)

{

  return 0; 

}


int disengageSensor(String extra)

{

  myServo.write(10);

  delay(6000);

  myServo.write(110);

  delay(2000);

  return 0;

}

Once this is pasted into particle IDE, save it and flash it to your device.

Brief overview of what the code actually does: Looping code prints the photoresistor values to connected serial terminal. Constantly checking if the value is less than 1000, since the laser shining on the photoresistor will return values over 1000. Once the value is less than 1000, the code will trigger a function to send a notification to my phone when the laser is tripped. It also lays out the code for the disengage function, which activates a servo to block the photoresistor from the laser and stops reading the photoresistor values for about 8 seconds.




Particle Webhooks

Screenshot 2023-01-30 221245.png

I used two particle webhooks in this project. You can make webhooks here, in the integration tab. Login to your particle account and your device should link.

  • Click "new integration."
  • Title the event "unknown_subject."
  • Use this URL: https://maker.ifttt.com/trigger/unknown_subject/json/with/key/cJdl7E598bxM_ISnPRRqVL
  • For request type, select "POST."
  • For request format, select "JSON."
  • For device select "Any," and for status select "Enabled."


Now for the second integration:

  • Click "new integration."
  • Title the event "disengageSensor."
  • Use this URL format: https://api.particle.io/v1/devices/[deviceIDhere]/disengage/?access_token=[accessTokenhere]
  • Paste your device ID and access token that you saved earlier into their respective places in the URL.
  • For request type, select "POST."
  • For request format, select "Web form." 
  • For device select "Any," and for status select "Enabled."

Mounting to the Wall

6D044080-9149-463D-9B29-9BF8E66FBFBF.jpeg
6024A5AB-7A2B-41AD-9C7F-3DAE0C04E0FC.jpeg
3B5BBD72-464E-4948-A406-CEE58328D7CF.jpeg

To mount the device to the wall, I used command strips. Two on the back of the Argon housing unit and two on the back of the laser diode + battery pack. I kept the Argon close to the ground since I was using my chromebook as a power source in lieu of a more elegant solution. I mounted the laser first so I could move around the Argon to the best position for the laser to hit the photoresistor. Remember to make sure the code is flashed to the Argon, and that you're using an up-to-date access token for IFTTT. Once the code is flashed and the device is mounted, make sure the laser is pointed at the photoresistor. Connect the device to power and it will now perform its functions as intended. To trigger the disengage function, go to the particle console webpage to access your disengageSensor webhook here: https://console.particle.io/integrations

laser tripwire disengage function
laser tripwire