Cerrojo con un servomotor

Hola, tengo un problema con mi LCD 16x2, Soy nuevo en esto y estoy haciendo un cerrojo con un servomotor mediante un keypad, en el que introduces la clave correcta y el servo se mueve.

El problema está en que Cuando el display lcd me pide que introduzca la clave, los numeros que presiono en el keypad solo aparecen por una fracción de segundo en el display, no me permiten continuar con el pin de seguridad. Espero me puedan ayudar!.

//LCD config
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);

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

//Variables
int mot_min = 90;   
int mot_max = 180; 
int character = 0;
int activated =0;
char Str[16] = {' ', ' ', ' ', ' ', ' ', ' ', '-', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' '};  

//Pins
Servo myservo;
int buzzer=11;     
int external = 12; 
int internal = 13; 

//Keypad config
const byte ROWS = 4; 
const byte COLS = 4; 
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'D','#','0','*'},
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; 
byte colPins[COLS] = {9, 8, 7, 6}; 

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  myservo.attach(10); 
  pinMode(buzzer,OUTPUT); 
  pinMode(external,INPUT);
  pinMode(internal,INPUT); 
  
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.print("    PASSWORD");
  lcd.setCursor(0,1);
  lcd.print("      -***     ");
  
  myservo.write(mot_min);  
  
}
  
void loop(){

  if (digitalRead(external))
  {
     myservo.write(mot_max);
      lcd.clear();
      lcd.setCursor(2,0);
      lcd.print("INSIDE  OPEN");
      activated = 2;
      analogWrite(buzzer,240);
      delay(250);
      analogWrite(buzzer,200);
      delay(250);
      analogWrite(buzzer,180);
      delay(250);
      analogWrite(buzzer,250);
      delay(250);
      analogWrite(buzzer,LOW);
     
      
      lcd.clear();    
      lcd.setCursor(4,0);
      lcd.print("WELLCOME");
      
      lcd.setCursor(2,1);
      lcd.print("ELECTRONOOBS");
      

      lcd.clear();    
      lcd.setCursor(3,0);
      lcd.print("DOOR  OPEN");
      lcd.setCursor(2,1);
      lcd.print("ELECTRONOOBS");
      delay(500);
    
  }

  if (digitalRead(internal))
  {
    myservo.write(mot_min);
    activated = 0;
    character=0;
    Str[6]= '-';
    Str[7]= '*'; 
    Str[8]= '*'; 
    Str[9]= '*';
    Str[10]= ' ';   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
  }
    
  
  char customKey = customKeypad.getKey(); 
  
  if (customKey){

    if (character ==0)
    {  
    Serial.println(customKey);
    Str[6]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==1)
    {  
    Serial.println(customKey);
    Str[7]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==2)
    {  
    Serial.println(customKey);
    Str[8]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==3)
    {  
    Serial.println(customKey);
    Str[9]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==4)
    {  
    Serial.println(customKey);
    Str[10]= customKey;
    activated=1;
   
    }
    character=character+1;
  }

  if (activated == 1)
    {


    if(Str[10]='A' && character==5 && Str[6]=='3' && Str[7]=='0' && Str[8]=='0' && Str[9]=='7' )
    {
      myservo.write(mot_max);
      lcd.clear();
      lcd.setCursor(4,0);
      lcd.print("ACCEPTED");
      activated = 2;
      analogWrite(buzzer,240);
      delay(250);
      analogWrite(buzzer,200);
      delay(250);
      analogWrite(buzzer,180);
      delay(250);
      analogWrite(buzzer,250);
      delay(250);
      analogWrite(buzzer,LOW);
      delay(1000);
      
      lcd.clear();    
      lcd.setCursor(4,0);
      lcd.print("WELLCOME");
      delay(500);
      lcd.setCursor(2,1);
      lcd.print("ELECTRONOOBS");
      delay(1000);

      lcd.clear();    
      lcd.setCursor(3,0);
      lcd.print("DOOR  OPEN");
      lcd.setCursor(2,1);
      lcd.print("ELECTRONOOBS");
      
    }
    else
    {
      lcd.clear();    
      lcd.setCursor(1,0);
      lcd.print("PASSWORD ERROR");
      lcd.setCursor(3,1);
      lcd.print("TRY  AGAIN");
      analogWrite(buzzer,150);
      delay(3000);
      analogWrite(buzzer,LOW);
      character=0;
      Str[6]= '-';
      Str[7]= '*'; 
      Str[8]= '*'; 
      Str[9]= '*';
      Str[10]= ' ';
      activated = 0;
      lcd.clear();    
      lcd.setCursor(4,0);
      lcd.print("PASSWORD");
      lcd.setCursor(0,1);
      lcd.print(Str);   
    }
  }
  if (activated == 2)
    {
    if(customKey == 'B' )
    {
      myservo.write(mot_min);
      activated = 0;
      character=0;
      Str[6]= '-';
      Str[7]= '*'; 
      Str[8]= '*'; 
      Str[9]= '*';
      Str[10]= ' ';   
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("    PASSWORD");    
      lcd.setCursor(0,1);
      lcd.print(Str);
     
    }
  }  
}

