The KLPTO is designed to alert you when your neighbor’s laptop is being stolen. An FSR is placed underneath the laptop. As long as the FSR is receiving 200 units of pressure, nothing happens. If the FSR detects less than 200, then the servo motor is activated waving the flag back and forth.
int servoPin = 2; // Control pin for servo motor
int minPulse = 500; // Minimum servo position
int maxPulse = 2500; // Maximum servo position
int pulse = 0; // Amount to pulse the servo
int analogValue = 0; // the value returned from the analog sensor
int analogPin = 0; // the analog pin that the sensor’s on
long lastPulse = 0; // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses
long lastSetTime = 0; // setting time for the flag delay
int delayValue = 500; // number of milliseconds to wait between flag waves
int pulseValue = 450; // the value returned from the analog sensor
void setup() {
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pulse = minPulse; // Set the motor position value to the minimum
Serial.begin(9600);
}
void safe(){ //this is the default state
Serial.println(“The laptop is safe!”);
Serial.println(analogValue);
delay(1000);
}
void alarm(){
Serial.println (“The laptop is in DANGER!!!”);
Serial.println (analogValue);
if (millis() - lastSetTime >= delayValue) { // check to see if it’s time to move the flag
if (pulseValue == 450) { //if the servo is in its start position
pulseValue = 700; //put it to the end position
}
else {
pulseValue = 450; //if it is any value other than start (which has to be the end b/c there are only 2 states)
}
lastSetTime = millis();
}
pulse = (pulseValue * 19) / 10 + minPulse; // convert the analog value
// to a range between minPulse
// and maxPulse.
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}
void loop()
{
analogValue = analogRead(analogPin); // read the analog input
if (analogValue>199)
{
safe();
}
if (analogValue “lessthan” 200)
{
alarm();
}
}