PWM motor speed control using Arduino Schematic Circuit Diagram
Pulse Width Modulation (PWM) is a widely employed technique for regulating power delivery to devices such as motors and lights. In PWM, the power supplied to the load is managed by adjusting the duty cycle of the driving signal. An increased duty cycle results in higher power delivery to the load, while a reduced duty cycle leads to decreased power supplied. Speed control is achieved through a hex keypad, allowing for seven distinct speed settings. The circuit incorporates an Arduino UNO development board. The diagram depicting the PWM motor speed control circuit utilizing Arduino is illustrated below.
Circuit diagram
Row pins R1 and R2 of the hex keypad are interfaced to digital pins 6 and 7 of the arduino. Column pins C1, C2, C3 and C4 are interfaced to the digital pind 10, 11, 12 and 13 of the arduino. The key pressed on the hex keypad is identified using the column scanning method and it is explained in detail in this article. Interfacing hex keypad to arduino. The digital pins of the arduino can source or sink only up to 4omA of current. So the digital pin 3 cannot drive the motor directly.
To address this issue, we’ve employed an NPN transistor (2N2222) to regulate the motor based on the PWM signal present at digital pin 3. A 100-ohm resistor, R1, is utilized to restrict the base current of the transistor. The motor is linked as a collector load to the transistor. To filter out voltage spikes and noise generated during motor switching, a 0.1uF capacitor, C1, is connected across the motor.
The Arduino board is powered via the external power jack included on the board. Alternatively, the Arduino board can be powered through USB from a PC, but an additional external power source is required to drive the motor. The complete program for PWM motor speed control using Arduino is provided below. A detailed explanation of the program is provided in the “About the Program” section.
Program
int pwm=3; // declares digital pin 3 as PWM output int r1=6; int r2=7; int c1=10; int c2=11; int c3=12; int c4=13; int colm1; int colm2; int colm3; int colm4; void setup() { pinMode(r1,OUTPUT); pinMode(r2,OUTPUT); pinMode(c1,INPUT); pinMode(c2,INPUT); pinMode(c3,INPUT); pinMode(c4,INPUT); pinMode(pwm,OUTPUT); digitalWrite(c1,HIGH); digitalWrite(c2,HIGH); digitalWrite(c3,HIGH); digitalWrite(c4,HIGH); digitalWrite(pwm,LOW); } void loop() { digitalWrite(r1,LOW); digitalWrite(r2,HIGH); colm1=digitalRead(c1); colm2=digitalRead(c2); colm3=digitalRead(c3); colm4=digitalRead(c4); if(colm1==LOW) //checks whether key "1" is pressed. { analogWrite(pwm,42); // writes "42" (duty cycle 16%). delay(200);} else { if(colm2==LOW) //checks whether key "2" is pressed. { analogWrite(pwm,84); // writes "84" (duty cycle 32%). delay(200);} else { if(colm3==LOW) //checks whether key "3" is pressed {analogWrite(pwm,126); // writes "126" (duty cycle 48%). delay(200);} else { if(colm4==LOW) // checks whether key"A" is pressed. {digitalWrite(pwm,LOW); // makes pin 3 LOW (duty cycle 0%).Motor OFF. delay(200);} }}} digitalWrite(r1,HIGH); digitalWrite(r2,LOW); colm1=digitalRead(c1); colm2=digitalRead(c2); colm3=digitalRead(c3); colm4=digitalRead(c4); if(colm1==LOW) // checks whether key "4" is pressed. {analogWrite(pwm,168); //writes "168" (duty cycle 64%). delay(200);} else { if(colm2==LOW) // checks whether key "5" is pressed. {analogWrite(pwm,202); // writes "202" (duty cycle 80%). delay(200);} else { if(colm3==LOW) // checks whether key "6" is pressed. {analogWrite(pwm,244); // writes "244" (duty cycle 96%). delay(200);} else { if(colm4==LOW) // checks whether key "B" is pressed. {digitalWrite(pwm,HIGH);//makes pin 3 HIGH (duty cycle 100%). FULL POWER delay(200); } }}}}
About the program.
The PWM control signal’s duty cycle can be adjusted by modifying the value assigned to output pin 3 through the use of the analogWrite() function. The permissible value range for writing is between 0 and 255. You can apply the analogWrite() function to pins 3, 5, 6, 9, 10, and 11 on the Arduino UNO board. On most Arduino boards, the PWM signal’s frequency is typically around 490Hz. The duty cycle of the PWM signal is directly proportional to the value specified in the analogWrite() function. Here are a few examples illustrating the use of the analogWrite() function:
- analogWrite(pwm,255) will generate a pwm wave of 100% duty cycle (full power) at the pin denoted by the variable “pwm”.
- analogWrite(pwm,128) will generate a pwm wave of 50% duty cycle (half power) at the pin denote by the variable “pwm”.
- analogWrite(pwm,0) will generate a pwm wave of 0% duty cycle (no power) at the pin denoted by the variable “pwm”.
In the program the digital pin 3 is configured as the PWM output pin. Keys 1 to 6 on the hex keypad are used for increasing the power in steps of “42” in terms of the value written using the analogWrite() function or 16% in terms of duty cycle. Key “A” on the hex keypad is used for switching the motor OFF and it is done using the command “digitalWrite(pwm,LOW);. Key “B” on the hex keypad is used for putting the motor at maximum speed an it is done using the command “digitalWrite(pwm,HIGH);.
Notes.
Instead of the motor, you can apply the same circuit to adjust the brightness of an LED string. However, it’s essential to ensure that the load current remains within the safe limits of the 2N2222 transistor, which is 800mA. Additionally, the external power supply must have sufficient power capacity to drive the LED string. Below is the circuit diagram for PWM brightness control of an LED using Arduino: