Post Top Ad

Monday, December 11, 2023

PWM DC Motor speed controller DIY, Simple 12V motor controller


 PWM DC Motor speed controller DIY, Simple 12V motor controller

Microcontrollers such as Arduinos are a great way to control your custom electronics projects. Unfortunately the digital pins have a max output of 40mA, and this is not enough to power most motors. This is where a motor controller shield can come in handy. But these are expensive to buy, and only let you control a few motors, especially if you are embedding them in a project.


The simplest kind of speed controller uses a Pulse Width Modulation signal to set the speed of the motor. This signal can be generated by any of the Pulse Width Modulation pins on an Arduino. So we need to use an external power source (such as a battery pack) and a transistor switching circuit. This is similar to the transistor circuit on a relay shield, but we made a few changes. I included an LED for a visual indication on the output.

Here are the materials and tools that you will need for this project.


Materials:

2x NPN Power Transistor (such as tip31a)

2x IN4001 Diode

2x 1KΩ Resistor

2x 100 Ω Resistor

2x LED in your choice of color

2x 2 x 1 Female Headers

1x 1 x 4 Female Header

1x Battery Connector

1x 30 Gauge Solid-core Wire

1x Perfboard


There are two of almost everything because we are making two motor speed controllers on one PCB. You can easily make only one circuit by cutting the double materials in half and using the schematic.

Tools:

Soldering Iron and Solder

Wire Cutters

Wire Strippers

Needle Nose Pliers

Start off by soldering the two power transistors on the PCB. Leave space between the two to make room for the other components. Don't trim the leads yet. After we make the connections to the transistor then you can cut off the leads. Take note of the transistor pinout above to avoid making the wrong connections. To get a better understanding of the circuit and how it works, it might be a good idea to prototype the circuit on a breadboard first.


Solder on the small 1 x 2 female headers. Alternatively, you could use screw terminals (I ended up switching the two out a the end) for an easier connection. Again, leave space between the headers and transistors for other components.


Solder the diodes on to the prefboard, in front of the small headers. Connect the diodes to the headers as shown in the 3rd picture above. This will prevent the motor from delivering high current to the board and ruining it. Trim the leads on all diodes. Ideally you should have the silver strip facing the top of the board, to make wiring the board easier.


Solder on the LEDs in the back of the small headers. Any color you choose should work. You do not need to trim the leads or do any wiring yet. Keep in mind where you placed the anode and cathode for each.


Solder the 1K resistors to the base (pin 1) of each transistor. Leave room in between the resistors, and do not connect it to anything. Cut the base lead and the resistor lead connected to it.


Solder the 100Ω resistor on the perfboard, with one of the leads connected to the LED's anode (longer lead). Trim the one resistor lead and anode lead.


Connect the lead from one of the LED resistors to one of the transistor resistors. Trim off the lead from the LED resistor only. Repeat with the other 2 resistors to make 2 resistor pairs.


*Remember*** which resistor is connected to which! These pairs will always be separate; we are making 2 motor controllers!

Solder on the Power Supply wires. You can connect this to the power source of your choice (keeping in mind the motor and microcontroller volts and current). I connected a 9V battery clip so it can connect to a 9V or 12V source. Tie a knot near the base to prevent it from being pulled out.

Solder the large female header on the board, in the upper hand left corner. Connect the positive wire from the power supply to the farthest pin on the left (looking at it with the header in the upper left hand corner). Connect the negative Power Supply Wire to the pin next to the positive pin you just soldered. I used red wire for positive connections and blue for ground connections.


*Note*** This can be used to power a microcontroller or other accessory, and you can also use it as a power input if you wish not to use the attached Power Supply wires!

Connect the resistor connected to the Base (pin 1) of the Transistor to 1 of the available pins on the large header. Do this for the remaining resistor, connecting it to the last available pin. This large header will serve for inputs/outputs. Connect a PWM pin to the PWM input pins you just soldered, and use the power supply pins as an output or input for power. I used white wire for these connections


Connect the two Emitters of the Transistors (pin 3) to ground. Connect the two cathode leads of the LEDs to ground. Trim the Emitter leads and LED leads. I used blue wire for ground.


Connect the positive wire to the solder joint closest to the silver strip on the diode. Look at the pictures for reference, as this part can get tricky. Do this for both setss of headers.

This is where remembering the pairs of resistors you made comes in handy. Choose a Motor connection header pin and figure out what transistor the LED near said header pin is connected to. Once you have done that, connect a wire from the remaining solder joint on said header pin and connect it to the collector (pin 2) of the transistor, that you just determined the LED is connected to. Trim the lead on the transistor, and repeat this for the other header and transistor. Use the pictures for reference.


Now you have a simple motor controller shield. You can set the speed of the motor by sending an analog write command to the base of the transistor. Download and then upload the sample Arduino code given below to an Arduino board of your choice to test the motor controller. Try playing with the numbers and code to get comfortable using the speed controller.


To use this with other microcontrollers, make sure it has a PWM output, and set the output to match the required speed. If you do not know how to do this, find a sample code for controlling an LED, and change the code to serve your needs. Basically, you can somewhat think of this as controlling an LED; It takes the PWM signal and controls the motor with a higher voltage and current.


 PWM DC Motor speed controller DIY, Simple 12V motor controller

