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...

Read more »