Components and supplies
Arduino UNO
keypad 4×4
SG90 Micro-servo motor
Project description
Code
untitled
arduino
1#include <Servo.h> 2 3#include <LiquidCrystal.h> 4 5#include <Keypad.h> 6Servo myservo; 7 8const int ROW_NUM = 4; //four rows 9const int COLUMN_NUM = 4; //four columns 10 11char keys[ROW_NUM][COLUMN_NUM] = { 12 {'1','2','3', 'A'}, 13 {'4','5','6', 'B'}, 14 {'7','8','9', 'C'}, 15 {'*','0','#', 'D'} 16}; 17 18byte pin_rows[ROW_NUM] = {9,8,7,6}; //connect to the row pinouts of the keypad 19byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad 20 21Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 22 23String inputString; 24long inputInt; 25LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 26void setup() { 27 Serial.begin(9600); 28 inputString.reserve(10); 29 myservo.attach(10);// maximum number of digit for a number is 10, change if needed 30} 31 32void loop() { 33 char key = keypad.getKey(); 34 35 if (key) { 36 Serial.println(key); 37 38 if (key >= '0' && key <= '9') { // only act on numeric keys 39 inputString += key; // append new character to input string 40 } else if (key == '#') { 41 if (inputString.length() > 0) { 42 inputInt = inputString.toInt(); // YOU GOT AN INTEGER NUMBER 43 inputString = ""; // clear input 44 // DO YOUR WORK HERE 45 46 } 47 } else if (key == '*') { 48 inputString = ""; // clear input- 49 } 50 } 51 if (key==3456){ 52 myservo.write(90); 53 54 } 55 else{ 56 myservo.write(0); 57 } 58 }
untitled
arduino
1#include <Servo.h> 2 3#include <LiquidCrystal.h> 4 5#include <Keypad.h> 6Servo myservo; 7 8const int ROW_NUM = 4; //four rows 9const int COLUMN_NUM = 4; //four columns 10 11char keys[ROW_NUM][COLUMN_NUM] = { 12 {'1','2','3', 'A'}, 13 {'4','5','6', 'B'}, 14 {'7','8','9', 'C'}, 15 {'*','0','#', 'D'} 16}; 17 18byte pin_rows[ROW_NUM] = {9,8,7,6}; //connect to the row pinouts of the keypad 19byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad 20 21Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 22 23String inputString; 24long inputInt; 25LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 26void setup() { 27 Serial.begin(9600); 28 inputString.reserve(10); 29 myservo.attach(10);// maximum number of digit for a number is 10, change if needed 30} 31 32void loop() { 33 char key = keypad.getKey(); 34 35 if (key) { 36 Serial.println(key); 37 38 if (key >= '0' && key <= '9') { // only act on numeric keys 39 inputString += key; // append new character to input string 40 } else if (key == '#') { 41 if (inputString.length() > 0) { 42 inputInt = inputString.toInt(); // YOU GOT AN INTEGER NUMBER 43 inputString = ""; // clear input 44 // DO YOUR WORK HERE 45 46 } 47 } else if (key == '*') { 48 inputString = ""; // clear input- 49 } 50 } 51 if (key==3456){ 52 myservo.write(90); 53 54 } 55 else{ 56 myservo.write(0); 57 } 58 }
untitled
arduino
1#include <Servo.h> 2 3#include <LiquidCrystal.h> 4 5#include <Keypad.h> 6Servo 7 myservo; 8 9const int ROW_NUM = 4; //four rows 10const int COLUMN_NUM = 4; 11 //four columns 12 13char keys[ROW_NUM][COLUMN_NUM] = { 14 {'1','2','3', 'A'}, 15 16 {'4','5','6', 'B'}, 17 {'7','8','9', 'C'}, 18 {'*','0','#', 'D'} 19}; 20 21byte 22 pin_rows[ROW_NUM] = {9,8,7,6}; //connect to the row pinouts of the keypad 23byte 24 pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad 25 26Keypad 27 keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 28 29String 30 inputString; 31long inputInt; 32LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 33void 34 setup() { 35 Serial.begin(9600); 36 inputString.reserve(10); 37 myservo.attach(10);// 38 maximum number of digit for a number is 10, change if needed 39} 40 41void loop() 42 { 43 char key = keypad.getKey(); 44 45 if (key) { 46 Serial.println(key); 47 48 49 if (key >= '0' && key <= '9') { // only act on numeric keys 50 inputString 51 += key; // append new character to input string 52 } else if (key 53 == '#') { 54 if (inputString.length() > 0) { 55 inputInt = inputString.toInt(); 56 // YOU GOT AN INTEGER NUMBER 57 inputString = ""; // clear 58 input 59 // DO YOUR WORK HERE 60 61 } 62 } else if (key == '*') 63 { 64 inputString = ""; // clear input- 65 } 66 } 67 68 if (key==3456){ 69 myservo.write(90); 70 71 } 72 else{ 73 myservo.write(0); 74 75 } 76 }
Downloadable files
website_9_YB6WX87KRF.png
website_9_YB6WX87KRF.png
Comments
Only logged in users can leave comments
pranavmadhavaram
0 Followers
•0 Projects
0