Microcontrollers such as Arduinos are a great way to control your custom electronics projects. Unfortunately the digital pins have a max output of 40mA, and this is not enough to power most motors. This is where a motor controller shield can come in handy. But these are expensive to buy, and only let you control a few motors, especially if you are embedding them in a project.


The simplest kind of speed controller uses a Pulse Width Modulation signal to set the speed of the motor. This signal can be generated by any of the Pulse Width Modulation pins on an Arduino. So we need to use an external power source (such as a battery pack) and a transistor switching circuit. This is similar to the transistor circuit on a relay shield, but we made a few changes. I included an LED for a visual indication on the output.

Here are the materials and tools that you will need for this project.


Materials:

2x NPN Power Transistor (such as tip31a)

2x IN4001 Diode

2x 1KΩ Resistor

2x 100 Ω Resistor

2x LED in your choice of color

2x 2 x 1 Female Headers

1x 1 x 4 Female Header

1x Battery Connector

1x 30 Gauge Solid-core Wire

1x Perfboard


There are two of almost everything because we are making two motor speed controllers on one PCB. You can easily make only one circuit by cutting the double materials in half and using the schematic.

Tools:

Soldering Iron and Solder

Wire Cutters

Wire Strippers

Needle Nose Pliers

Start off by soldering the two power transistors on the PCB. Leave space between the two to make room for the other components. Don't trim the leads yet. After we make the connections to the transistor then you can cut off the leads. Take note of the transistor pinout above to avoid making the wrong connections. To get a better understanding of the circuit and how it works, it might be a good idea to prototype the circuit on a breadboard first.


Solder on the small 1 x 2 female headers. Alternatively, you could use screw terminals (I ended up switching the two out a the end) for an easier connection. Again, leave space between the headers and transistors for other components.


Solder the diodes on to the prefboard, in front of the small headers. Connect the diodes to the headers as shown in the 3rd picture above. This will prevent the motor from delivering high current to the board and ruining it. Trim the leads on all diodes. Ideally you should have the silver strip facing the top of the board, to make wiring the board easier.


Solder on the LEDs in the back of the small headers. Any color you choose should work. You do not need to trim the leads or do any wiring yet. Keep in mind where you placed the anode and cathode for each.


Solder the 1K resistors to the base (pin 1) of each transistor. Leave room in between the resistors, and do not connect it to anything. Cut the base lead and the resistor lead connected to it.


Solder the 100Ω resistor on the perfboard, with one of the leads connected to the LED's anode (longer lead). Trim the one resistor lead and anode lead.


Connect the lead from one of the LED resistors to one of the transistor resistors. Trim off the lead from the LED resistor only. Repeat with the other 2 resistors to make 2 resistor pairs.


*Remember*** which resistor is connected to which! These pairs will always be separate; we are making 2 motor controllers!

Solder on the Power Supply wires. You can connect this to the power source of your choice (keeping in mind the motor and microcontroller volts and current). I connected a 9V battery clip so it can connect to a 9V or 12V source. Tie a knot near the base to prevent it from being pulled out.

Solder the large female header on the board, in the upper hand left corner. Connect the positive wire from the power supply to the farthest pin on the left (looking at it with the header in the upper left hand corner). Connect the negative Power Supply Wire to the pin next to the positive pin you just soldered. I used red wire for positive connections and blue for ground connections.


*Note*** This can be used to power a microcontroller or other accessory, and you can also use it as a power input if you wish not to use the attached Power Supply wires!

Connect the resistor connected to the Base (pin 1) of the Transistor to 1 of the available pins on the large header. Do this for the remaining resistor, connecting it to the last available pin. This large header will serve for inputs/outputs. Connect a PWM pin to the PWM input pins you just soldered, and use the power supply pins as an output or input for power. I used white wire for these connections


Connect the two Emitters of the Transistors (pin 3) to ground. Connect the two cathode leads of the LEDs to ground. Trim the Emitter leads and LED leads. I used blue wire for ground.


Connect the positive wire to the solder joint closest to the silver strip on the diode. Look at the pictures for reference, as this part can get tricky. Do this for both setss of headers.

This is where remembering the pairs of resistors you made comes in handy. Choose a Motor connection header pin and figure out what transistor the LED near said header pin is connected to. Once you have done that, connect a wire from the remaining solder joint on said header pin and connect it to the collector (pin 2) of the transistor, that you just determined the LED is connected to. Trim the lead on the transistor, and repeat this for the other header and transistor. Use the pictures for reference.


Now you have a simple motor controller shield. You can set the speed of the motor by sending an analog write command to the base of the transistor. Download and then upload the sample Arduino code given below to an Arduino board of your choice to test the motor controller. Try playing with the numbers and code to get comfortable using the speed controller.


To use this with other microcontrollers, make sure it has a PWM output, and set the output to match the required speed. If you do not know how to do this, find a sample code for controlling an LED, and change the code to serve your needs. Basically, you can somewhat think of this as controlling an LED; It takes the PWM signal and controls the motor with a higher voltage and current.

No comments:

Post a Comment

Post Top Ad

Pages