0

I'm currently assembling a prototype of the lightning infrastructure (based on several MEGAs interconnected via RS485, as described in this other post)

The prototype consists of three MEGAs, a couple of wall-push-button and the two relay modules here below:

Obviously I've:

  • connected one endpoint of each push-buttons to Arduino INPUT-PIN; the other endpoint to ground;
  • connected the relay-module control-pins to Arduino OUTPUT-PIN (and ensuring a properly connected ground).
  • connected lamps to relay-modules power connectors.

My question relates to "pull-up resistor": I've read in lots of places that when involving push-buttons, "pull-up resistors" are needed in order to prevent shorts between ground and input-pin. As such, there are lots of tutorial/videos on the web, showing a nice resistor added in the push-button circuit.

Further investigating, I've also learnt from the official documentation that "...There are 20K pullup resistors built into the Atmega chip that can be accessed from software....", by setting the pinMode() as INPUT_PULLUP or setting it to INPUT and the forcing a digitalWrite(<PIN>,HIGH).

So, I ended:

  • directly connecting the two relay-modules to MEGAs INPUT-PINs and...
  • ...activating the internal pull-up, with digitalWrite(<INPUT_PIN>,HIGH);

Nothing more.

This is the second evening I'm "testing" my Arduino-luggage-prototype and... lamps are turning on/off like a charm, without any noticeable problem.

The question is: am I doing something nasty toward my MEGAs? Is the approach depicted above, a commonly-safe (as for the Arduino's health) approach?


P.S.: should you wonder about how the prototype looks like, here is a photo (actually, taken right after the first power-up ;-)

enter image description here

2 Answers 2

0

Connecting one side of a switch to ground and the other side to an input pin (with its pinmode set to INPUT_PULLUP) is a standard way of connecting control switches to an Arduino installation, and is not a problem.

Note, claims that built-in pull-ups are 20KΩ oversimplifies the situation. See, for example, Table 28.2, DC Characteristics, in the ATmega48PA/88PA/168PA/328P specs, which shows a min value of 20KΩ for I/O Pin Pull-up Resistors and a max value of 50KΩ. I've measured resistances of about 40KΩ, IIRC, whenever I've measured the pull-up values.

Note, built-in pull-ups typically are of too much resistance to work as pull-ups for TWI/SPI/I2C communications.

Note, when you say in the question that you connected the relay-modules to input pins and they worked ok, I suppose that could be the case, but in general it is better to put i/o pins into output mode when you want to drive an output. When you send LOW to an input pin, its built-in pull-up is turned off, the input impedance becomes high, and then the pin can float to any value between ground and Vcc. It might fail to turn off an attached device if that device also has high impedance.

1
  • As for the connection of relay-modules, I'm sorry! It's a typo (that I've just fixed): relay modules are driven by OUTPUT pins. Not input. Commented Oct 24, 2015 at 22:57
0

I am making the assumption the push buttons are wired directly to the mega. This may work but for me it is not acceptable. Why? All of those wires act as an antenna array tuned to a lot of different frequencies. My favorite trick is to use a 74C14 Schmidt trigger chip. The reason is several fold. First it isolates the antennas from the processor. The family I use will tolerate about 25volts input, giving a lot of head room. Second it makes the software a bit easier, all switches come in positive true. Third I use a low pass network in front so if one of the mains hits it it will probably survive. What I do is Pull up with a resistor that will cause about 1.5 ma to flow through the switch. This value is dependent on your voltage, I typically use 12 or 24 VDC. This input then goes through a 100K resistor to the input of the gate where I also put a .01 uF cap.

I am also working on a similar project, I made the same decision on a hardwired network about 15 years ago. All the switching is on several output boards (5V) located in a PC AT. I also chose the mega for several reasons, first I needed full duplex with my network, the MAX485 will do that you just have to leave the receive enabled and cycle the transmit when you want to send something. I also added a low pass on the (A line I Think) to another pin so I could determine if the network was busy, I currently have about 150 outputs with very few inputs. Code is all in ASM86.

I hope this helps, I will see if I can add to your reference question.

Thanks, Gil

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.