// constants won't change. They're used here to set pin numbers:
const int buzzer = 9;
const int sensorPin = 10; // the number of the sensor pin
const int signalPin = 13; // the number of the signal pin
// variables will change:
int tiltState = 0; // variable for reading the sensorpin
void setup() {
// initialize the singnal pin as an output:
pinMode(signalPin, OUTPUT);
// initialize the sensor pin as an input:
pinMode(sensorPin, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the state of the sensorpin:
tiltState = digitalRead(sensorPin);
// check if the there is water on the rain sensor. If it is, the signalpin is Low:
Serial.println(tiltState);
delay(100);
if(tiltState ==HIGH)
{
digitalWrite(signalPin,HIGH);
tone(buzzer, 2000); // Send 2KHz sound signal...
}
else
{
digitalWrite(signalPin,LOW);
noTone(buzzer);
}
}
Comments
Please log in or sign up to comment.