Connecting Output to Input + custom keypad

Hi, I'm newbie with arduino and it seems that I already destroyed one;) I'll try to simplify my project as much as possible. I made a simple keypad with 6 buttons (2 cols, 3 rows). I want to use INPUT_PULLUP to simplify the board and read 0 from input rows.

setup(){
  int col1 = 7;
  int col2 = 8;
  int row1 = 9;
  int row2 = 10;
  int row3 = 11;
  
  pinMode(col1, OUTPUT);
  pinMode(col2, OUTPUT);
  pinMode(row1, INPUT_PULLUP);
  pinMode(row2, INPUT_PULLUP);
  pinMode(row3, INPUT_PULLUP);

  digitalWrite(col1, HIGH);
  digitalWrite(col2, HIGH);
}

void loop() {
  int r1, r2, r3; //row inputs

  digitalWrite(col1, LOW);
  r1 = digitalRead(row1);
  r2 = digitalRead(row2);
  r3 = digitalRead(row3);
  digitalWrite(col1, HIGH);
  //someLogic(){}

  digitalWrite(col2, LOW);
  r1 = digitalRead(row1);
  r2 = digitalRead(row2);
  r3 = digitalRead(row3);
  digitalWrite(col2, HIGH);
  //someLogic(){}
}

What will happen if I connect: 1. HIGH output to PULLUP input 2. LOW output to PULLUP input

After few runs my Nano doesn't work anymore: avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x0d avrdude: ser_send(): write error: sorry no info avail avrdude: ser_recv(): read error: no access.

DanyWay: What will happen if I connect: 1. HIGH output to PULLUP input 2. LOW output to PULLUP input

I'm not sufficiently certain what you mean by that.

If you connect 5v to a pin set as INPUT_PULLUP it will read as HIGH If you connect GND (or 0v) to a pin set as INPUT_PULLUP it will read as LOW

You could derive the 5v and the 0v from another pin set as OUTPUT and written as HIGH or LOW

...R

What you describe should cause no damage. Connecting inputs to outputs through a switch is fine and done everyday, the input state will reflect the the output state if the switch is closed.

That said, we don't know how you have things connected. Please post a schematic or clear photos of the keypad, wiring and Nano.

Initial state:
pin 7 - col1 (OUTPUT, HIGH)
pin 8 - col2 (OUTPUT, HIGH)
pin 9 - row1 (INPUT_PULLUP)
pin 10 - row2 (INPUT_PULLUP)
pin 11 - row3 (INPUT_PULLUP)

Image from Reply #3 so we don’t have to download it. See this Simple Image Guide

ca503bcc014d5ecc9a9007cd9b0f62717fcb18b8.jpg

…R

Another idea, what will happen after connecting col1 and col2 (both OUTPUT, HIGH) by pressing 2 buttons at the same time? Could it damage Arduino?

Connecting 2 outputs could cause damage. If you need to do that make sure to put an external resistor in the circuit so that the maximum possible current is kept at or below 20 mA.

...R

Hi,
1K resistors in the col1 and col2 wires will prevent any damage to outputs.
keypadedit.jpg

Tom… :slight_smile: