Introduction

In the world of automation and the Internet of Things (IoT), access control systems have become increasingly present, ensuring security and practicality in various environments. This article presents the development of an access control system using the ESP32, which acts as the main processing unit, receiving commands in JSON format sent by a Raspberry Pi.

Access this link and download all project files of the PCB project.

By combining the versatility of the ESP32 and the processing capacity of the Raspberry Pi, this project allows for the efficient management of the activation of two relays, responsible for controlling devices such as doors, turnstiles, or other access mechanisms. In addition, we highlight the simplicity and robustness of communication between devices, exploring concepts of integration and data processing.

Throughout the article, the main steps to implement this solution will be covered, including the configuration of the devices, the communication protocol used, and details on the processing of data received via USB. This project is a practical demonstration of how to combine different technologies to create intelligent and customized solutions for access control.

Electronic Circuit Design

The electronic circuit project is divided into 4 important blocks: the power supply circuit, the control circuit with the ESP32 Microcontroller, the relay drive circuit and the USB communication circuit for exchanging data between the ESP32 and the Raspberry PI/Orange Pi.

Below we'll present the the 3 sheets of the electronic circuits developed.

Power Supply Circuit and ESP32 Microcontroller

Firstly, we have the circuit of power supply and ESP32 microcontroller circuit.The power supply circuit was created to be powered with 9V. From this value, the voltage is regulated to a value of +5V through an AMS1117-5V.

However, we know that we have a relay drive circuit and, often, they generate interference in the operation of the ESP32 CHIP. To avoid this problem, we use the isolated DC-DC converter B0505S.

Its purpose is to convert a 5V input voltage into another 5V output voltage, in such a way that we will create a voltage source isolated from the other. Because they are isolated, we can have a dedicated power supply to power the ESP32 and this will increase the immunity of our circuit against noise coming from the input voltage source.

Below the power supply circuit, we have the ESP32 Microcontroller circuit. It consists of the ESP32, its buttons to put it in programming mode and the programming pins for transferring code through an external USB-Serial converter.

How the Relay Drive Circuit Works

The relay drive circuit uses a PC817 optocoupler IC to ensure electrical isolation between the ESP32 and the high-power components. The ESP32 sends a digital signal to the circuit, which is received by the optocoupler's internal LED. When the LED is energized, it activates the PC817's internal phototransistor, allowing current to flow through the transistor and thus activating the next stage of the circuit.

Access this link and download all project files of the PCB project.

The signal from the phototransistor is used to control the base of a bipolar junction transistor (BJT) or a MOSFET, depending on the design. This transistor, when activated, allows current to pass through the relay, activating it. The relay, in turn, acts as an electromechanical switch, and can control the activation or deactivation of external loads, such as motors, lamps or other devices.

This circuit is designed to ensure that the ESP32 operates safely, isolated from possible interference or voltage spikes from the load controlled by the relays. The use of the PC817 not only protects the microcontroller, but also increases the reliability of the system in practical applications.

Finally, we have the USB communication circuit.

USB Communication Circuit between Raspberry Pi and ESP32

The circuit responsible for USB communication in the project aims to establish a reliable interface between the Raspberry Pi and the ESP32. To do this, we use a female USB connector, which receives the USB cable connection coming from the Raspberry Pi.

Access this link and download all project files of the PCB project.

TVS (Transient Voltage Suppressor) protection diodes were implemented at the USB connector input. These components have the function of protecting the circuit against voltage surges or unwanted spikes that may arise in the data line, ensuring greater safety and longevity for the system.

The data transmitted by the Raspberry Pi is sent to the FT232RL integrated circuit, a USB to UART converter. This component converts the received USB signals to a format understandable by the ESP32, allowing it to process the information. The same path is used for the ESP32 to send data back to the Raspberry Pi, or any other compatible device, through the USB interface.

In addition, the circuit includes indicator LEDs for the TX (transmission) and RX (reception) lines. These LEDs provide visual feedback on communication, flashing when data is being sent or received, making it easier to diagnose potential problems and monitor in real time.

This USB integration with the FT232RL enables efficient communication, allowing the ESP32 to process external data and send responses, expanding the system's application possibilities in IoT and access control projects.

Conclusion

This project demonstrated how a well-designed circuit board is essential for integrating and managing the various functions of an access control system. From processing data received via JSON from the Raspberry Pi to efficiently driving relays and reliable USB communication, each component of the circuit plays a key role in ensuring the security and performance of the system.

The use of components such as the PC817 optocoupler and the FT232RL USB to UART converter not only ensures the protection and efficiency of the circuit, but also makes the project scalable and robust for practical applications. This board is not just an intermediary between devices, but the heart of the system, uniting hardware and software to deliver a complete and functional solution.

Are you ready to turn your project into reality? Order 5 PCBWay quality electronic boards now! Sign up on the website and take the next step in developing your access control system. Manufacturing quality will make all the difference in the success of your project!