Does a input need to be pulldown

Dear all

I am abit frustrated about this question.

I have a microcontroller bas on Arduino Micro (ATSAMD21 MO).

I need to connecet a rain gauge to A2. Each time the bucket move a pulse is sent to A2.

pinMode(pin, INPUT_PULLUP)

A2 measures 1 or 0 and I have to measure 0V, when it's not raining.

I pull down A2 with a 4.7K but I always measure 3.3V at A2, whille I should measure 0V.

How can we explain that?
Now I wunder if I have to put down A2 in the setup() as the following

digitalWrite(A2, LOW)

To make sure to have 0V (LOW state)

Post your code, post your schematic.

Then I suspect that your wiring is wrong or your code is pulling it HIGH

Please post your full sketch but read How to get the best out of this forum first and follow the advice on posting code

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

pinMode(pin, INPUT_PULLUP)
Is correct.

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.


Here is the schematic

Forget R1, R1 is not connected to J2

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

Thanks for the schematic but...

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.

digitalWrite(A2, LOW)

Don't do that.

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.

I missed that. You don't need an interrupt, but that lesson is for after you get the basic input working.

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 :slight_smile:

Lost all afternoon because of the resistance

Like I said in reply #9...

We all have done similar things! Goes with the hobby :upside_down_face:

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 :slight_smile:

1 Like

@pierrot10 full details of your requirements at the start of the topic would have been more helpful