Controlling the speed of a DC motor
In any smart home, chances are you will find a DC motor somewhere that you will need to automate. It could, for example, be on electric window blinds, or on an automated garage door. In this section, we are going to see how to control the speed of a simple DC motor and you will then be able to apply this to any motors you already have in your home.
Let's first see how to connect the DC motor to your Raspberry Pi Zero board. We actually won't connect the motor directly to the Raspberry Pi, as this would require a lot of external components, such as transistors, diodes, and so on. Instead, we'll use the L293D chip, which is a dedicated IC to control DC motors.
First, place the L293D on the board. The following diagram shows the pinout of the L293D:
You basically need to connect the components to the L293D as follows:
GPIO14 of the Raspberry Pi to pin 1A
GPIO15 of the Raspberry Pi to pin 2A
GPIO18 of the Raspberry Pi to pin 1,2EN
DC motor to pin 1Y and 2Y
5V of the...