Connecting a Servo to a Keypad (Arduino Uno)

Hello! I have recently started understanding code and don't really know too much about it, although I am learning quickly. I was wondering if anyone could help me code in a servo into this code. I have a keypad, and once the password is entered correctly (in this case 314159) I want the servo to turn 90* for about 5-7 seconds, then go back to normal. How would I code that into this code? (FYI This is on an Arduino Uno)

Here's the code:

#include <Servo.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>


#define Password_Length 7


int signalPin = 13, i=0;


char Data[Password_Length];
char pass[Password_Length] = "314159";
char Master[Password_Length] = "444444";
byte data_count = 0;
bool Pass_is_good;
char customKey;
char newKey;


const byte ROWS = 4;
const byte COLS = 4;


char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};


byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};


Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);


//LiquidCrystal_I2C lcd(0x21, 16, 2);


void setup(){
//lcd.init();
//lcd.backlight();
Serial.begin(9600);
pinMode(signalPin, OUTPUT);


}


void loop(){


//lcd.setCursor(0,0);
//lcd.print(“Enter Password:”);
//Serial.print(“Enter Password: “);


customKey = customKeypad.getKey();
if (customKey){
Data[data_count] = customKey;
//lcd.setCursor(data_count,1);
Serial.print(Data[data_count]);
//lcd.print(Data[data_count]);
data_count++;
}


if(data_count == Password_Length-1)
{
//lcd.clear();


if(!strcmp(Data, pass))
{
//lcd.print(“Correct”);
Serial.println(); Serial.println("Correct password");
}
else
{
if (!strcmp(Data, Master))
{
//lcd.print(“Incorrect”);
Serial.println("Please input the new password: ");
for (i=0; i<3; i++)
{
newKey = customKeypad.waitForKey();
if (newKey)
{
pass[i] = newKey;
Serial.print(pass[i]);
}
//lcd.setCursor(data_count,1);
//lcd.print(Data[data_count]);
}
//Serial.print("New password is: "); Serial.println(pass);
}
else
{
Serial.println(); Serial.println("Wrong password");
}
delay(1000);
}
//lcd.clear();
clearData();
}
}


void clearData(){
while(data_count !=0){
Data; data_count = 0;
}
return;
}

Give us a bit more of a hint. Does the code do anything now? If so what does it do when you enter a code correctly? It's a pain trying to read your code when so many lines are commented out.

Steve

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.