Simulación bomba de conteo regresivo con clave, no funciona de manera correcta al momento de conectar fuente de 12V

El programa tiene un display que hace un conteo regresivo de 60min, una vez se introduce la clave correcta debe detenerse el reloj y me apertura un cerrojo electromagnetico alimentado a 12 V, la fuente principal es de 12V, el cual esta conectado a un reductor de voltaje para alimentar el arduino a 5V.
Problema: al conectarlo por USB desde el computador funciona de manera correcta, pero al conectarlo a la fuente de 12V no lee el teclado y no realiza la funcion como tal, me podrian ayudar

Codigo..

#include <TM1637Display.h>
#include <avr/sleep.h>

// Countdown Timer
const unsigned long COUNTDOWN_TIME = 3600; // 60 minutes in seconds

// Pins for TM1637 display module
#define CLK_PIN 2
#define DIO_PIN 3

TM1637Display display(CLK_PIN, DIO_PIN);

unsigned long startTime;
unsigned long currentTime;
unsigned long elapsedTime;

const int LED=12;
const int L2=13;

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {11, 10, 9, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char password[7];
char realpassword[7]= "7395";
byte index=0;

void setup() {
display.setBrightness(7); // Set the brightness of the display (0-7)
display.clear(); // Clear the display
startTime = millis(); // Record the starting time
pinMode(LED,OUTPUT);
Serial.begin(9600);
}

void loop() {
//digitalWrite(PULSO, LOW);

char key = keypad.getKey();
currentTime = millis(); // Get the current time
elapsedTime = (currentTime - startTime) / 1000; // Calculate elapsed time in seconds

if (elapsedTime <= COUNTDOWN_TIME) {
unsigned long remainingTime = COUNTDOWN_TIME - elapsedTime;

// Display remaining time in Minutes:Seconds format
// unsigned int hours = remainingTime % 60;
unsigned int minutes = remainingTime / 60;
unsigned int seconds = remainingTime % 60;

display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);

if (key != NO_KEY){
//Serial.println(key);
password[index]= key;
index++;
}
if (index==4){
byte check =0;
for(int i=0;i<4;i++){
Serial.print(password[i]);
if (password[i]==realpassword[i]){
check++;
}

 if (check== 4) {
    digitalWrite(LED, HIGH);
    digitalWrite(L2, HIGH);
    Serial.println("OK");
    stop();
     }else{
    digitalWrite(LED, LOW);
    Serial.println("INTENTA");
  }
  index=0;
  }
 }
 if (L2==HIGH){

stop();
}

if (remainingTime == 0) {
// Start blinking when countdown reaches 00:00

  delay(10);
  while (true) {
    display.showNumberDecEx(0, 0b01000000, true); // Display "00:00"
    delay(1000);
    display.clear(); // Clear the display
    delay(500);
    
  }
  }

}

}

void stop(){
Serial.flush();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
noInterrupts();
sleep_cpu();
}

Moderador:
Por favor, lee las Normas del foro y publica/edita tu código/error usando etiquetas de código.
Ve a edición, luego selecciona todo el código que has publicado/editado, lo cortas y click en (<CODE/>)




Agrega link de donde copiaste el código porque obviamente no es tuyo, si hay esquema electrónico mejor.
Que Placa estas usando?
No respondas la pregunta a continuación si editar cada cosa que te he solicitado.

La fuente que usas de 12V de que corriente es?

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