Cerrojo_2.ino (5.14 KB)

I've deleted/merged your other cross-post(s) @Oscarito.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I've also moved your post to the International > Español forum board. In the future, if you want to post in Spanish, please use the appropriate forum board.

Yet another cross-post deleted. @Oscarito this is your final warning. If you do it again I'm going to give you an account suspension.

Hola, tengo un problema con mi LCD 16x2, Soy nuevo en esto y estoy haciendo un cerrojo con un servomotor mediante un keypad, en el que introduces la clave correcta y el servo se mueve.

El problema está en que Cuando el display lcd me pide que introduzca la clave, los numeros que presiono en el keypad solo aparecen por una fracción de segundo en el display, no me permiten continuar con el pin de seguridad. Espero me puedan ayudar!.

Nota:Estoy especulando que el problema pueda estar en el codigo, ya que el lcd parpadea muy rapidamente y me permite ver el caracter pulsado en el keypad, pero si modifico los siguientes valores:

(0x27,20,4)

El display deja de parpadear pero ya no me deja ver ningun caracter pulsado... Ya no se que mas puedo hacer, espero con su ayuda lleguemos juntos a una solucion.

//LCD config
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);

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

//Variables
int mot_min = 90;   
int mot_max = 180; 
int character = 0;
int activated =0;
char Str[16] = {' ', ' ', ' ', ' ', ' ', ' ', '-', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' '};  

//Pins
Servo myservo;
int buzzer=11;     
int external = 12; 
int internal = 13; 

//Keypad config
const byte ROWS = 4; 
const byte COLS = 4; 
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'D','#','0','*'},
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; 
byte colPins[COLS] = {9, 8, 7, 6}; 

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  myservo.attach(10); 
  pinMode(buzzer,OUTPUT); 
  pinMode(external,INPUT);
  pinMode(internal,INPUT); 
  
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.print("    PASSWORD");
  lcd.setCursor(0,1);
  lcd.print("      -***     ");
  
  myservo.write(mot_min);  
  
}
  
void loop(){

  if (digitalRead(external))
  {
     myservo.write(mot_max);
      lcd.clear();
      lcd.setCursor(2,0);
      lcd.print("INSIDE  OPEN");
      activated = 2;
      analogWrite(buzzer,240);
      delay(250);
      analogWrite(buzzer,200);
      delay(250);
      analogWrite(buzzer,180);
      delay(250);
      analogWrite(buzzer,250);
      delay(250);
      analogWrite(buzzer,LOW);
     
      
      lcd.clear();    
      lcd.setCursor(4,0);
      lcd.print("WELLCOME");
      
      lcd.setCursor(2,1);
      lcd.print("ELECTRONOOBS");
      

      lcd.clear();    
      lcd.setCursor(3,0);
      lcd.print("DOOR  OPEN");
      lcd.setCursor(2,1);
      lcd.print("ELECTRONOOBS");
      delay(500);
    
  }

  if (digitalRead(internal))
  {
    myservo.write(mot_min);
    activated = 0;
    character=0;
    Str[6]= '-';
    Str[7]= '*'; 
    Str[8]= '*'; 
    Str[9]= '*';
    Str[10]= ' ';   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
  }
    
  
  char customKey = customKeypad.getKey(); 
  
  if (customKey){

    if (character ==0)
    {  
    Serial.println(customKey);
    Str[6]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==1)
    {  
    Serial.println(customKey);
    Str[7]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==2)
    {  
    Serial.println(customKey);
    Str[8]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==3)
    {  
    Serial.println(customKey);
    Str[9]= customKey;   
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    PASSWORD");    
    lcd.setCursor(0,1);
    lcd.print(Str);
   
    }

    if (character ==4)
    {  
    Serial.println(customKey);
    Str[10]= customKey;
    activated=1;
   
    }
    character=character+1;
  }

  if (activated == 1)
    {


    if(Str[10]='A' && character==5 && Str[6]=='3' && Str[7]=='0' && Str[8]=='0' && Str[9]=='7' )
    {
      myservo.write(mot_max);
      lcd.clear();
      lcd.setCursor(4,0);
      lcd.print("ACCEPTED");
      activated = 2;
      analogWrite(buzzer,240);
      delay(250);
      analogWrite(buzzer,200);
      delay(250);
      analogWrite(buzzer,180);
      delay(250);
      analogWrite(buzzer,250);
      delay(250);
      analogWrite(buzzer,LOW);
      delay(1000);
      
      lcd.clear();    
      lcd.setCursor(4,0);
      lcd.print("WELLCOME");
      delay(500);
      lcd.setCursor(2,1);
      lcd.print("ELECTRONOOBS");
      delay(1000);

      lcd.clear();    
      lcd.setCursor(3,0);
      lcd.print("DOOR  OPEN");
      lcd.setCursor(2,1);
      lcd.print("ELECTRONOOBS");
      
    }
    else
    {
      lcd.clear();    
      lcd.setCursor(1,0);
      lcd.print("PASSWORD ERROR");
      lcd.setCursor(3,1);
      lcd.print("TRY  AGAIN");
      analogWrite(buzzer,150);
      delay(3000);
      analogWrite(buzzer,LOW);
      character=0;
      Str[6]= '-';
      Str[7]= '*'; 
      Str[8]= '*'; 
      Str[9]= '*';
      Str[10]= ' ';
      activated = 0;
      lcd.clear();    
      lcd.setCursor(4,0);
      lcd.print("PASSWORD");
      lcd.setCursor(0,1);
      lcd.print(Str);   
    }
  }
  if (activated == 2)
    {
    if(customKey == 'B' )
    {
      myservo.write(mot_min);
      activated = 0;
      character=0;
      Str[6]= '-';
      Str[7]= '*'; 
      Str[8]= '*'; 
      Str[9]= '*';
      Str[10]= ' ';   
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("    PASSWORD");    
      lcd.setCursor(0,1);
      lcd.print(Str);
     
    }
  }  
}

