Introduction:
Speed control of motor using Potentiometer. Whenever we adjust knob of pot the speed will either increase or decrease. We have also used switch to make the motor revolve in clockwise or counter clockwise direction.
Components Used:
- Arduino Nano
- 10k potentiometer
- Switch
- L293D IC
- Motor
- Jumper Wires
- Breadboard
Circuit Diagram:
Code:
int enablePin = 11;
int in1Pin = 10;
int in2Pin = 9;
int switchPin = 7;
int potPin = 0;
int statusPin= 13;
void setup()
{
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
pinMode(statusPin,OUTPUT);
}
void loop()
{
digitalWrite(13,HIGH);
int speed = analogRead(potPin) / 4;
boolean reverse = digitalRead(switchPin);
setMotor(speed, reverse);
}
void setMotor(int speed, boolean reverse)
{
analogWrite(enablePin, speed);
digitalWrite(in1Pin, ! reverse);
digitalWrite(in2Pin, reverse);
}
No comments:
Post a Comment