Arduino keypad 4 Button Key Module

Hello,

As I’ am a newbie in Arduino, I would appreciate for your help.

I’m currently trying to create a PID controller based on Arduino PID for Espresso V2.0 by Ross Satchell project.

Everything is working fine till now but I can’t make the 4 button switch to work with the PID menu.

When I connect it and try to press any of the buttons nothing happens.

Can someone instruct me what I'm doing wrong?

Im using this keypad :

Any ideas??

When I connect it and try to press any of the buttons nothing happens.

We need to see the sketch you are using.
Did you use:
pinMode( X ,INPUT_PULLUP) // X = 10, 11, 12, 13 ?

Dear LarryD,

In the code there is the below :

const int buttonPinLeft = 13; // pin for the Up button
const int buttonPinRight = 10; // pin for the Down button
const int buttonPinEsc = 12; // pin for the Esc button
const int buttonPinEnter = 11; // pin for the Enter button

And for pinmode the following :

pinMode(buttonPinLeft, INPUT);    //setup input buttons
 pinMode(buttonPinRight, INPUT);
 pinMode(buttonPinEnter, INPUT);
 pinMode(buttonPinEsc, INPUT);

I do not see a pull up resistor on your board.

Use the following for all four inputs:

pinMode(13,PULL_PULLUP);

etc.

Best to show all your code when attaching it.

Thanks for the quick reply....

When I use :

pinMode(X ,INPUT_PULLUP);

and as soon as I restart the Arduino, it keeps changing the menu automaticly without even push a button.

The code is a little bit large, can I uploaded here ?

You can attach the complete .ino file to a post so we can download it.

If you are using:
if (digitalRead(13));

You may have to use:
if (!digitalRead(13));

Ok thanks for the info and the help provided.

I have attached the .ino file.

Just a remark, this is not my code.

I have just modified it to suit my needs.

Arduino_PID_for_Espresso_v2_0.ino (24.1 KB)

Try changing the HIGH to LOW in these lines.

//records which button has been pressed
if (buttonEnterState==HIGH){
lastButtonPushed=buttonPinEnter;
enter = true;
right = false;
left = false;

}else if(buttonEscState==HIGH){
lastButtonPushed=buttonPinEsc;
//escape = true;
enter = false;
right = false;
left = false;

}else if(buttonRightState==HIGH){
lastButtonPushed=buttonPinRight;
right = true;
left = false;
enter = false;

}else if(buttonLeftState==HIGH){
lastButtonPushed=buttonPinLeft;
left = true;
right = false;
enter = false;

Be consistent:

long unsigned lastMillis;
unsigned long nowMillis;

Change to

unsigned long lastMillis;
unsigned long nowMillis;

Cutting the lawn now. . .

Thanks for your time...but it didnt worked.

I'll try again, to solve this.

Disable sections of code by commenting strategic lines out to see if you can narrow things down.

Maybe try some serial prints on variables to see that their values are what you think they are.

Thats what I'm trying to do now.

I'll share the results later.

thanks Larry for all your help.

FYI
The commented lines here effectively do the same as INPUT_PULLUP

pinMode(buttonPinLeft, INPUT);    //setup input buttons
  pinMode(buttonPinRight, INPUT);
  pinMode(buttonPinEnter, INPUT);
  pinMode(buttonPinEsc, INPUT);
  
  //digitalWrite(buttonPinLeft, HIGH);
  //digitalWrite(buttonPinRight, HIGH);
  //digitalWrite(buttonPinEnter, HIGH);
  //digitalWrite(buttonPinEsc, HIGH);

Did you comment them out?

LarryD finally I did it, its working great now.

What I did was set the digital.Write High in order to enable the pull up resistor according to the manufacture.

Then I send the button state to serial.print and I was suprised to see that the button state was 1 when idle and 0 when pressed.

So I modified the code as following:

void readButtons(){ //read buttons status
int reading;
int buttonEnterState=digitalRead(buttonPinEnter); // the current reading from the Enter input pin
int buttonEscState=digitalRead(buttonPinEsc); // the current reading from the input pin
int buttonLeftState=digitalRead(buttonPinLeft); // the current reading from the input pin
int buttonRightState=digitalRead(buttonPinRight); // the current reading from the input pin

The above worked great, thanks !! :slight_smile:

totemos:
I was suprised to see that the button state was 1 when idle and 0 when pressed.

That's a consequence of using pullUP: the pin is taken up to high normally, and is then taken low when you activate the switch. For that reason, this approach is known as "active low".

Good for you for sticking with it!

JimboZA:
That's a consequence of using pullUP: the pin is taken up to high normally, and is then taken low when you activate the switch. For that reason, this approach is known as "active low".

Thanks for sharing the sceintific point of you.

Good for you for sticking with it!

;D ;D