

In this circuit, for controlling the speed of DC motor, we use a 100K ohm potentiometer to change the duty cycle of the PWM signal. Now, in the below code, setting pin A0 as input and 12 (which is PWM pin) as output. int pwmPin = 12 int pot = A0 int c1 = 0 int c2 = 0 In the below code, we have initialized the variable c1 and c2 and assigned analog pin A0 for the potentiometer output and 12 th Pin for ‘pwm’.
#Arduino pwm with potentiometer code
The complete code for Arduino DC Motor Control using potentiometer is given at the end. You can learn more about PWM by going through various projects based on PWM.Ĭircuit diagram for Arduino DC Motor Speed Control using PWM is geven below: AC Fan Speed Control using Arduino and TRIAC.Temperature Controlled Fan using Arduino.

We have used PWM with Arduino in many of our Projects: In the third case the duty cycle is 20% and the average terminal voltage is 20% of the battery voltage. Say if the battery voltage is 5V and the duty cycle is 50% and so the average terminal voltage will be 2.5V. In the second case, the switch is closed for 5ms and opened for 5ms over a period of 10ms, so the average terminal voltage at the output will be 50% of the battery voltage. Now human eye cannot see that motor is on for 8ms and off for 2ms, so will look like DC Motor is rotating with 80% speed. Now the average terminal over across the over a period of 10ms = Turn ON time/ (Turn ON time + Turn OFF time), this is called duty cycle and is of 80% (8/ (8+2)), so the average output voltage will be 80% of the battery voltage. If the switch is closed for 8ms and opened for 2ms over a cycle of 10ms, then the Motor will be ON only in the 8ms time. Now if the switch in the figure is closed continuously over a period of time then the motor will continuously ON during that time. Where, T ON = HIGH time of the square wave We have explained PWM in detail in this article. Also check this circuit where PWM is used to control the brightness of LED: 1 Watt LED Dimmer. This concept is used in the project to control the voltage using PWM. To understand it more simply, if you are applying 5 volt for driving a motor then motor will moving with some speed, now if we reduces applied voltage by 2 means we apply 3 volt to motor then motor speed also decreases. What is PWM? PWM is a technique by using we can control the voltage or power. Here in this Arduino Motor Speed Control project, the speed can be controlled by rotating the knob of potentiometer. For controlling the speed of DC motor we have various methods, like the speed can be automatically controlled based on temperature but in this project PWM method will be used to control the speed of DC motor. DC motor is the most used motor in Robotics and electronics projects.
#Arduino pwm with potentiometer download
To simplify communication between Arduino IDE and LCD module, we need to download LiquidCrystal library to make use of a built program in Arduino. Place the L293IC in the center of the breadboard, with half of the pins on either side of the breadboard.