Hola oscarito.

Cada vez que en el loop lees una tecla, borras la pantalla, y haces cosas diferente. Debes estructurar mejor el código.

Si estas en la pantalla de password por ejemplo, no tienes que borrar, cada vez que haya un tecla pulsada, simplemente muestrala, aumenta el contador de caracteres y guardala. Cuando hayas contado el total de digitos, entonces haz la operación de comprobar y abrir la puerta o no.

Quizas te convenga utilizar una MAQUINA DE ESTADOS

Como consejo, deja de hacer doble post en todos lados, ya te estan adviertiendo los administradores que te van a sancionar. Si alguien no responde, es porque no hemos visto o no tenemos tiempo, y cada vez que vemos un código tenemos que analizarlo como es tu caso.

victorjam:
Hola oscarito.

Cada vez que en el loop lees una tecla, borras la pantalla, y haces cosas diferente. Debes estructurar mejor el código.

Si estas en la pantalla de password por ejemplo, no tienes que borrar, cada vez que haya un tecla pulsada, simplemente muestrala, aumenta el contador de caracteres y guardala. Cuando hayas contado el total de digitos, entonces haz la operación de comprobar y abrir la puerta o no.

Quizas te convenga utilizar una MAQUINA DE ESTADOS

Como consejo, deja de hacer doble post en todos lados, ya te estan adviertiendo los administradores que te van a sancionar. Si alguien no responde, es porque no hemos visto o no tenemos tiempo, y cada vez que vemos un código tenemos que analizarlo como es tu caso.

victorjam:
Hola oscarito.

Cada vez que en el loop lees una tecla, borras la pantalla, y haces cosas diferente. Debes estructurar mejor el código.

Si estas en la pantalla de password por ejemplo, no tienes que borrar, cada vez que haya un tecla pulsada, simplemente muestrala, aumenta el contador de caracteres y guardala. Cuando hayas contado el total de digitos, entonces haz la operación de comprobar y abrir la puerta o no.

Quizas te convenga utilizar una MAQUINA DE ESTADOS

Como consejo, deja de hacer doble post en todos lados, ya te estan adviertiendo los administradores que te van a sancionar. Si alguien no responde, es porque no hemos visto o no tenemos tiempo, y cada vez que vemos un código tenemos que analizarlo como es tu caso.

Hola victorjam, muchas gracias por responder y una disculpa por hacer los dobles posts, soy nuevo en esto de los foros...

Ya borré del codigo los comandos lcd.clear() y sigue sin dejarme ingresar la clave, solo me deja escribir el primer digito y se borra a medio segundo, no consigo que el digito se quede y avanze al siguiente para ingresar la clave completa.

Con respecto a la direccion, despues de investigar descubrí que no era el problema, y que era una 0x27, asi que eso ya quedó

No se especificamente que comandos tengo que borrar o tal vez haya algun codigo setCursor() mal estructurado.

Alguna otra sugerencia? Gracias de antemano.

Sinceramente no entiendo.
Les pongo un aviso a donde se ha movido el hilo, con información,

https://forum.arduino.cc/index.php?topic=651725.0

Hilo movido a Software y una y otra vez vuelves a postear en el foro en inglés, Sección General.

Si repites esto, tendras una sanción. No lo advertiré mas.

Hilo movido a Software y mezclado con el anterior por triple posteo.

Pregunta para Oscarito:

¿Por qué no utilizas directamente una cerradura de esas eléctricas y la abres con un relay?

He visto estos proyectos con servomotores y me parece de lo menos inseguro, a menos que la seguridad no sea un objetivo del proyecto.
-Si se va la luz o se agota la batería que alimenta el circuito, ¿Cómo abres la puerta?
-Si vas a cambiar de cerrojo, ¿Vas a desmontar el servo, adaptarlo al otro cerrojo... etc?
Me gustaría saber tu punto de vista.