Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Laser Trip Beam Alarm
- Created by Chris Swart
- http://digigram.za.net
- Using Energia 0101E0009 on Linux Mint 13
- Version 0.0.1 - 30 December 2012
- Alarm Activates {armedDelay} seconds after reset button
- Beam needs to be interupted for more than {howLongMax}x10 milliseconds to sound the alarm
- This is to weed out false trips from ADC errors
- */
- /*
- Circuit
- Status LED - ARMED connected to pin 14
- Status LED - INTRUDER connected to pin 9
- Sensor LED - RED connected to pin A0 (1) and GND --- Red LED for use with red laser pointer (<5mW)
- */
- //Declarations
- const int analogInPin = A0; // Analog input pin that the receiving diode (Red LED) is attached to
- const int LED_INTRUDER = 9; // Intruder alert LED. Mine is Blue :)
- const int LED_ARMED = 14; // System is arming when blinking, armed when steady on
- int sensorValue = 0; // value read from the LED
- int threshold = 100; // Below this value the alarm will trip. You might need to alter this value
- int howLong = 0; // How many consecutive measurements were missed
- const int howLongMax = 5; // Alarm will only sound if this many consecutive measurements were missed
- const int armedDelay = 10; // Delay from reset to Armed in seconds
- void setup() {
- // Debugging
- Serial.begin(9600);
- // Set status LEDs
- pinMode(LED_INTRUDER, OUTPUT);
- pinMode(LED_ARMED, OUTPUT);
- digitalWrite(LED_INTRUDER, LOW);
- digitalWrite(LED_ARMED, LOW);
- // Delay arming
- for (int timer = armedDelay; timer >= 0; timer--){
- digitalWrite(LED_ARMED, HIGH);
- delay(200);
- digitalWrite(LED_ARMED, LOW);
- delay(800);
- }
- digitalWrite(LED_ARMED, HIGH); //system is armed
- }
- void SoundAlarm() {
- //Intruder LED will light. Siren can be inserted here.
- //Feedback to controlling MCU will follow later
- digitalWrite(LED_INTRUDER, HIGH);
- digitalWrite(LED_ARMED, LOW);
- Serial.println("INTRUDER");
- delay(1000);
- }
- void loop() {
- //replace with interrupts in following versions to decrease power usage
- sensorValue = analogRead(analogInPin);
- if (sensorValue < threshold){
- howLong = 0; //Clean the counter
- }
- else {
- howLong += 1;
- Serial.println(howLong);
- }
- // If counts are exceeded, alarm will sound WITHOUT interruption
- // Interruption and reset will be established at the controlling MCU
- while (howLong >= howLongMax){
- SoundAlarm();
- }
- //Uncomment this line to establish a good value for threshold
- //Serial.println(sensorValue);
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement