Brushed DC Motors are often used to drive robots around, or for variety of other cool Arduino projects. To control the motor with Arduino, you usually need to use a motor driver. There are a lot of different motor drivers available. One of the most popular and affordable ones for very small motors are the L9110S Motor Drivers. When the sketch starts, it prompts you, to remind you that to control the speed of the motor you need to enter a value between 0 and 255 in the Serial Monitor. The example code will control both kinds of motors. See the unipolar and bipolar motor schematics for information on how to wire up your motor. In this example, a potentiometer (or other sensor) on analog input 0 is used to control the rotational speed of a stepper motor using the Arduino Stepper Library.
The DC motor in your Arduino kit is the most basic of electric motors and is used in all types of hobby electronics. When current is passed through, it spins continuously in one direction until the current stops. Unless specifically marked with a + or -, DC motors have no polarity, meaning that you can swap the two wires over to reverse the direction of the motor.
The Motor sketch
You will need a simple control circuit to turn your motor on and off.
You need:
To power the motor, you need to send 5V through it and then on to ground. This voltage spins the motor, but you have control of it. To give your Arduino control of the motorâs power, and therefore its rotation, you place a transistor just after the motor.
The transistor is an electrically operated switch that can be activated by your Arduinoâs digital pins. In this example it is controlled by pin 9 on your Arduino, in the same way as an LED except that the transistor allows you the turn the motor circuit on and off.
This circuit works, but it still allows the chance of creating a reverse current because of the momentum of the motor as it slows down, or because the motor could be turned. If reverse current is generated, it travels from the negative side of the motor and tries to find the easiest route to ground.
This route may be through the transistor or through the Arduino. You canât know for sure what will happen, so you need to provide a way to control this excess current.
To be safe, you place a diode across the motor. The diode faces toward the source of the voltage, meaning that the voltage is forced through the motor, which is what you want. If current is generated in the opposite direction, it is now be blocked from flowing into the Arduino.
If you place the diode the wrong way, the current bypasses the motor and you create a short circuit. The short circuit tries to ground all the available current and could break your USB port or at the very least, show a warning message, informing you that your USB port is drawing too much power.
Build the circuit as shown, and open a new Arduino sketch. Choose the Save button and save the sketch with a memorable name, such as myMotor, and then type the following code:
After youâve typed the sketch, save it and press the Compile button to check your code. The Arduino Environment checks your code for any syntax errors (grammar for your code) and highlights them in the message area. The most common mistakes include typos, missing semicolons, and case sensitivity.
If the sketch compiles correctly, click Upload to upload the sketch to your board. You should see your motor spinning for one second and stopping for one second repeatedly.
If thatâs not what happens, you should double-check your wiring:
The Motor sketch breakdown
This is a very basic sketch, and you may notice that itâs a variation on the Blink sketch. This example changes the hardware but uses the same code to control an LED.
First, the pin is declared using digital pin 9.
In setup, pin 9 is defined as an output.
The loop tells the output signal to go to HIGH, wait for 1000mS (1 second), go to LOW, wait for another 1000mS, and then repeat. This scenario gives you the most basic of motor control, telling the motor when to go on and off.
Hello friends! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about how can you make a simple program for DC Motor Speed Control using Arduino UNO. In my previous tutorial, DC Motor Direction Control using Arduino, I have just controlled the DC motor in both directions at constant speed using Arduino. I have also performed the DC Motor Direction Control in Matlab by sending different commands through serial port from Matlab and LabVIEW to the Arduino and then controlled the direction of rotation of DC motor. But in this tutorial I will rotate the same DC motor at variable speed in both clockwise and anti clockwise directions.
In my previous tutorial, we have seen that input pins In1 & In2 of motor control driver L298 (H-Bridge) are useful to control the direction of rotation of the DC motor. In this tutorial, I have controlled its speed as well by providing different voltage levels at the enable pin of the DC motor control driver L298. It will be helpful to vary the speed of the DC motor in either clockwise or in anti clockwise direction. So, letâs get started with DC Motor Speed Control using Arduino UNO:
DC Motor Speed Control using Arduino UNO
In this tutorial we will learn that how to make an algorithm for DC Motor Speed Control using Arduino UNO. Speed control of any motor is always done y Pulse Width Modulation, abbreviated as PWM. PWM pulse can be generated using Arduino and L298 Enable Pin is used to get that PWM pulse and then it controls the motor speed accordingly. Before going into the further details I would like to tell you about the concept of PWM for controlling DC motor. Moreover, you can download the complete Arduino code for DC Motor Speed Control using Arduino by clicking the below button:
Arduino Motor Driver CodeArduino Source CodePulse Width Modulation (PWM)
PWM stands for Pulse Width Modulation. It basically describes the type of the digital signal. PWM technique is an excellent technique to control the analog circuits with microcontrollerâs digital PWM output. In this technique we can get analog results with the digital means. Digital control is used to create square wave. This pattern can vary voltages between full on i.e. 5V and full off i.e. 0V. The duration of on time i.e. when the the signal is present is known as pulse width. PWM waves for the different duty cycles are shown in the figure below.
Duty cycle is basically the proportion of the time during which a system is operated. It can be expressed as a percentage. For example motor rotates for 1 second out of 100 seconds, it duty cycle can be represented as 1/100 or as 1%. For Arduino software coding the command analogWrite(255) shows the maximum i.e. 100% duty cycle. To achieve 50% duty cycle we have to update this command to analogWrite(127). Arduino UNOâs pin no 3, 5, 6,10 and 11 are used as PWM pins. In this project we can control the speed of the DC motor by providing high and low voltages to the enable pin of the motor control driver L298. For example, if a motor rotates with the maximum speed and 100% duty cycle at 12V and we provide it with the 6V then it will rotate with the half of the initial speed having 50% duty cycle.
Motor Controller L298
The pins EnA and EnB of the motor controller L298 are used as the PWM pins. We can rotate the DC motor at different speed providing different high and low voltage levels to these pins of the motor control driver. If we start to reduce the maximum voltage at which the motor rotates at maximum speed, the speed of the motor also starts to reduce. In this way these enable pins are helpful to control the speed of the DC motor.
Algorithm design and descrition
In this section of the tutorial DC Motor Speed Control using Arduino UNO, I am going to explain you about designing as well as a detailed description of the designed algorithm. I will tell you about the entire algorithm in step by step procedure.
Note:Since you are working on the DC motor so you must also have a look at my previous tutorials, they will be helpful for you to simulate this project as well.
Open your Arduino software, copy and paste the source code given below in your software.
Actual Hardware Setup
Arduino Dc Motor Controller Driver Code 10
Arduino Dc Motor Controller Code
Thats all from the tutorial DC Motor Speed Control using Arduino UNO. I hope you have enjoyed this tutorial. If you face any sort of problem, you can ask me anytime without feeling any kind of hesitation. I will further explore my knowledge about Arduino projects in my later tutorials. Till then, Take care ?
JLCPCB â Prototype 10 PCBs for $2 (For Any Color) Chinaâs Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w Arduino Motor Controller ModuleSyed Zain Nasir3 CommentsMotor Driver ArduinoAuthor: Syed Zain Nasirhttps://www.theengineeringprojects.com/I am Syed Zain Nasir, the founder of The Engineering Projects (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. My Google Profile+Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |