Arduino Mega - can not handle 24 simultaneous pullup inputs with long wires

Hi,

I am using an Arduino Mega 2560 to monitor 24 home alarm inputs.
I have set up 24 input pins as input pullups with pinMode(pinNumber,INPUT_PULLUP).

The normal state of the input is LOW since a window/door is normally closed.

When I try out the sketch on a local board with no wires connected it runs fine (even grounding the inputs to simulate a closed door/window).
But when I try at home where some longer cables are used (alarm cables can be as long as 25 metres) the board behaves in a strange way.

At times the main loop is not fired at all and the board keeps switching on and off.
Reducing the number of set-up input pullups solves the problem, since the sketch works on a disconnected board it must be due to the long wiring.

Any idea as to why this happens and if there is a solution?
The maximum number of input pullups seems to be around 10.

I was hoping a could monitor each single door/window but I am currently stuck.

Have I reaching the maximum 200 mA (correct?) total current limit ?

Thank you

E.

it's 800mA on a 2560 chip. try adding external 1k to 10k pullups.

It's like having 24 aerials connected to your Mega.
Your wiring should be twisted pair (Cat-5 or 6). One twisted pair to one sensor (signal and ground).
You could try adding 100n caps from each input to ground.

Or, a CrossRoads has suggested, use external pull-up resistors.
I wouldn't go as low as 1k (uses ~120mA from your 5volt rail).
But 4k7 (or 10k) should work.
Leo..

Your sensor wires pick up all kinds of Electro-Magnetic interference. You need use low-pass filters on every sensor input.
Long wires attached to sensitive inputs can, as you have experienced, induce unwanted switching of logical states. It can even be hazardous for the processor in case of nearby thunder-lightning. So you need to have some sort of protection/suppression circuits.

I believe the best way of doing this is to have a defined electrical groundplane, like f.i. a copperclad PCB board, under/close to the mega-board (sort of shielding). Mount screw-wire strips close to the mega board. Connect all the ground wires directly to the groundplane, connect 10k resistors between the positive 5-volt and the sensorWireInputs on the screwterminals. Place low-pass filters between the sensorWireInputs and the processorInputs (the connectors on the mega).

As your sensors are normally-closed contacts the sensor signals are of long duration so low-pass filtering of all signals above a few Hertz is allowed. Can easily done with a few resistors(or inductors) and capacitors.
Construct and connect each low-pass filter like this: Add 2 resistors of 10k each from every screwWireInput to every individual MegaInput. Between the 2 resistors connect a capacitor of 100nF and grondplane. Do not use the internal pullup's. Place all the low-pass filters and screwTerminals relative close to the atMega.

This will probably solve your EM-interference problems.

Hi,

thank you for the recommendations,

@CrossRoads, Wawa:

I read this topic:

http://forum.arduino.cc/index.php?topic=108476.0

And the issue might be related to the noise.

Why would an external pull-up resistor make a difference? (less noise presumably)
Should I then use only external pull-up resistors or add a resistor to the internal pull-up configuration?

The internal pull-up resistors should have a value between 20 and 50K so the current draw per pin when the circuit is closed should be really low (assuming 30K around 0.15 mA) and the total Arduino power drain should be well below the 800 mA.

Thanks

E.

External pull-up resistors can be of lower resistance. Lower value resistor means less probability of false reading. It helps against slow noise, such as mains noise.

However you are facing a different kind of noise called "electric fast transients" (EFT). It is very short and very active spikes occasionally induced on any wire and propagating to other wires. On their way spikes come through your board a kick off the microcontroller.

Pullup resistors do not help against this kind of noise. Very helpful would be to use optocouplers. Alternatively, it is helpful to insert resistors of about 100...1000 Ohm in series with incoming wires. Advise to use a low-pass filter is very good because there are such resistors in that filter too, while capacitors help to divert spikes away from microcontroller. It would be the best if ground pins of those capacitors connected together in one point, in that case spikes will jump from one wire to another without affecting microcontroller.