Devices & Components
Arduino Nano Matter
Button Keypad 4x4 module
Resistor 220 ohmios
7 Segment Display-Common Anode
Software & Tools
Arduino IDE
Project description
Code
keypad + 7 sevegment
c
Find code below
1#include <Keypad.h> 2 3/* ===== Keypad setup ===== */ 4const byte ROWS = 4; 5const byte COLS = 4; 6 7char keys[ROWS][COLS] = { 8 {'1','2','3','A'}, 9 {'4','5','6','B'}, 10 {'7','8','9','C'}, 11 {'*','0','#','D'} 12}; 13 14byte rowPins[ROWS] = {9, 8, 7, 6}; // Connect to keypad ROW pins 15byte colPins[COLS] = {5, 4, 3, 2}; // Connect to keypad COL pins 16 17Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); 18 19/* ===== 7-segment pins (a–g) ===== */ 20int segA = 10; 21int segB = 11; 22int segC = 12; 23int segD = A0; 24int segE = A1; 25int segF = A2; 26int segG = A3; 27 28/* ===== Segment patterns for numbers 0–9 ===== */ 29/* Common Cathode (HIGH = ON) */ 30byte digits[10][7] = { 31 {1,1,1,1,1,1,0}, // 0 32 {0,1,1,0,0,0,0}, // 1 33 {1,1,0,1,1,0,1}, // 2 34 {1,1,1,1,0,0,1}, // 3 35 {0,1,1,0,0,1,1}, // 4 36 {1,0,1,1,0,1,1}, // 5 37 {1,0,1,1,1,1,1}, // 6 38 {1,1,1,0,0,0,0}, // 7 39 {1,1,1,1,1,1,1}, // 8 40 {1,1,1,1,0,1,1} // 9 41}; 42 43int segmentPins[7] = {segA, segB, segC, segD, segE, segF, segG}; 44 45void setup() { 46 for (int i = 0; i < 7; i++) { 47 pinMode(segmentPins[i], OUTPUT); 48 digitalWrite(segmentPins[i], LOW); 49 } 50} 51 52void loop() { 53 char key = keypad.getKey(); 54 55 if (key >= '0' && key <= '9') { 56 displayDigit(key - '0'); 57 } 58} 59 60/* ===== Display function ===== */ 61void displayDigit(int num) { 62 for (int i = 0; i < 7; i++) { 63 digitalWrite(segmentPins[i], digits[num][i]); 64 } 65}
Downloadable files
Keypad-Synced 7-Segment Display using Arduino Nano
Check the video for the project demonstration
Project Demo.mp4
Comments
Only logged in users can leave comments