In this project learn how to control a motor using an Arduino. The Arduino will generate a PWM signal that will control the speed of the motor.
Before we get into the circuit it is important that we know what PWM is. PWM stands for pulse width modulation. To understand what that means I connected a PWM signal from the Arduino to my scope.
When I connected the signal to my scope I set the scope to measure the duty cycle. The duty cycle is the amount of time the signal is high this is measured in percent. Below are some signals I measured at different duty cycles.
At 20% duty cycle the signal was high 20% of the time and was low 80% of the time. This can be seen in the lower right hand value. As you can see the pulse is rather small.
I then increased the duty cycle to 50% on and 50% off. This can be seen as the amount of time that the signal is high and the signal is low is the same.
I then increased it to 80% duty cycle this is where the time the signal is spent high is 80% and low is 20%. this is shown on the scope ad the signal spends 80% of its time high.
Now that you understand what PWM does it can be implemented into a project. I chose to use a PWM signal from an Arduino to change the speed of a motor. Below is the schematic for my motor speed controller.
I have included the code I used it is a very simple piece of code that can easily be implemented in to different projects.
int Motor = 9; // Motor pin
int PotPin = 3; // potentiometer pin
int val = 0; // variable to store the read value
void setup() {
pinMode(Motor, OUTPUT);// sets the pin as an output
}
void loop() {
val = analogRead(PotPin); // read the input from the potentiometer
analogWrite(Motor, val / 4)
AcknowledgementI thank PCBWay & LCSC Electronics for the partnership.
PCBWay Is a cheap reliable service where you can get your PCBs manufactured. All the PCBs are high quality and the engineers are very helpful and will resolve any problems you may have quickly. Sign up today and get a $5 welcome bonus. Check Out PCBWay Hackster page.
LCSC Electronics Is China's leading Electronic Components Distributor. LCSC sells a wide variety of high quality electronic components at low prices. With over 150, 000 parts in stock they should have the components you need for your next project. Sign up today and get $8 off on your first order.
WebsiteCheck out more of my other projects on my website.
Comments
Please log in or sign up to comment.