Introduction: Build a Hands Free Automatic Gate Opener With ESP32 and JENCE J4220U
Say goodbye to fumbling around for your access cards or fobs! This project shows you how to integrate the JENCE J4220U UHF RFID Reader with an ESP32 microcontroller to create a truly automatic, long-range gate access system for your home or parking facility. Using your car's unique RFID tag, the gate will open from up to 14 feet away, ensuring seamless entry.
The Problem: Slow, Inconvenient Access
Traditional parking access often relies on short-range readers, requiring you to stop, roll down your window, and physically tap a card. This is frustrating in bad weather or high-traffic situations. Then there's primitive manual gate opening which is still being used in many places.
The Solution: Hands-Free UHF Automation
We'll use the JENCE J4220U extended-range reader (902-928MHz) to reliably read a tag from several meters away. The tag's unique ID will be sent to an ESP32 board, which checks the ID against an authorized list and triggers a Relay Module to momentarily open the gate. The ESP32's Wi-Fi capability also allows for easy remote management.
Supplies
Materials and Tools Required
- JENCE J4220U UHF Reader Writer (1 piece/set)
- ESP32 Development Board 38 pins (1pc | Any standard 30-pin board works)
- 5V Relay Module (1 or 2 Channel) (1 pc | To switch the gate control signal)
- Mosfet (1pc | CSD18532KCS)
- Resistor (1pc | 10 kΩ [Pull-down resistor])
- Diode (1pc | 1N4148 Diode for motor protection)
- UHF RFID Tags (3+pcs | DogBone for max range, 3 given with J4220u Package)
- DC Motor (1pc | Can Use Both DC or AC motor)
- External Power Supply (Recommended for the Motor/Gate [Can Use both DC or AC power Supply])
- Hook-up Wires (As needed | Jumper wires [male-to-female, female to female and male-to-male])
- Breadboard (Optional) (1pc | For prototyping)
- Mounting Enclosure(Optional) (1 | Weatherproof is recommended for outdoor installation)
All necessary component's that was used in this project is given above with their links from where they can be bought.
Step 1: Prepare the ESP32, Reader Hardware and Other Components
Step: Prepare the ESP32 and Reader Hardware
The JENCE J4220UX communicates via a standard UART (Universal Asynchronous Receiver/Transmitter) connection, to send the complex tag data. Meanwhile, the Relay Module uses a simple GPIO (General Purpose Input/Output) pin for an on/off command. Since the ESP32 has multiple UART ports, we'll dedicate one (UART2) to the RFID reader.
1. Power Setup:
- System Power: In this build, the ESP32 is powered via its USB port. Both the JENCE J4220UX Reader and the Relay Module’s VCC receive their 5V power directly from the ESP32’s 5V pin. This keeps the logic side of the project simple and compact.
- Pro Tip: While the ESP32 can power the reader, you can connect a dedicated external 5V power source to the JENCE reader’s 5V pin if you want to maximize its scanning efficiency and range.
- External Power (The Muscle): An External Power Supply is used strictly for the motor circuit after the relay. The relay acts as a bridge, keeping the high-voltage motor power completely separate from the ESP32.
2. UART Communication: Connect the J4220U's UART pins to the ESP32:
- J4220U TXD → ESP32 RXD2 (GPIO 16)
- J4220U RXD → ESP32 TXD2 (GPIO 17)
- J4220U GND → ESP32 GND
- J4220U VEXT → ESP32 3V3 (Logic High voltage)
- J4220U 5V → ESP32 5V
3. Relay & MOSFET Driver Connection: To trigger the gate, we use GPIO 5 to drive a MOSFET, which in turn activates the relay. This protects your ESP32 from the relay's current draw.
- Trigger Path: ESP32 GPIO 5 → MOSFET Gate.
- Pull-down: Connect a 10kΩ Resistor between the MOSFET Gate and ESP32 GND to prevent accidental triggers.
- Relay "IN":MOSFET Drain → Relay Module IN pin.
- Grounding:MOSFET Source and the Relay GND → ESP32 GND.
- Relay Power:Relay VCC → ESP32 5V.
This setup uses the MOSFET as a high-speed switch to trigger the relay without putting strain on the ESP32's pins.
4. Gate Motor Wiring (The Output): The relay acts as a switch for your gate motor.
- DC Motor Setup: Connect the External Power Supply Positive (+) to the DC Motor. Connect the Negative (-) to the Relay's Normally Closed (NC) port.
- Completion: Connect the Relay Common (COM) port to the other end of the DC motor.
- Protection: Place a Diode in parallel with the motor (Cathode to positive) to suppress voltage spikes (back-EMF) when the motor stops.
Step 2: Circuit Completion
Wire Labeling:
1. The Power Tier (Red & Black)
- Red Wire: Connects ESP32 5V to the J4220U 5V and Relay VCC.
- Black Wire: Connects ESP32 GND to J4220U GND, Relay GND, and MOSFET Source.
- Purple Wire (Optional): Used purple color for the VEXT (3.3V) line to distinguish logic voltage from supply voltage.
2. The Communication Tier (UART)
- Blue Wire: "UART_TX" : From J4220U TXD to ESP32 RX2(GPIO16).
- Green Wire: "UART_RX": From J4220U RXD to ESP32 TX2(GPIO17).
- Note: Remember that TX always goes to RX on the other side!
3. The Control Tier (Trigger)
- Orange Wire: "GATE_TRIGGER": From ESP32 GPIO 5 to the MOSFET Gate.
- Orange Wire: "RELAY_IN": From MOSFET Drain to the Relay Module "IN" pin.
4. The Motor Tier (Isolated Power)
- Red Wire: "MOTOR_VCC": From the External Power Supply to the Motor.
- Black Wire: "MOTOR_RETURN": From the Motor to the Relay COM/NC port.
- Note: Remember to use a Diode to protect the Motor from Power Surge!
Note on Gate Wiring: The Relay Module acts as a simple switch. It should be wired to the gate control circuit's trigger inputs (the same inputs used by an intercom button or remote control receiver). Always check your gate system's manual before wiring the relay to avoid damage. Use the Relay's Normally Open (NO) and Common (COM) terminals. Both DC or AC Components can be added after the relay.
Note on Versatility: Because the relay isolates the circuits, you can use this same logic for DC or AC motors. While this setup uses a 1-channel relay for one-way movement, upgrading to a 2-channel relay allows for bi-directional control (opening and closing).
The Schematic Zip file an be downloaded using the link : Schematic
Use KiCad to view the Schematic
USB Serial for Debugging [Optional]: The ESP32 uses its primary USB-Serial connection for communication with your PC (the Arduino IDE's Serial Monitor). This is crucial for debugging. It allows you to see messages, such as “Authorized Tag Detected” confirmation when a tag is read or when the gate signal is triggered. To use this while also communicating with the JENCE J4220U reader, your MCU must utilize two separate UART ports: one for the PC/debugging and one for the JENCE J4220U reader. This dual setup is recommended for easy development.
Step 3: Configure and Test the RFID Tags
Step: Configure and Test the RFID Tags
Before setting up the gate logic, you need to know the unique EPC (Electronic Product Code) of the tags you want to authorize.
- Software Download: Download the open-source SDK and Demo App from the JENCE GitHub repository: GitHub - jence/j4210u-app
- Initial Scan: Connect the J4220U directly to your PC (Windows, Mac, or Linux) using the provided USB cable.
- Run the Demo: Use provided demo application. J4210u-app-3.0.0platform”your OS”/j4210u.exe
- Identify Tags: Scan your RFID tags (stickers or inlays). The software will display a list of all detected tags and their unique EPC values (usually a long hexadecimal string).
- Authorization List: Copy the EPC values of the tags you want to authorize (your car's tag) into a text file. You can then hardcode these values into the ESP32 program.
Step 4: Program the ESP32 (Authorization Logic)
Step: Program the ESP32 (Authorization Logic)
The ESP32 firmware will perform three tasks: listen for the reader, check the tag against the "Allowed" list, and trigger the MOSFET/Relay. You may have a powerful test program, but for this step, we'll outline the core C++ logic using the Arduino framework for the ESP32, which utilizes the JENCE Arduino API.
- Include Libraries: You will need the appropriate JENCE Arduino API (C++) library for the reader.
- Define Constants: Set UART communication pins and GPIO Relay pin and baud(C++)
- Define Authorized Tags: Paste the EPC values copied in Step 2 into an array. (C++)
- The Logic: The program follows a specific loop to ensure secure and consistent access:Initialization: During setup(), the ESP32 initializes Serial2 (pins 16 & 17) and configures the reader settings (like scan time and the buzzer).
- Inventory Scan: In the loop(), the code triggers an uhf.Inventory() scan to see all tags currently in the 14-foot range.
- Comparison: The code converts the raw tag data into a Hex string and checks it against the authorizedEPCs list.
- Trigger: * Match Found: The ESP32 sets CONTROL_GPIO to LOW. This triggers the MOSFET and clicks the relay to open the gate. No Match: The pin remains HIGH, keeping the gate closed.
- Interval: The system waits 3 seconds between scans to prevent the relay from "chattering" or triggering too many times in a row.
- Upload Code: Use the Arduino IDE with the ESP32 board package installed. Ensure you have selected the correct COM port and "ESP32 Dev Module" as your board before clicking upload. You can download the full code here: continuous_scan.zip
Step 5: Final Installation and Testing
Step 4: Final Installation and Testing
- Mounting: Install the JENCE J4220U reader in a location that gives it a clear line of sight to the approaching vehicle's tag (vehicle tag is often mounted on the dashboard or windshield). A weatherproof enclosure for the reader is highly recommended.
- Powering Up: Plug the ESP32 into a USB power source. This powers the "Brains" (the reader and the relay trigger).
- Motor Power: Ensure your External Supply is connected to the motor via the relay contacts.
- Live Test: Drive toward the gate with an authorized tag. The reader should pick up the signal from several feet away (up to 14 feet depending on tag quality and environment), you should hear the relay "click" and see the motor spin as the reader detects the tag and the gate opens (in this case, the motor spins).
Next Level Upgrades
- Bi-Directional Gate Control (2-Channel Relay): As previously mentioned, our current setup uses a 1-channel relay to trigger a gate to open. By upgrading to a 2-channel relay module, you can control the motor in both directions. This allows the ESP32 to send one signal to "Open" the gate and a second signal to "Close" it, or even reverse the polarity of the motor to wind the gate back.
- Remote Management: Use the ESP32's built-in Wi-Fi and the JENCE J4220U reader's JSON messaging capabilities (as described in the SDK) to send tag data to a server. This lets you remotely add or delete authorized EPCs without reprogramming the ESP32.
- Vehicle Safety and Auto-Close Sensors: Enhance safety by adding two IR sensors across the gate opening. One sensor is placed near the entry point and the second near the exit point. This allows the system to know exactly when the car has fully passed through the gate, ensuring the gate only closes once the vehicle is completely clear of the closing path. This prevents accidents caused by premature closing.
- Logging: Use the ESP32 to log all successful and failed access attempts to an SD card or a remote cloud service for auditing.
Note to Readers:
I will be Updating this Project if it needs necessary revisions and add more links, images and video later.

