1

In a project with an Atmega328 running at 8 MHz and powered from 3.3 V, I need to check if a 2-pin jumper is permanently inserted.

photo of 2-pin jumper example

So, the schematic is:

schematic diagram

and the board is:

PCB layout

I cannot figure it...

Is it really simple as:

1) Configure the PIN as INPUT_PULLUP?

2) Check if PIN is HIGH then is connected and do stuff?

3) Do I need external resistor (and what value) or is it sufficient the INTERNAL_PULLUP?

4) Can I leave the PIN shorted to GND for a massive amount of time, let's say for 1 year? This ATmega will be on "forever"

pseudocode, to understand:

void setup() {

  pinMode(PIN_CHECK , INPUT_PULLUP);

}

void loop() {

   // at first post, I did put this HIGH, but I was wrong.
   // the check need to be for LOW, when connected
   if ( PIN_CHECK == LOW ) {

     Serial.println("The user has placed the jumper, the pin is shorted to GND!");

   }


}

Thank you to all

sineverba
  • 303
  • 2
  • 11
  • 1
    I didn't look up the specific MCU. But if it supports an internal pull-up resistor, and if you activate that mode correctly, then yes you can apply the pull-up and configure the pin for input and detect the jumper. – jonk Oct 08 '17 at 16:52
  • 1
    If the jumper is installed, the pin will be LOW, not HIGH. – Peter Bennett Oct 08 '17 at 16:52
  • @PeterBennett ok, thank you for correction. But, for my 4 question? The answer is "YES" to the 4 questions? Thank you – sineverba Oct 08 '17 at 17:24
  • 1
    1) yes 2) low 3) internal pull-up enough for not very noisy environments 4) forever. But put decoupling 100-nF capacitors between AVCC/VCC and gnd. – next-hack Oct 08 '17 at 17:30
  • 1
    Also asked at: http://forum.arduino.cc/index.php?topic=504506 If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. – per1234 Oct 08 '17 at 22:49

1 Answers1

1

Is it really simple as

Almost:

  • you need one code change (as kindly mentioned in comments by Peter Bennett and next-hack while I was writing this)

  • Atmel recommend (see link below) that you add at least one decoupling capacitor between Vcc and Gnd, and an RC combination on the Reset pin, to help prevent spurious resets when relying on the internal pull-up alone in electrically noisy environments (a classic trigger is nearby relays operating). If you decided to change the design so that the Reset pin is driven by anything external, then a diode from the Reset pin to Vcc is also recommended.

1) Configure the PIN as INPUT_PULLUP?

Yes, you can do this whether or not you also add an external pull-up resistor.

2) Check if PIN is HIGH then is connected and do stuff?

Almost. The pin state to check for, is the pin being LOW with the jumper installed, so your code needs to be changed for that.

3) Do I need external resistor (and what value) or is it sufficient the INTERNAL_PULLUP?

From experience, I would consider adding an external pull-up resistor for the jumper pin input (e.g. 10k), especially if anything causing an electric field (e.g. fingers, nearby relays etc.) could come close to it, as the internal pull-up resistors are relatively weak. Other people with different experience may disagree that this is needed.

If you choose not to add an external pull-up resistor on that input pin, then you must enable its internal pull-up resistor.

4) Can I leave the PIN shorted to GND for a massive amount of time, let's say for 1 year? This atmega will be on "forever"

Yes, that is fine. There will be some power consumed through the pull-up resistor (whether internal or external) and that jumper.

There are other techniques that you could use to reduce power consumption e.g. sleeping, then waking every 100ms, checking the pin state, then sleeping again, if power consumption is a concern.

See:

for more information about "minimal" ATmega circuits.

SamGibson
  • 17,231
  • 5
  • 37
  • 58
  • 1
    Thank you for your answer. I know the need of capacitors, btw. My schema was simple to render the main focus. Thank you. – sineverba Oct 09 '17 at 05:17