Components and supplies
Arduino UNO
4x4 keypad
SG90 Micro-servo motor
Grove - Mini Fan v1.1
LED, RGB
DC Motor, 12 V
Dual H-Bridge motor drivers L293D
9V battery (generic)
I2C 16x2 Arduino LCD Display Module
Tools and machines
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Breadboard, 270 Pin
Apps and platforms
Arduino IDE
Project description
Code
code
c_cpp
1#include <Keypad.h> 2#include<Servo.h> 3#include <Wire.h> 4#include <LiquidCrystal_I2C.h> 5LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display 6int servoPin =A0; 7Servo myServo; 8const int Forward = A1; 9const int Backward = A2; 10const int ROW_NUM = 4; //four rows 11const int COLUMN_NUM = 4; //three columns 12 13char keys[ROW_NUM][COLUMN_NUM] = { 14 {'1', '2', '3', 'A'}, 15 {'4', '5', '6', 'B'}, 16 {'7', '8', '9', 'C'}, 17 {'*', '0', '#', 'D'} 18}; 19 20byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad 21byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad 22 23Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 24 25const String password_1 = "1234"; // door open 26const String password_2 = "4321"; // door close 27const String password_3 = "5642"; // fan 28 29String input_password; 30 31int red_light_pin= 13; 32int green_light_pin = 12; 33int blue_light_pin = 11; 34void setup(){ 35 Serial.begin(9600); 36 lcd.init(); // initialize the lcd 37 lcd.backlight(); 38 myServo.attach(servoPin); 39 pinMode(leftForward , OUTPUT); 40 pinMode(leftBackward , OUTPUT); 41 pinMode(red_light_pin, OUTPUT); 42 pinMode(green_light_pin, OUTPUT); 43 pinMode(blue_light_pin, OUTPUT); 44 input_password.reserve(4); // maximum input characters is 4, change if needed 45} 46void setColour(int red_light_value, int green_light_value, int blue_light_value) 47 { 48 analogWrite(red_light_pin, red_light_value); 49 analogWrite(green_light_pin, green_light_value); 50 analogWrite(blue_light_pin, blue_light_value); 51} 52void loop(){ 53 char key = keypad.getKey(); 54 55 if (key){ 56 Serial.println(key); 57 lcd.setCursor(0, 0); 58 lcd.print(key); 59 switch (key) 60 { 61 case 'A': 62 setColour(255,0,0);//GREEN 63 break; 64 case 'B': 65 setColour(0,255,0);//GREEN 66 break; 67 case 'C': 68 setColour(0,0,255);//BLUE 69 break; 70 case 'D': 71 setColour(255,255,125);//RASPBERRY 72 break; 73 case '7': 74 setColour(255,0,255);//MAGENTA 75 break; 76 case '8': 77 setColour(225,255,0);//YELLOW 78 break; 79 case '9': 80 setColour(225,255,255);//WHITE 81 break; 82 default: 83 setColour(0,0,0); //NO COLOR 84 } 85 if(key == '*') { 86 input_password = "";// reset input password 87 lcd.clear(); 88 } else if(key == '#') { 89 lcd.clear(); 90 if(input_password == password_1) { 91 Serial.println("door unlocked"); 92 myServo.write(90); 93 lcd.setCursor(0, 0); 94 lcd.print("CORRECT!"); 95 lcd.setCursor(0, 1); 96 lcd.print("DOOR UNLOCKED!"); 97 98 99 } 100 else if(input_password == password_2){ 101 Serial.println("door locked"); 102 myServo.write(0); 103 lcd.setCursor(0, 0); 104 lcd.print("CORRECT!"); 105 lcd.setCursor(0, 1); 106 lcd.print("DOOR LOCKED!"); 107 108 } 109 else if(input_password == password_3){ 110 Serial.println("fan on"); 111 digitalWrite(Forward , HIGH); 112 digitalWrite(Backward , LOW); 113 lcd.setCursor(0, 0); 114 lcd.print("CORRECT!"); 115 lcd.setCursor(0, 1); 116 lcd.print("FAN ON!"); 117 118 } 119 else { 120 Serial.println("password is incorrect, try again"); 121 lcd.setCursor(0, 0); 122 lcd.print("INCORRECT!"); 123 lcd.setCursor(0, 1); 124 lcd.print("TRY AGAIN!"); 125 126 } 127 128 input_password = ""; // reset input password 129 } else { 130 input_password += key; string 131 lcd.setCursor(input_password.length(), 0); // move cursor to new point 132 lcd.print('*'); // print * key as hidden character 133 } 134 } 135} 136
Source Code
Github Source Code
Source Code
Github Source Code
code
c_cpp
1#include <Keypad.h> 2#include<Servo.h> 3#include <Wire.h> 4#include 5 <LiquidCrystal_I2C.h> 6LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address 7 to 0x27 for a 16 chars and 2 line display 8int servoPin =A0; 9Servo myServo; 10const 11 int Forward = A1; 12const int Backward = A2; 13const int ROW_NUM = 4; //four rows 14const 15 int COLUMN_NUM = 4; //three columns 16 17char keys[ROW_NUM][COLUMN_NUM] = { 18 19 {'1', '2', '3', 'A'}, 20 {'4', '5', '6', 'B'}, 21 {'7', '8', '9', 'C'}, 22 23 {'*', '0', '#', 'D'} 24}; 25 26byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect 27 to the row pinouts of the keypad 28byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; 29 //connect to the column pinouts of the keypad 30 31Keypad keypad = Keypad( makeKeymap(keys), 32 pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 33 34const String password_1 = "1234"; 35 // door open 36const String password_2 = "4321"; // door close 37const String 38 password_3 = "5642"; // fan 39 40String input_password; 41 42int red_light_pin= 43 13; 44int green_light_pin = 12; 45int blue_light_pin = 11; 46void setup(){ 47 48 Serial.begin(9600); 49 lcd.init(); // initialize the lcd 50 51 lcd.backlight(); 52 myServo.attach(servoPin); 53 pinMode(leftForward , 54 OUTPUT); 55 pinMode(leftBackward , OUTPUT); 56 pinMode(red_light_pin, OUTPUT); 57 58 pinMode(green_light_pin, OUTPUT); 59 pinMode(blue_light_pin, OUTPUT); 60 input_password.reserve(4); 61 // maximum input characters is 4, change if needed 62} 63void setColour(int red_light_value, 64 int green_light_value, int blue_light_value) 65 { 66 analogWrite(red_light_pin, 67 red_light_value); 68 analogWrite(green_light_pin, green_light_value); 69 analogWrite(blue_light_pin, 70 blue_light_value); 71} 72void loop(){ 73 char key = keypad.getKey(); 74 75 76 if (key){ 77 Serial.println(key); 78 lcd.setCursor(0, 0); 79 lcd.print(key); 80 81 switch (key) 82 { 83 case 'A': 84 setColour(255,0,0);//GREEN 85 86 break; 87 case 'B': 88 setColour(0,255,0);//GREEN 89 90 break; 91 case 'C': 92 setColour(0,0,255);//BLUE 93 94 break; 95 case 'D': 96 setColour(255,255,125);//RASPBERRY 97 98 break; 99 case '7': 100 setColour(255,0,255);//MAGENTA 101 102 break; 103 case '8': 104 setColour(225,255,0);//YELLOW 105 106 break; 107 case '9': 108 setColour(225,255,255);//WHITE 109 110 break; 111 default: 112 setColour(0,0,0); 113 //NO COLOR 114 } 115 if(key == '*') { 116 input_password = "";// 117 reset input password 118 lcd.clear(); 119 } else if(key == '#') { 120 lcd.clear(); 121 122 if(input_password == password_1) { 123 Serial.println("door unlocked"); 124 125 myServo.write(90); 126 lcd.setCursor(0, 0); 127 lcd.print("CORRECT!"); 128 129 lcd.setCursor(0, 1); 130 lcd.print("DOOR UNLOCKED!"); 131 132 133 134 } 135 else if(input_password == password_2){ 136 Serial.println("door 137 locked"); 138 myServo.write(0); 139 lcd.setCursor(0, 0); 140 lcd.print("CORRECT!"); 141 142 lcd.setCursor(0, 1); 143 lcd.print("DOOR LOCKED!"); 144 145 146 } 147 else if(input_password == password_3){ 148 Serial.println("fan 149 on"); 150 digitalWrite(Forward , HIGH); 151 digitalWrite(Backward 152 , LOW); 153 lcd.setCursor(0, 0); 154 lcd.print("CORRECT!"); 155 156 lcd.setCursor(0, 1); 157 lcd.print("FAN ON!"); 158 159 160 } 161 else { 162 Serial.println("password is incorrect, try again"); 163 164 lcd.setCursor(0, 0); 165 lcd.print("INCORRECT!"); 166 lcd.setCursor(0, 167 1); 168 lcd.print("TRY AGAIN!"); 169 170 } 171 172 input_password 173 = ""; // reset input password 174 } else { 175 input_password += key; 176 string 177 lcd.setCursor(input_password.length(), 0); // move cursor to new 178 point 179 lcd.print('*'); // print * key as hidden character 180 181 } 182 } 183} 184
Downloadable files
Servo motor
Servo motor
Connections
Connections
dc motor fan
dc motor fan
Connections
Connections
Connecting with arduino IDE software
Connecting with arduino IDE software
Servo motor
Servo motor
dc motor fan
dc motor fan
Comments
Only logged in users can leave comments
vidhi_kumari
0 Followers
•0 Projects
Table of contents
Intro
4
0