int photoResistorPin = A0;
int lightReading = 0;
int fsrPin = A1;
int fsrReading = 0;
int onLED = D0;
int offLED = D1;
int buzzerPin = D2;
bool securityOn = false;
bool alarmOn = false;
void setup()
{
Spark.variable("light", &lightReading, INT);
Spark.variable("force", &fsrReading, INT);
pinMode(photoResistorPin, INPUT);
pinMode(fsrPin, INPUT);
pinMode(onLED, OUTPUT);
pinMode(offLED, OUTPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(onLED, LOW);
digitalWrite(offLED, LOW);
digitalWrite(buzzerPin, LOW);
}
void loop()
{
lightReading = analogRead(photoResistorPin); //reading will be between 0 to 4095
if (lightReading <= 750)
{
securityOn = true;
}
else if (lightReading > 750)
{
securityOn = false;
}
else
{
digitalWrite(onLED, HIGH);
digitalWrite(offLED, HIGH);
}
if (securityOn || alarmOn)
{
digitalWrite(onLED, HIGH);
digitalWrite(offLED, LOW);
fsrReading = analogRead(fsrPin);
if (fsrReading > 2000 || alarmOn)
{
alarmOn = true;
digitalWrite(buzzerPin, HIGH);
delay(1000);
digitalWrite(buzzerPin, LOW);
delay(100);
}
}
else
{
digitalWrite(onLED, LOW);
digitalWrite(offLED, HIGH);
}
delay(100);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .