I have an Arduino Pro Micro (ebay clone), a 4x4 membrane keypad.
The code and everything like this works great, the problem I have is that if I touch the backside or the wires going from the keypad to the arduino, it goes crazy, it inputs all characters and numbers in a random order.
So what I'm thinking, may it be some pull-up resistor trouble ?
I have tested for shorts 50 times all over, and the code cant be the problem, since it works fine exept for when I touch the wires or backside of the membrane keypad.
Have anyone experienced something similar or have any tips what I can try ?
I have tried with two keypads, and two pro-micros, same problem with all.
So post the code?
taulen:
So what I'm thinking, may it be some pull-up resistor trouble ?
I don't know. Have you got any?
taulen:
the code cant be the problem
Yes it can.
taulen:
if I touch the backside or the wires going from the keypad to the arduino, it goes crazy, it inputs all characters and numbers in a random order.
So - the solution is obvious. Don't touch the backside or the wires going from the keypad to the Arduino. Solved!
{Did you realise there is in fact a proximity/ touch sensor library for the Arduino? How do you suppose it works?}
taulen:
So what I'm thinking, may it be some pull-up resistor trouble ?
I would most certainly be thinking along those lines. Of course, you are using the internal pull-ups, are you not? Silly to do otherwise, but you may not have the code quite right.
Of course, until you post the code - all of it - in code tags (using the [ # ] icon), we will never know, will we?
By popular demand, here comes the code ![]()
And thank you all for helping out !
/*############################## COUNTDOWN TIMER ##################################
From: Mike Myers (http://mikemyers.me) @netnutmike
Let's Make It Episode 42 (http://letmakeit.tv)
*/
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
//constants for Control Pin
int relayPin = 21;
char currentTimeValue[4];
int currentState = 1;
int timerSeconds = 0;
int lpcnt = 0;
//define the keypad
const byte rows = 4;
const byte cols = 4;
char keys[rows][cols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[rows] = {9,8,7,6};
byte colPins[cols] = {5,4,3,2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
*/
LiquidCrystal lcd(10, 16, 14, 15, 18, 19);
void setup()
{
lcd.begin(16, 2);
//display main screen
displayCodeEntryScreen();
//setup and turn off relay
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
//setup default time to 00:00
currentTimeValue[0]='0';
currentTimeValue[1]='0';
currentTimeValue[2]='0';
currentTimeValue[3]='0';
showEnteredTime();
}
void loop()
{
int l;
char tempVal[3];
char key = keypad.getKey();
//key pressed and state is 1
if (int(key) != 0 and currentState == 1) {
switch (key) {
case '*':
relayStatus(false);
currentTimeValue[0]='0';
currentTimeValue[1]='0';
currentTimeValue[2]='0';
currentTimeValue[3]='0';
showEnteredTime();
currentState = 1;
lpcnt = 0;
timerSeconds = 0;
break;
case '#':
tempVal[0] = currentTimeValue[0];
tempVal[1] = currentTimeValue[1];
tempVal[2] = 0;
timerSeconds = atol(tempVal) * 60;
tempVal[0] = currentTimeValue[2];
tempVal[1] = currentTimeValue[3];
tempVal[2] = 0;
timerSeconds = timerSeconds + atol(tempVal);
currentState = 2;
break;
default:
currentTimeValue[0] = currentTimeValue[1];
currentTimeValue[1] = currentTimeValue[2];
currentTimeValue[2] = currentTimeValue[3];
currentTimeValue[3] = key;
showEnteredTime();
break;
}
}
if (currentState == 2) {
if (int(key) != 0) {
if (key == '*') {
relayStatus(false);
displayCodeEntryScreen();
currentTimeValue[0]='0';
currentTimeValue[1]='0';
currentTimeValue[2]='0';
currentTimeValue[3]='0';
showEnteredTime();
currentState = 1;
lpcnt = 0;
timerSeconds = 0;
}
} else {
if (lpcnt > 9) {
lpcnt = 0;
--timerSeconds;
showCountdown();
if (timerSeconds <= 0) {
currentState = 1;
relayStatus(false);
displayCodeEntryScreen();
showEnteredTime();
} else {
relayStatus(true);
}
}
++lpcnt;
delay(100);
}
}
}
void showEnteredTime()
{
lcd.setCursor(9,1);
lcd.print(currentTimeValue[0]);
lcd.print(currentTimeValue[1]);
lcd.print("m:");
lcd.print(currentTimeValue[2]);
lcd.print(currentTimeValue[3]);
lcd.print("s");
}
void relayStatus(bool state)
{
if (state)
digitalWrite(relayPin, HIGH);
else
digitalWrite(relayPin, LOW);
}
void showCountdown()
{
char timest[6];\
clearScreen();
lcd.setCursor(0,0);
lcd.print("** Ferdig om: **");
lcd.setCursor(0,1);
lcd.print("***** ");
sprintf(timest, "%d:%.2d", (timerSeconds/60), (timerSeconds - ((timerSeconds/60)*60)));
lcd.print(timest);
lcd.print(" *****");
}
void displayCodeEntryScreen()
{
clearScreen();
lcd.setCursor(0,0);
lcd.print("*UV-EKSPONERING*");
lcd.setCursor(0,1);
lcd.print("Tid: ");
}
void clearScreen()
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
}
And yes, I'm "using" the internal resistors. Haven't added any externally, and I thought that the library takes care of using the internal ones automatically ?
As you can see I'm using a slightly modified example found on the net.