+21622886281
DC Motor ESP32 L298N module

Control a motor by the ESP32 card and the L298N module

The ESP32 is a microcontroller developed by Espressif that is similar to the Arduino but with built-in WiFi and Bluetooth capabilities. It can be used to control DC motors just like the Arduino.

To control a DC motor with an ESP32, you will need to use a motor driver IC that can handle the voltage and current requirements of the motor. One popular motor driver IC that can be used with the ESP32 is the L298N. This IC is a dual H-bridge driver that can be used to control the speed and direction of two DC motors.

To use the L298N with the ESP32, you will need to connect the ESP32 to the motor driver IC using digital I/O pins. You will also need to connect power to the L298N (typically between 7V and 35V) to power the motor.

Purpose of this tutorial:

The L298N module is a development board allowing the control of a DC motor or a stepper motor.

In this tutorial we will see how to control a DC motor by the ESP32 card and the L298N module while changing the direction of rotation.

Necessary components:

ESP32 card

An ESP32 card is a development board or module that is based on the ESP32 microcontroller developed by Espressif. It typically includes the ESP32 chip, as well as a number of peripheral components, such as RAM, flash memory, power management, and input/output (I/O) pins. ESP32 cards can come in a variety of form factors, including the ESP32-DevKitC, ESP32-WROVER, ESP32-PICO-D4 and more.

ESP32 card can be programmed using various programming languages such as C, C++, Python and MicroPython. The ESP32 has a built-in support for the Arduino IDE which makes it easy to program and debug.

L298N module

The L298N is a popular dual H-bridge motor driver IC that can be used to control DC motors and stepper motors with an Arduino microcontroller. The L298N is a relatively simple IC that allows you to control the speed and direction of two DC motors, or control one stepper motor.

The L298N has two H-bridge circuits, each of which can be used to control the speed and direction of a DC motor. Each H-bridge has two input pins (IN1 and IN2) that are used to control the direction of the motor, and an enable pin (EN) that is used to control the speed of the motor. By applying a voltage to these pins, you can control the speed and direction of the motor.

The L298N also has a built-in 5V linear voltage regulator, which can be used to power the Arduino board and the motors. The power supply voltage for the L298N should be between 7V and 35V.

You can control the speed of the motor by adjusting the duty cycle of the PWM signal that is sent to the enable pin. The duty cycle is the percentage of time that the PWM signal is in the high state, compared to the period of the PWM signal. The greater the duty cycle, the faster the motor will rotate.

To control the stepper motor with the L298N module, you will need to connect the stepper motor to the module, and then send step and direction signals to the module. The L298N module has four inputs that can be used to control the stepper motor: IN1, IN2, IN3, and IN4. By applying the appropriate signal to these inputs, you can control the stepper motor.

You need to connect the IN1, IN2, IN3, IN4 pins to the digital pin of the Arduino. Also connect the Enable pin of the L298N to the PWM pin of the arduino so that you can control the speed of the motor.

DC motor

A 5V DC motor is a type of electric motor that operates on direct current (DC) voltage. It is a small motor that typically runs on 5V of power, although the voltage may vary slightly depending on the specific motor and the load it is driving. These motors are often used in small electronic devices, such as portable fans, toys, and robotic applications. They are generally very reliable, efficient, and simple to control, making them a popular choice for many different types of projects and applications.

Battery of 9V

A 9V battery is a type of primary cell, which means that it cannot be recharged and must be replaced once the energy stored inside is depleted. They are commonly used in small electronic devices such as smoke detectors, remote controls, and portable audio devices.

Assembly

  • Connect pin 18 of the ESP32 board to pin ENA of the L298N module

  • Connect pin 5 of the ESP32 board to pin IN1 of the L298N module

  • Connect pin 4 of the ESP32 board to pin IN2 of the L298N module

  • Connect the GND pin of the ESP32 board to the GND pin of the L298N module

  • Connect the GND pin of the ESP32 board to the (-) terminal of the 9V battery

  • Connect the 12V pin of L298N module to the (+) terminal of battery
  • Connect the two motor terminals to the two pins OUT1 and OUT2 of the L298N module

Micropython program

Here are the micropython programs that allow the motor to be turned in both directions by the L298N module.

boot.py

DCMotor.py




0 commentaire


Leave a comment

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Scroll to Top