SHARE
TWEET

LaserAlarm

a guest Sep 5th, 2010 2,301 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Laser Security Alarm
  2. // BY Stigern, www.stigern.net
  3.  
  4. int ldr_readings = 0;
  5. int AlarmPin = 10;
  6.  
  7. void setup()
  8. {
  9.  // Setting up Serial communication!
  10.  // I use this for calibration first, to read what values I
  11.  // get when it got the laser in center, and what value I
  12.  // get when it's not in the center. So that I know what
  13.  // to put in the if statements.
  14.   Serial.begin(9600);
  15. }
  16.  
  17. void loop()
  18. {
  19.   // Read from the analog 0 and put it into the integer.
  20.   // So that we can use the if statement to ask if it's
  21.   // something blocking the light or now.
  22.   ldr_readings = analogRead(0);
  23.  
  24.   // Just so we can see the values from the LDR
  25.   // Prints the integer to us via serial. Used
  26.   // for calibration when adjusting 100 and 50.
  27.   Serial.println(ldr_readings);
  28.  
  29.   // Should we activate the alarm?
  30.   // Yepp, if we get a value higher than 100.
  31.   if (ldr_readings > 100)
  32.   {
  33.      digitalWrite(AlarmPin, HIGH);
  34.   }
  35.      
  36.   // Or should we deactivate it?
  37.   // Yes if we get a value lower than 50.
  38.   if (ldr_readings < 50)
  39.   {
  40.      digitalWrite(AlarmPin, LOW);
  41.   }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top