Hello, I'm new in electric and I'm trying to use ESP8266 for controlling selenoid door lock, as picture attached.
I've checked ESP8266 works fine it could get data from firebase and send data to pin.
But I could not make it works with Selenoid Door Lock.
For battery I used 9v alkaline battery and it did work for selenoid door lock without relay when I checked it out. I've also already tried to replace battery with Adaptor 12V 2A.
I've already tried to use a diode parallel to magnetic locks but still does not work.
Could you please tell me where did the wiring go wrong?
Did it not work because I use 3.3v in ESP8266 as VCC in Relay Module?
Should I add Arduino Uno for Mikrocontroller to get 5v VCC?
Here is my circuit diagram :
And here is my source code in Arduino IDE:
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#define FIREBASE_HOST "esp8266-fb11b-default-rtdb.firebaseio.com" //Your Firebase Project URL goes here without "http:" , "\" and "/"
#define FIREBASE_AUTH "6r9o0ufnXx8AgOtILrnou7sJqrJOtAGEbgH6DEs2" //Your Firebase Database Secret goes here
#define WIFI_SSID "Rachmawatha" //your WiFi SSID for which yout NodeMCU connects
#define WIFI_PASSWORD "081357581200" //Password of your wifi network
// Declare the Firebase Data object in the global scope
FirebaseData firebaseData;
// Declare global variable to store value
int val=0;
void setup() {
pinMode(D7, OUTPUT);
Serial.begin(115200); // Select the same baud rate if you want to see the datas on Serial Monitor
Serial.println("Serial communication started\n\n");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP Address is : ");
Serial.println(WiFi.localIP()); //print local IP address
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
Firebase.reconnectWiFi(true);
delay(1000);
digitalWrite (D7, LOW);
}
void loop() {
// Firebase Error Handling And Reading Data From Specified Path ************************************************
if (Firebase.getInt(firebaseData, "/esp8266-fb11b-default-rtdb/data")) { // On successful Read operation, function returns 1
if (firebaseData.dataType() == "int") { // print read data if it is integer
val = firebaseData.intData();
Serial.print ("Kunci Pintu: ");
Serial.println(val);
digitalWrite(D7, val);
Serial.println("\n Change value at firebase console to see changes here.");
delay(2000);
}
} else {
Serial.println(firebaseData.errorReason());
}
}
I would really appreciate it if someone could help me.
Thank you.

