Other Arduino Codes and Videos by Robojax

Arduino code and video for 4 keys keypad

This is the Arduino code for 4 keys keypad

This video shows you how to use 4 key keypad for arduino.

Related Code and Videos

1-4 Keys Keypad
2-4x3 Kaypad
3-4x4 Keypad
4-4x4 Keypad Black (hard shell)
5-5x4 Keypad
6-4x3 Keypad: Controlling 8 Channel Relay

Resources for this code

  1. Library code for 4x4 Keypad
  2. Get Schematic diagram for this sketch from Arduino Course on Udemy
  3. Learn Arduino step by step from beginner to Advance (Coruse)
  4. Get Early Access to my videos via Patreon

 /*
 * This is the Arduino code for 4 keys Keypad.
 * watch the video for details and demo https://youtu.be/BiOh_Z2N7kk
 *  * 
 * Written by Ahmad Nejrabi for Robojax Video channel www.Robojax.com
 * Date: Dec 28, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * this code has been downloaded from http://robojax.com/learn/arduino/
// Recorded Dec 28, 2017 for Robojax.com

#define key1 2 //connect wire 1 to pin 2
#define key2 3 //connect wire 2 to pin 3
#define key3 4 //connect wire 3 to pin 4
#define key4 5 //connect wire 4 to pin 5

void setup() {
 Serial.begin(9600);
 pinMode(key1, INPUT_PULLUP);// set pin as input
 pinMode(key2, INPUT_PULLUP);// set pin as input
 pinMode(key3, INPUT_PULLUP);// set pin as input
 pinMode(key4, INPUT_PULLUP);// set pin as input   
}

void loop() {
  int key1S = digitalRead(key1);// read if key1 is pressed
  int key2S = digitalRead(key2);// read if key1 is pressed
  int key3S = digitalRead(key3);// read if key1 is pressed
  int key4S = digitalRead(key4);// read if key1 is pressed 
 // Code written for Robojax.com video Tutorial
     if(!key1S){
      Serial.println("key 1 is pressed");
     }
     if(!key2S){
      Serial.println("key 2 is pressed");
     }
     if(!key3S){
      Serial.println("key 3 is pressed");
     }
     if(!key4S){
      Serial.println("key 4 is pressed");
     }          
     delay(100);
}

		
		
				

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal