
We recommend soldering a 0.1uF ceramic capacitor to the positive and negative terminals of the DC motor, as shown in the diagram to help smooth out any voltage spikes. This way you don’t need to constantly connect and then disconnect the wires to save power.
#SERVO MOTOR ARDUINO TURNING A WHEEL DRIVER#
The switch between the battery holder and the motor driver is optional, but it is very handy to cut and apply power. In this configuration, you can use a power supply with 6V to 12V. As an example, we’re using 4AA batteries, but you can use any other suitable power supply. The DC motor requires a big jump in current to move, so the motors should be powered using an external power source from the ESP32. Follow the next schematic diagram to wire the DC motor and the L298N motor driver to the ESP32. The motor we’ll control is connected to the motor A output pins, so we need to wire the ENABLEA, INPUT1 and INPUT2 pins of the motor driver to the ESP32.

#SERVO MOTOR ARDUINO TURNING A WHEEL HOW TO#
Now that you know how to control a DC motor with the L298N motor driver, let’s build a simple example to control the speed and direction of one DC motor. Recommended reading: Build Robot Car Chassis Kit for ESP32, ESP8266, Arduino, etc… Control DC Motor with ESP32 – Speed and Direction The following table shows the input pins’ state combinations for the robot directions. For example, to make the robot turn right, enable the motor at the left, and disable the motor at the right. To turn the robot in one direction, you need to spin the opposite motor faster. To make it go backwards, both should be rotating backwards. If you want to build a robot car using 2 DC motors, these should be rotating in specific directions to make the robot go left, right, forward or backwards.įor example, if you want your robot to move forward, both motors should be rotating forward.

Motor B can be controlled using the same method but applying HIGH or LOW to input 3 and input 4.Ĭontrolling 2 DC Motors – ideal to build a robot If you apply power the other way around: HIGH to input 1 and LOW to input 2, the motor will rotate backwards.If you apply LOW to input1 and HIGH to input 2, the motor will spin forward.Input 1 and input 2 control motor A, and input 3 and 4 control motor B.

The input pins control the direction the motors are spinning. Motor enabled: speed proportional to duty cycle However, note that for small duty cycles, the motors might not spin, and make a continuous buzz sound. The motor speed is proportional to the duty cycle.

It’s important to note that despite the +12V terminal name, with the setup we’ll use here (with the jumper in place) you can supply any voltage between 6V and 12V. Note: if you supply more than 12V, you need to remove the jumper and supply 5V to the +5V terminal. However, if the jumper is in place, the chip is powered using the motor’s power supply and you don’t need to supply 5V through the +5V terminal. The +5V terminal is used to power up the L298N chip. The +12V terminal block is used to power up the motors. OUT1 and OUT2 at the left and OUT3 and OUT4 at the right.Īt the bottom you have a three terminal block with +12V, GND, and +5V. The motor driver has a two terminal block in each side for each motor.
