Auto output from un connected pins

am testing a sketch in serial monitor taking input from piezo disc on pin4 & pin5 using Matrix . but other unconnected
pins are also giving output some time ,you can see my serial monitor image.
my circuit is same as show on attachment image. no any wire is sparking or shorted.

skecth ,result,circuit is in attachment

please tell why others pins are giving auto response some time

new_for_uno.ino (17.6 KB)

44 posts and you still can't use code tags?

BJHenry: 44 posts and you still can't use code tags?

17.6k

...R

Images from Original Post so we don't have to download them. See this Simple Image Posting Guide

|500x198

|375x500

...R

Sorry, but I am too lazy to study 17k of code to try to relate it to your images.

Perhaps you can create a short (1k or 2k) program that illustrates the problem?

…R

am so sorry ,
i made large khilara code

but please see this simple code

#include <Keypad.h>

const byte ROWS = 4; //five rows
const byte COLS = 8; //three columns             // tested ok display Key number
char keys[ROWS][COLS] = {
{1,2,3,4,5,6,7,8},
{9,10,11,12,13,14,15,16},
{17,18,19,20,21,22,23,24},
{25,26,27,28,29,30,31,32},
};
byte rowPins[ROWS] = { 3, A1, A2, A3}; //connect to the row6 pinouts of the kpd     { 3, A1, A2, A3};
byte colPins[COLS] = {4, 5, 6, 7, 8, 9, 10, 11}; //connect to the column8 pinouts of the kpd    {4, 5, 6, 7, 8, 9, 10, 11};
                  
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup() {
  Serial.begin(9600);
  }

 
void loop() {
  
    if (kpd.getKeys())
    {
             for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
        {
           int myKey = (kpd.key[i].kchar);

              if (( kpd.key[i].stateChanged ) &&  (kpd.key[i].kchar == 1)) 
            {
                switch (kpd.key[i].kstate) {                     
                    case PRESSED:                    
                    Serial.println("PAD-1 ");
                break;
                }
            }  
            if (( kpd.key[i].stateChanged ) &&  (kpd.key[i].kchar == 2)) 
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                     
                     case PRESSED:
                   Serial.println("PAD----2");
                break;

                }
            }  
               if (( kpd.key[i].stateChanged ) &&  (kpd.key[i].kchar == 3)) 
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                     
                     case PRESSED:
                     Serial.println("PAD-----3");
                break;
                }
            }  
             if (( kpd.key[i].stateChanged ) &&  (kpd.key[i].kchar == 4)) 
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                     
                     case PRESSED:
                     Serial.println("PAD----4");
                }
            }  
             if (( kpd.key[i].stateChanged ) &&  (kpd.key[i].kchar == 5))
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                     
                     case PRESSED:
                     Serial.println("PAD---5");
                break;
                }
            }  
             if (( kpd.key[i].stateChanged ) &&  (kpd.key[i].kchar == 6)) 
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                     
                     case PRESSED:
                     Serial.println("PAD----6");
                break;
                }
            }  
             if (( kpd.key[i].stateChanged ) &&  (kpd.key[i].kchar == 7)) 
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                     
                     case PRESSED:
                    Serial.println("PAD----7");
                break;
                }
            }  
             if (( kpd.key[i].stateChanged ) &&  (kpd.key[i].kchar == 8)) 
            {
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                     
                     case PRESSED:
                     Serial.println("PAD----8");
                     break;
                }
            }  
        }
    }
}

i have connected piezo to pin4 & pin5 with pin3 . other pins are not connected. when i am hitting piezo

other pins giving output in serial moniter some time time auto matic
why???

Do the spurious outputs only happen when you hit the piezos?

I wonder if the Keypad library uses INPUT_PULLUP to prevent floating pins?

...R

I don’t know for sure which Keypad library @charnjit is using, but the common one does:

 for (byte r=0; r<sizeKpd.rows; r++) {
 pin_mode(rowPins[r],INPUT_PULLUP);
 }

I don’t think it could work any other way.

pert: I don't think it could work any other way.

Clearly not. :grinning:

charnjit: am testing a sketch in serial monitor taking input from piezo disc on pin4 & pin5 using Matrix . but other unconnected pins are also giving output some time ,you can see my serial monitor image.

Hang on! :astonished: Are we talking about the keypad library, or are we talking about piezos? Two completely different and totally unrelated things. What is going on here? :roll_eyes: Have I missed something?

Paul__B: Clearly not. :grinning: Hang on! :astonished: Are we talking about the keypad library, or are we talking about piezos? Two completely different and totally unrelated things. What is going on here? :roll_eyes: Have I missed something?

Do you mean,,,, piezo sensor can not be use in matrix library circuit ???

Hi,
I think you had better tell us what you are trying to achieve.
A keyboard made of piezo elements as the keys?
If you are only using two keys, then the matrix library is a waste of resources, for a start you are having to use 3 I/O.
If you used them a simple keys, 2 I/O and gnd.
What voltage are you expecting out of the piezo units when you “press” them?
Why?

Thanks… Tom… :slight_smile:

TomGeorge: Hi, I think you had better tell us what you are trying to achieve. A keyboard made of piezo elements as the keys? If you are only using two keys, then the matrix library is a waste of resources, for a start you are having to use 3 I/O. If you used them a simple keys, 2 I/O and gnd. What voltage are you expecting out of the piezo units when you "press" them? Why? |500x211 Thanks.. Tom... :)

I am going to check it with 2 piezo but my project is midi device which requires 16 piezo,16 push buttons , 3 potentiometers, 1 oled display I2C ..Arduino board will be used 32u4 in future. What you think . how can add these input components && which board in Arduino boards in simple way????

charnjit: Do you mean,,,, piezo sensor can not be use in matrix library circuit ???

Correct.

Quite incredulous that others have been providing answers but not realised such a blindingly obvious detail. :astonished: :roll_eyes: :astonished:

Paul__B: Quite incredulous that others have been providing answers but not realised such a blindingly obvious detail. :astonished: :roll_eyes: :astonished:

The code posted in #5 suggests there is a LOT more connected to that Arduino than just two piezos! 4 rows and 8 columns (those comments are wrong) for a total of up to 32 keys.

Far more incredulous is why the OP has ever decided that it's a good idea to set up a 4x8 button matrix and then tries to read 2 non-button inputs with it! Just reading the thread I at first just ignored the keypad parts in that sketch, assuming that's just something they should have left out building a minimal sketch but for whatever reason didn't (which is something that happens all the time here).

charnjit: 16 piezo,16 push buttons , 3 potentiometers, 1 oled display I2C

3 pots: 3 analog inputs.

Display: SDA & SCL pins (I2C).

16 piezo = 16 inputs - if voltage is high enough (>3V) this can be directly connected to digital inputs, otherwise need analog inputs or adding a comparator for high enough voltage for digital input. Considering the time it takes to take an analog reading, the comparator may be a good solution. Maybe this can be read through a 16-bit port extender & its interrupt function, for just one extra pin for the interrupt (you have I2C already for the display)

16 push buttons: 4x4 matrix = 8 inputs. Could be an I2C port extender for no extra pins (again, you have I2C already for the display).

Hi, Why do you need the piezo elements, won't a pushbutton switch be easier the use?

Tom... :)