Issue digitalread Self made rain detector

Hello everyone,

I have built a rain detector myself, which is supposed to function as a switch on a digital input. The sensor consists of parallel metal pins, where every second pin is soldered to a silver wire. On the other side, it is the same. For testing, when the sensor is shorted with a wire, a digital input should go to LOW.

Strangely, this does not work with the Arduino; the input always remains HIGH. When I measure the sensor, using a multimeter, I get an open circuit (OL). If I touch the sensor area with a piece of wire, connecting two parallel rods, I get a closed circuit displayed on the multimeter.

Why doesn't this work with the Arduino or what i am missing here?
Here is a photo from the sensor and the code I am using for testing:

int pushButton = 5;

void setup()
{
  Serial.begin(9600);
  pinMode(pushButton, INPUT_PULLUP);
}

void loop()
{
  if(digitalRead(pushButton) == LOW)
   {
      Serial.println("DRY");
   } else {
      Serial.println("WET");
   }
}

How is the sensor wired to the Arduino ?

Presumably one side goes to pin 5 but where is the other side connected to ?

Yes. One wire goes to pin 5. The other goes to ground. (Gnd)

What value do you get if you use analogRead() instead of digitalRead() ?

Values like this:

22:32:58.622 -> 310
22:32:59.641 -> 318
22:33:00.634 -> 314
22:33:01.625 -> 330
22:33:02.647 -> 299
22:33:03.638 -> 311
22:33:04.628 -> 271
22:33:05.616 -> 310
22:33:06.642 -> 308

When i use this code:

int pushButton = 5;

void setup()
{
  Serial.begin(9600);
  pinMode(pushButton, INPUT_PULLUP);
}

void loop()
{
  Serial.println(String(analogRead(pushButton)));
  delay(1000);
}

What do you see if you print the values returned by digitalRead() ?

Incidentally, why do you convert the value to a String in your code ?

Serial.println(digitalRead(pushButton));

prints out 1

You are right, no need for converting. :slight_smile:

Ok, this is now strange. Seems the converting did something wrong. Now it's working. Don't know why.

The above makes a released button HIGH.

The following looks for a pressed button (LOW) to indicate DRY.

Yes it is in wrong order. Give me a second, it seems to work now. I change the code an test it again.

or 'wrong state' (of digitalRead(pushButton) )

int pushButton = 5;

void setup()
{
  Serial.begin(9600);
  pinMode(pushButton, INPUT_PULLUP);
}

void loop()
{
  if(digitalRead(pushButton) == LOW)
   {
      Serial.println("WET");
   } else {
      Serial.println("DRY");
   }
}

It is very strange. I tried now for two hours and it did not work. Now it is working. This must be some kind of spirituality of this forum. :smiley:
Thank you all!

1 Like

I like your rain catcher! If it is DIY, do you have the STL file and wire guage?

1 Like

Are you sure that you didn't have a bad connection ? I am suspicious of the values returned by analogRead() if you actually shorted the two poles of the sensor

1 Like

Yes could be. First i tried it on Input 1, then on Input 2 and now on Input 5.
Or it could be some water left somewhere i am not sure, but now it works like a charm. Tested it now with water. -> WET
After drying with some towel -> DRY

Of course. I can send you a 3mf file.
The wire gauge is just a normal wire we are using in our country for house installations.
Is named:
H07V-U 1,5mm²
And it has a diameter of 1.33mm
I can not upload the 3mf file here, but i can send it by email if you like?

There is also still room for some improvement of the sensor. :slight_smile:
If you have Solidworks i can also send you the raw solidworks file and you can modify it by yourself.

1 Like

I see the limited file types. Thank you for offering, but I will tinker with my printer (or some other material).

Nice project, nice design.

1 Like

Hi @gegy.

If you put it in a ZIP file, you can upload the ZIP file as an attachment to a forum post.

I doubt that a conductive rain sensor will reliably work for long.
Rain (clean water) is a poor conductor.
The metal electrodes will eventually oxidise/migrate, creating a bridge between electrodes.
I can think of better (longer lasting) ways of detecting rain.

  1. optical, as used in car windscreens.
  2. capacitive (non-exposed electrodes), like your smartphone screen.
  3. sound, with a contact microphone.

Leo..

1 Like

You are right, conductive sensors don't last that long. But since it's a homemade one, made with materials that you might have at home, it's not such a big problem to build a new one. I actually had a sensitive sensor (touch sensor) in use before, but it didn't trigger reliably. Optical and acoustic sensors cannot be made from materials that you have at home. But as I said, you are right, there are better and more durable solutions. :slight_smile:

Another possibility might be a small light plastic tray improvised so that when water reaches a certain level it tips over, empties, and triggers a micro switch before tilting back to its original position. A count could deliver duration and/or intensity info.