SunFounder ESP32 Starter Kit
(continued from previous page)
for power in range(1023, 0, -20):
motor1A.duty(power)
motor2A.duty(0)
time.sleep(0.1)
# Rotate the motor in the opposite direction by gradually increasing the power on␣
˓→the motor2A pin
for power in range(0, 1023, 20):
motor1A.duty(0)
motor2A.duty(power)
time.sleep(0.1)
# Decreasing the power on the motor2A pin
for power in range(1023, 0, -20):
motor1A.duty(0)
motor2A.duty(power)
time.sleep(0.1)
Unlike the previous script, here the motor is controlled by PWM signals with a frequency of 1000 Hz, which determines
the speed of the motor.
• The code uses a while True loop to run continuously. Inside the loop, there are four for loops that control the
motors in a sequence.
• The first two for loops increase and decrease the speed of IN1 while keeping IN2 at 0 speed.
• The next two for loops increase and decrease the speed of IN2 while keeping IN1 at 0 speed.
• The range function in each for loop produces a string of numbers that serves as the duty cycle of the PWM
signal. This is then output to IN1 or IN2 via the duty method. The duty cycle determines the percentage of
time that the PWM signal is high, which in turn determines the average voltage applied to the motor, and thus
the motor speed.
• The time.sleep function is used to introduce a delay of 0.1 seconds between each step in the sequence, which
allows the motor to change speed gradually, rather than jumping from one speed to another instantaneously.
3.17 4.2 Pumping
In this intriguing project, we will delve into controlling a water pump using the L293D.
In the realm of water pump control, things are a bit simpler compared to controlling other motors. The beauty of this
project lies in its simplicity - there’s no need to worry about the direction of rotation. Our primary goal is to successfully
activate the water pump and keep it running.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
ESP32 Starter Kit 320+
You can also buy them separately from the links below.
3.17. 4.2 Pumping 349