The easiest way to ensure that a pin is kept at a known state is to use INPUT_PULLUP in its pinMode() to activate its internal pullup resistor. Then wire the pin so that it is taken LOW when the rain gauge is activated and detect the change to the LOW state
Wire the rain gauge contact between the input and 0v, no resistor, then it should work.
A2 measures 1 or 0 and I have to measure 0V, when it's not raining.
I doubt that. I would expect to always show 3V3, rain or no rain, except for a brief pulse to 0v lasting, maybe, 50ms each time the bucket tips. You won't see it unless you use an oscilloscope.
What kind of 'pulse'? Does the rain gauge act as a switch, connecting or disconnecting two pins briefly? Does it have power and ground pins and a separate signal pin? Is the signal pin an Open Collector (NPN) output? Perhaps you could point us to the details on the rain gauge so we could help.
SJ22 is solder to 3.3V
SJ2 is solder to R6 and GND
and of course A2 is connected to A2 of my micro-controller
The rain gauge has two wire anf has a magnet. Each time the buncket move the magnet close and send a HIGHT signal to A2. An interrupt happen and my variable is incremented.
From rhe schemtaic above, if there is no rain, the buncket does not move and A2 is DOWN because of R6. In my case, I measure 3.3V and I wonder if A2 of the microcontroller remind HIGH. That the reason why I wonder if I have to put it down with
digitalWrite(A2, LOW)
I read somewhere, R6 should be at least 10K, instead of 4.7K, but I am not sure about that
I can't make sense of it and what sense I can make makes no sense!
Where is the rain gauge? Is it J2? That seems to have 3 wires, not the 2 you said and not the 2 I expect.
It makes no sense to put a pull us and a pull down resistor on the same pin, all you are doing is creating a potential divider.
You don't need an external pull up / down / sideways / shake it all about resistor anyway, just use the internal one as you are already doing. Connect the rain gauge between 0V (gnd) and the pin. That's it. Nothing else.
Please create a new schematic to show you understand what I have said.
I think some confusion has arisen here. It appears that you consider the "normal" condition from the bucket is 0V, and you get a pulse of 3.3V each time the bucket tips. This is the opposite way round from what @PerryBebbington describes.
But what do you mean by a HIGH signal? Does the bucket switch have a HIGH and LOW connections, and it switches between the two? Or is it open circuit until the bucket tips, or what?
We need an EXACT description of how the wires are connected and how the magnetic switch is configured. A hand-drawn schematic would do - the one you've posted is very difficult to interpret. Once we've got all the information, we can get you going in a jiffy.
GRRRRR, forget my post, R6 was not well solderd. So, A2 was not pull down.
Now it's work, and A2 is GND. When the bucket toogle, ma variable is incrementing because A2 change of state of a short time DONW/UP/DOWN
My rain gauge has 2 wires. The red goes to 3.3V and the yellow goes to A2 with a pull down reststence.
When the bucket toogle, the magnet close the connection and A2 read a HIGH level. My interrupt function is called and my variable is incremented. Each incremention is 3.333ml of water. Then I count the nomber of incrementation in one hour and then I give the value of 0 to ma variable. And so on, each hour, as long is raining
Ho yes, because my board sleep 59mn and need less than one minute to take the measures. Then I need a interrupt to wakup the board, each time a drop toogle the bucket, and then the board goes back to sleep. Of course, when it is rainimg, the board will not sleep a lot