1

I saw a tutorial on linking a keypad using one pin, utilising several resistors: http://razibshahdat.blogspot.com/2018/05/one-single-analog-pin-keypad-control.html

I have this keypad, a 16x2 LCD, a PIR motion detector, and a DHT11 temperature & humidity sensor attached. Furthermore, I have an additional 5V power supply connected to the breadboard for additional power, although I'm not sure if this is required?

All components work as expected in the current configuration when only loading their relevant Arduino template code, except for the keypad. The keypad worked initially when nothing else was connected, but now the resistance values fed to the serial seem to jump, particularly in the first column. I tried to add some resistance between the first input of the keypad matrix and the live wire, which dampens the fluctuations but does not remove them completely. ![Schematic using Fritzing I have created a Fritzing sketch to try to make it a bit easier to understand, although I realise that it is still rather chaotic. I am new to Fritzing and Arduino and am still figuring things out.

Here is the isolated code for the keypad, which I am using to find the output values (which, as mentioned, are varying unpredictably), although this was working previously, on a more simple setup:

    // code adapted from: https://www.youtube.com/watch?v=W8ZSeLD90KA
    void setup() {
         Serial.begin(9600);  /* Define baud rate for serial communication */
    }
    
    void loop() {
      int keyIn;
      int keyVals [16] = {976, 450, 333, 244, 166, 138, 124, 109, 90, 81, 76, 70, 61, 57, 54, 51};
      char keys[16] = {'1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'};
      int range = 1;
    
      keyIn = analogRead(A1);
    
      String temp = "";
    
      if (keyIn > 2)
      {
        Serial.print(keyIn);
        for(int i=0; i<=15; i++)
        {
          // The values of the keys changed, that's why the following is commented out
          //if (keyIn >= keyVals[i]-range && keyIn <= keyVals[i]+range)
          //{
          //  temp = keys[i];
          //}
        }
       Serial.print(temp);
       Serial.println("");
       delay(500);
    }

}

Lastly, I intend for this board to be my master. I then intend to connect a slave through I2C with a DC motor, a servo motor, and an RGB LED. Does this seem feasible?

Please assist if you can.

If you have any additional advice, that too would be highly appreciated - thank you in advance!

2
  • 1
    you do not have a common ground connection between the arduino and the breadboard
    – jsotola
    Jul 10, 2021 at 18:37
  • Lower the resistance, that will reduce the coupled noise after you make sure all grounds are connected. There are other possibilities but the frizzy picture is useless to me.
    – Gil
    Jul 10, 2021 at 23:29

1 Answer 1

1

Your key values are:

int keyVals [16] = {976, 450, 333, 244, 166, 138, 124, 109, 90, 81, 76, 70, 61, 57, 54, 51};

The formula for the key values given in the OnewireKeypad library is:

float V = (voltage * float( R3 )) / (float(R3) + (float(R1) * float(R)) + (float(R2) * float(C)));
float Vfinal = V * ANALOG_FACTOR;

where:

  • voltage = 5 V
  • R1 = 1,000 Ω (the three horizontal ones in the schematic)
  • R2 = 4,700 Ω
  • R3 = 1,000 Ω (the pulldown to GND in the schematic)
  • R = row number 0 to 3
  • C = column number 0 to 3
  • ANALOG_FACTOR = 1023 / 5.0;

The keypad schematic given in the blogspot article is:

Onewire keypad schematic

I put the formula and parameters into an Excel spreadsheet and produced this:

Excel spreadsheet of Onewire formula

...which is different to your key values.

Have I misunderstood your circuit setup? Are you doing something different?

1
  • Thanks you for your detailed response Tim! It consisted of two errors: the one was my ground not being connected between the Arduino and the breadboard, which reduced jumping. Your recommendation of adding the 1 kOhm resistance between the ground and the keypad resistor setup was the finishing touch! Jul 12, 2021 at 20:14

Your Answer

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

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