RAIN ALARM

 

rain

/*Arduino Rain Sensor sketch*/

int rainsense= 0; // analog sensor input pin 0

int buzzerout= 11; // buzzer output

int countval= 0; // counter value starting from 0

void setup(){

Serial.begin(9600);

pinMode(buzzerout, OUTPUT);

pinMode(rainsense, INPUT);

}

void loop(){

int rainSenseReading = analogRead(rainsense);

Serial.println(rainSenseReading); // serial monitoring message

delay(50);// this variable fo adjust counter interval

// from heavy rain – no rain.

if (countval >= 35){

Serial.print(“Heavy rain”);

analogWrite(buzzerout, 150); //raise an alert after x time

}

//raining for long duration rise buzzer sound

// there is no rain then reset the counter value

if (rainSenseReading <350){

countval++; // increment count value

}

else if (rainSenseReading >350) { // if not raining

digitalWrite(buzzerout, LOW); // turn off buzzer

countval = 0; // reset count to 0

}

delay(50); //this variable fo adjust counter interval

}

OTHER SKET

/*Arduino Rain Sensor sketch*/

int rainsense= 0; // analog sensor input pin 0

const int pinSpeaker = 11; // buzzer output

int countval= 0; // counter value starting from 0

#define NOTE_C4 262

#define NOTE_D4 294

#define NOTE_E4 330

#define NOTE_F4 349

#define NOTE_G4 392

#define NOTE_A4 440

#define NOTE_B4 494

#define NOTE_C5 523

void setup(){

Serial.begin(9600);

pinMode(pinSpeaker, OUTPUT);

pinMode(rainsense, INPUT);

}

void loop(){

int rainSenseReading = analogRead(rainsense);

Serial.println(rainSenseReading); // serial monitoring message

delay(50);// this variable fo adjust counter interval

// from heavy rain – no rain.

if (countval >= 35){

Serial.print(“Heavy rain”);

alarm(); //raise an alert after x time

}

//raining for long duration rise buzzer sound

// there is no rain then reset the counter value

if (rainSenseReading <350){

countval++; // increment count value

}

else if (rainSenseReading >350) { // if not raining

noTone(pinSpeaker); // turn off buzzer

countval = 0; // reset count to 0

}

delay(50); //this variable fo adjust counter interval

}

void alarm(){

tone(pinSpeaker,NOTE_C4, 500);

delay(500);

tone(pinSpeaker,NOTE_D4, 500);

delay(500);

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s