Relays, weather station. Ok code- keeps disconnecting

I thought I’d answer your coding questions separately from your power supply question.

I’m not a fan of using the “D” pin references in you’re code when using ESP/MCU boards. It works, but it doesn’t help with code portability and makes it difficult to diagnose when inappropriate pins ave been selected.

I do it this way instead…

const int gate = 12;  // The number of the gate pin (Pin D6 on Wemos D1 Mini)

You’ve selected good GPIO pins (12 (D6), 13 (D7) and 5 (D1)), so presumably you’ve read this:

When you’re struggling to diagnose what’s happening with the program flow then it’s a good idea to add lots of Serial.print statements to your code and see what appears in the serial monitor; like this:

void emergencybtn()

{
  //REDBUTTON EMERGENCY
  previousMillis = millis();
  
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);
   
   //The button is pushed
   while (buttonState == HIGH) {
      
      currentValue = millis() - previousMillis;
      Serial.print("The button is pressed, currentValue = ");
      Serial.println(currentValue);
     
     if (currentValue > interval)  //If the button has been pressed for over 7 secs, open it
     {
      // save the last time relays has been turned on
      previousMillis = millis();   
      Serial.println("Opening the door....")
      digitalWrite(door, HIGH);      //opendoor
      delay(4000);     //give time to get in
      digitalWrite(door, LOW);    //close it
      Serial.println("The door is closed again")
      }
   
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);
   
   }
}

I’d also change the serial baud rate from 9600 to 74880 as this is the default for the D1 Mini and it allows you to see the D1 Mini’s system messages in the same serial monitor as your debug messages.

This will almost certainly lead to Blynk disconnection problems at some point. As I’ve said before, a countdown timer is the best way to do this stuff, but as you don’t seem to be happy to go down that route, then use a second millis() comparison to determine how long the gate has been open for, in the same way that you check how long the button has been pressed.

You may also need to throw some Blynk.run(); commands into your emergency button routine to keep Blynk fed with processor time.

One final observation, you’re checking to see if your emergency button is pressed every 2 seconds:

This means that it could be 2 seconds before the 7 second test begins, requiring a button press of between 7 and 9 seconds in total to release your door. If that’s a problem then reduce this to a few hundred milliseconds.

Pete.