Things used in this project

Hardware components:
A000066 iso both
Arduino 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
SparkFun Pushbutton switch 12mm
×1
Adafruit industries ada1536 image
Buzzer
×1
Software apps and online services:
Ide web
Arduino 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.

Contact

Replications

Did you replicate this project? Share it!

I made one

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

Give feedback

Comments

Similar projects you might like

Guess the Number With Arduino KeyPad
Easy
  • 37
  • 3

Full instructions

A simple and funnies project with an Arduino UNO and the famous keypad shield. Arduino selects a random number, you guess the number.

Control a 7 Segment Display with a keypad!
Easy
  • 52
  • 2

Full instructions

In this project I'll show you a simple way to control a 7 Segment Display with a keypad!

Using 9 Axes Motion Shield with Arduino
Easy
  • 5
  • 1

Protip

The Arduino 9 Axes Motion Shield allows your Arduino to measure movement: orientation, acceleration and magnetic field.

Potentiometer with RGB LED
Easy
  • 30
  • 2

This uses potentiometers to control a RGB LED.

Launch Pad Count Down Sequence Display
Easy
  • 65
  • 2

Work in progress

A 7 Segment Display of a Countdown from 9 to 0 for a Launch Pad Control Panel.

Mask with Blinking Eye
Easy
  • 72
  • 3

Protip

Makes a great mask more eye-catching when one eye is blinking. Has an on-off switch, is powered by a cell , and driven by an ATtiny85.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog