B4R Question I can't make it work esp8266 + relay Elegoo 4 +MFRC522

omarruben

Active Member
Licensed User
Longtime User
I need some help to make it work, read the card and open the relay

the esp8266 and the RFID work just fine, but when connected to the relays Elegoo4 can't even upload the code to the esp8266

2023-09-26 17_13_56-How to use RFID Reader with NodeMCU - RC522 RFID Reader Tutorial - YouTube...jpg

RELAY is connected to D8, GND,+5 v on the esp8266 (not on the picture)

* question: do I need an external 5v power supply?


what I am doing wrong ??


B4X:
Sub Process_Globals
    Public Serial1 As Serial
    
    
    Private rfid As MFRC522
    Private bc As ByteConverter
    Dim d1 As D1Pins
    Private d8 As Pin
    Private relay1 As Pin
    Private relay1State As Boolean
    
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")

    d8.Initialize(d1.D8, d8.MODE_OUTPUT)
    'relay1.Initialize(d1.D8, relay1.MODE_OUTPUT) 'Pin D8 ESP Relay 1
    d8.DigitalWrite(True)'True = 1 | Pin D8 Esp is Off | Relay_1 is Off
    relay1State = True
    
    rfid.Initialize(d1.D4, d1.D3, "rfid_CardPresent")
    rfid.LogVersion
    
End Sub

Sub rfid_CardPresent (UID() As Byte, CardType As Byte)
    Log("UID: ", bc.HexFromBytes(UID))
    relay1State = Not(relay1State)
    Log(relay1State)
    d8.DigitalWrite(relay1State)'Relay 1 ON/OFF House Alarm
End Sub
 
Solution
after a few days of researching:

final control entry Rfid Based Lock System.png


B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
  
  
    Private rfid As MFRC522
    Private bc As ByteConverter
    Dim d1 As D1Pins
    Private d0 As Pin
    Private relay1 As Pin
    Private relay1State As Boolean
  
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")

    d0.Initialize(d1.D0, d0.MODE_OUTPUT)
    'relay1.Initialize(d1.D8, relay1.MODE_OUTPUT) 'Pin D8 ESP Relay 1
    d0.DigitalWrite(True)'True = 1 | Pin D8 Esp...

omarruben

Active Member
Licensed User
Longtime User
after a few days of researching:

final control entry Rfid Based Lock System.png


B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
  
  
    Private rfid As MFRC522
    Private bc As ByteConverter
    Dim d1 As D1Pins
    Private d0 As Pin
    Private relay1 As Pin
    Private relay1State As Boolean
  
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")

    d0.Initialize(d1.D0, d0.MODE_OUTPUT)
    'relay1.Initialize(d1.D8, relay1.MODE_OUTPUT) 'Pin D8 ESP Relay 1
    d0.DigitalWrite(True)'True = 1 | Pin D8 Esp is Off | Relay_1 is Off
    relay1State = True
  
    rfid.Initialize(d1.D4, d1.D3, "rfid_CardPresent")
    rfid.LogVersion
  
End Sub

Sub rfid_CardPresent (UID() As Byte, CardType As Byte)
    Log("UID: ", bc.HexFromBytes(UID))
    relay1State = Not(relay1State)
    Log(relay1State)
    d0.DigitalWrite(relay1State)'Relay 1 ON/OFF House Alarm
  
End Sub

WORKS PERFECTLY!!!!!
total invested on hardware :$55 (and have left overs to make 3 more circuits) all fro Amazon, I don't put the links, I don't know if it is allowed
 
Last edited:
Upvote 0
Solution
Top