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.
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!