100% found this document useful (1 vote)
71 views

Arduino Keypad

The document defines code for an Arduino project that uses a 4x3 keypad connected to an Arduino. It initializes the keypad by defining the number of rows and columns, mapping the keys, and connecting the rows and columns to Arduino pins. It then defines a loop to read the keypad, print any pressed keys to the serial monitor, and turn on an LED.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
71 views

Arduino Keypad

The document defines code for an Arduino project that uses a 4x3 keypad connected to an Arduino. It initializes the keypad by defining the number of rows and columns, mapping the keys, and connecting the rows and columns to Arduino pins. It then defines a loop to read the keypad, print any pressed keys to the serial monitor, and turn on an LED.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <Keypad.

h>

const byte ROWS = 4; // Four rows

const byte COLS = 3; // Three columns

// Define the Keymap

char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'},


{'#','0','*'} };

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these


Arduino pins.

byte rowPins[ROWS] = { 9, 8, 7, 6 };

// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

byte colPins[COLS] = { 12, 11, 10 };

// Create the Keypad Keypad kpd = Keypad( makeKeymap(keys),


rowPins, colPins, ROWS, COLS );

#define ledpin 13

void setup()

pinMode(ledpin,OUTPUT);

digitalWrite(ledpin, HIGH);

Serial.begin(9600);

void loop()
{

char key = kpd.getKey();

if(key) // Check for a valid key.

switch (key)

case '1':

Serial.println(key);

break;

case '2':

Serial.println(key);

break;

case '3':

Serial.println(key);

break;

case '4':

Serial.println(key);

break;

case '5':

Serial.println(key);
break;

case '6':

Serial.println(key);

break;

case '7':

Serial.println(key);

break;

case '8':

Serial.println(key);

break;

case '9':

Serial.println(key);

break;

case '0':

Serial.println(key);

break;

case '*':

Serial.println(key);

break;

case '#':
Serial.println(key);

break;

You might also like