LaserAlarm
By: a guest | Sep 5th, 2010 | Syntax:
C++ | Size: 1.08 KB | Hits: 275 | Expires: Never
// Laser Security Alarm
// BY Stigern, www.stigern.net
int ldr_readings = 0;
int AlarmPin = 10;
void setup()
{
// Setting up Serial communication!
// I use this for calibration first, to read what values I
// get when it got the laser in center, and what value I
// get when it's not in the center. So that I know what
// to put in the if statements.
Serial.begin(9600);
}
void loop()
{
// Read from the analog 0 and put it into the integer.
// So that we can use the if statement to ask if it's
// something blocking the light or now.
ldr_readings = analogRead(0);
// Just so we can see the values from the LDR
// Prints the integer to us via serial. Used
// for calibration when adjusting 100 and 50.
Serial.println(ldr_readings);
// Should we activate the alarm?
// Yepp, if we get a value higher than 100.
if (ldr_readings > 100)
{
digitalWrite(AlarmPin, HIGH);
}
// Or should we deactivate it?
// Yes if we get a value lower than 50.
if (ldr_readings < 50)
{
digitalWrite(AlarmPin, LOW);
}
}