Things used in this project

Hardware components:
A000066 iso both
Arduino UNO & Genuino UNO
Or a compatible Arduino Uno Board
×1
Adafruit industries ada64 image 75px
Solderless Breadboard Half Size
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×3
11026 02
Jumper wires (generic)
×1
Adafruit industries ada161 image 75px
Photo resistor
×2
Laser Diode
×1
Omron b3f 1000 image 75px
Tactile Button Switch (6mm) Single
×1
Adafruit industries ada1536 image
Buzzer
×1
Software apps and online services:
Ide web
Arduino IDE

Schematics

Breadboard View
Breadboard View
Laser tripwire beep bb rnul0isroa
Schematic
Schematic view
Laser tripwire beep schem ygwdkxqt0e

Code

Laser TripwireArduino
// 5 pins trip wire

// Variables
int mode = 1;
int ambiant;
int trip = 1000; // The light value I get when using my laser
int minLight = 900;
int makeBeep = 1; //0 for no beep, 1 for beep!
int atAverage;
long millisCount;

// Output Pins
int laserPin = 2;
int ledPin = 13;
int buzzerPin = 3;
String  modeNames[3] = {"SETTINGS","ARMED","TRIP"};

// Input Pins
int modePin = 4; 
int tripPin = A0;
int ambiantPin = A1;


void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(laserPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(modePin, INPUT);
  Serial.begin(9600);
}


void loop() {

  // When the button is pushed
  if (digitalRead(modePin) == 1) {
    trip = analogRead(tripPin);
    mode=mode + 1;
    if (mode >= 2) {
      mode = 0;
    }
    beep(1);
    delay(300);
  }

  
  //does something when the mode changes
  switch (mode) {
    case 0: //calibration mode
      digitalWrite(laserPin,HIGH);
      
      ambiant = analogRead(ambiantPin);
      trip = analogRead(tripPin);
      atAverage = ambiant + ((trip - ambiant)/2);
      stats();
      
      if (trip  >= minLight) {
        digitalWrite(ledPin,HIGH);
      } else {
        digitalWrite(ledPin,LOW);
      }

    break;

    case 1: // Armed mode
      digitalWrite(laserPin,HIGH);
      digitalWrite(ledPin,LOW);
      ambiant = analogRead(ambiantPin);
      atAverage = ambiant + ((trip - ambiant)/2);
      if (analogRead(tripPin) < atAverage) {
        mode = 2;
      }
      if ((millis() - millisCount) >= 3000) {
        millisCount = millis();
        stats();
      }
    break;
    
    case 2: //Trip Mode
      if ((millis() - millisCount) >= 1000) {
        millisCount = millis();
        stats();
        beep(3);
        mode = 1;
      }
    break;
    }

    
  delay(1);                       // wait for a bit
}

//It Beeps
void beep(int qty) {
  int count;
  if (makeBeep == 1) {
    for (count = 1;count<=qty;count++) {
      digitalWrite(buzzerPin, HIGH);
      delay(50);
      digitalWrite(buzzerPin, LOW);
      delay(50);
    }
  }
}

//Writes stats to the Serial Port
void stats() {
  Serial.print("A:");
  Serial.print(ambiant);
  Serial.print(" T:");
  Serial.print(trip);
  Serial.print(" AT:");
  Serial.print(atAverage);
  Serial.print(" MODE:");
  Serial.print(modeNames[mode]);
  Serial.println("");
}

Credits

509f148d252c095177dfab08c0364567
Ian Cumming

I like stuff, from building rockets to elctronics.

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

3D-Printed Prank Vibrating Cup
Easy
  • 1,401
  • 14

Full instructions

The instant your prankee lifts up this 3D-printed cup it starts violently vibrating! The electronics separate from the cup for easy washing.

The Magic Display With Arduino - The Mind Reader
Easy
  • 1,605
  • 6

Full instructions

The Magic Display With Arduino can figure out with a few clues what is your choose on a card with 64 options of numbers, letters or symbols.

Very First Hands On Arduino - Voice Activated LED
Easy
  • 908
  • 9

Full instructions

Use voice command to turn LED on or off.

Get Connected! WiFi Registration Using AP Mode!
Easy
  • 1,597
  • 16

Full instructions

Stop reflashing your devices everytime the WiFi password changes! Learn how to use anduinoWiFi and AP mode to initiate WiFi registration!

Car Blinker
Easy
  • 271
  • 4

Protip

Blink for Vehicles, such as bikes and skates. Easy.

The Soldering Iron Controller for Hakko T12 Tips
Easy
  • 8,903
  • 27

Full instructions

Per-tip calibration and high-frequency temperature check by Timer1.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback