ESP32 – Motor controller

While developing the ESP – HomeKit blinds, it became clear that stronger motors are needed. In this blog, we look at a DC motor controller in which the speed and direction of rotation must be able to be controlled.

motor

We are also looking at a controller for controlling a small electric motor via a PWM signal. To ensure that the direction of rotation can also be switched, whereby the polarity reversal can be additionally realized so that the direction of rotation can be determined. This resulted in two different circuits with associated software, which I will discuss below. We are also going to design a new controller, in which we determine a set of requirements in advance, more about that later.

A simple polarity reversal is this:

Motor

The relay we are using contains a double switch, as used in the example above. Here, T1 is connected to 1 or 2 and at the same time T2 to 3 or 4. In this way, the supply voltage applied is reversed to the motor when the relay is energized and that determines the direction of rotation of the motor.

DPDT Relay

DPDT stands for double pole double throw relay. A relay is an electromagnetic device used to separate two circuits electrically and connect them magnetically. They are often used to interface an electronic circuit, which works at a low voltage, to an electrical circuit which works at a high voltage. Relays are available in different configuration of operating voltages like 6V, 9V, 12V, 24V etc.

motor

Motor controller

So how do we accomplish this motor control with an ESP32. First, we have a look at the hardware.

Schematic

The schematic shows how this setup works.

Circuit

In this circuit overview, we used a breadboard to test our schematic in real life.

Motor

Alternative scheme with external power supply, for example 12V. As you can see, optocouplers have been added to create a galvic separation.

Code

To run the motor controller, we need a Code. We make our Code in Arduino IDE. It will accelerate from 0 to full speed and back to 0 the relay then reverses the direction of rotation of the motor and then starts the acceleration again.

motor

Reference
leonvanderhors, motor regelaar, http://www.leonvanderhorst.nl/workshop_SMG_motorregelaar.htm

Scroll to Top