How to use raindrop sensor

MATERIALS REQUIRED

1.ARDUINO UNO
2.BREADBOARD
3.MALE TO FEMALE WIRES
4.MALE TO MALE WIRES
5.BUZZER
6.RAINDROP SENSOR


CIRCUIT

analogpin-A0
digitalpin-D7
GND-GND
VCC-5V
buzzer+ve-13
buzzer-ve-GND

CODE

const int analogPin=A0; //the AO of the module attach to A0
const int digitalPin=7; //D0 attach to pin7
const int buzzer=13; //
int Astate=0; //store the value of A0
boolean Dstate=0; //store the value of D0

void setup() 
{
  pinMode(buzzer,OUTPUT); //set the buzzer as OUTPUT 
  pinMode(digitalPin,INPUT); //set digitalPin as INPUT
  Serial.begin(9600); //initialize the serial monitor
}

void loop() 
{
  Astate=analogRead(analogPin); //read the value of A0
  Serial.print("A0: ");
  Serial.println(Astate); //print the value in the serial monitor
  Dstate=digitalRead(digitalPin); //read the value of D0
  Serial.print("D0: ");
  Serial.println(Dstate);
  if(Dstate==HIGH) 
  {
    digitalWrite(buzzer,LOW);
  }
  else //if the value of D0 is LOW
  {
    digitalWrite(buzzer,HIGH); //turn on the led
  }
}

Comments