int i=0; float rain=0.0; const int REED_PIN = 3; // Pin connected to reed switch,has to be a PWM pin const int LED_PIN = 12; // LED pin - active-high int old_val = 0; //Old value of reed switch void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(REED_PIN, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); } void loop() { // put your main code here, to run repeatedly: int proximity = digitalRead(REED_PIN); // Read the state of the switch // int proximity = LOW; if ((proximity == LOW) && (old_val == HIGH)) // If the pin reads low, the switch is closed. { delay(10); // Serial.println("Switch closed"); old_val=proximity; i=i+1; rain=0.03*i; digitalWrite(LED_PIN, HIGH); // Turn the LED on Serial.print("Rain Height="); Serial.print(rain); Serial.println(" mm"); } else { digitalWrite(LED_PIN, LOW); // Turn the LED off old_val=proximity; } // delay(1000); }