//Here is some sample code that you can use for your sensor
int AlarmOneInputPin = 0; // sensor connected to analog pin 0
int AlarmOneOutputPin = 9; // Alarm connected to digital pin 9 int AlarmOneInputValue = 0; // variable to store the value read int AlarmOneTriggerValue = 350; // alarm set value
void setup() { pinMode(AlarmOneOutputPin, OUTPUT); // sets the digital pin as output Serial.begin(9600); // setup serial }
void loop() {
AlarmOneInputValue = analogRead(AlarmOneInputPin); // read the input pin Serial.println(AlarmOneInputValue); // debug value
if(AlarmOneInputValue < AlarmOneTriggerValue) //flash the alarm if the sensor value is below the trigger value { digitalWrite(AlarmOneOutputPin, HIGH); // turns the alarm on delay(1000); // waits for a second digitalWrite(AlarmOneOutputPin, LOW); // turns the alarm off delay(1000); // waits for a second } else { digitalWrite(AlarmOneOutputPin, LOW); // turns the alarm off delay(1000); // waits for a second }
}