hi, I asked to do DC motor control dirctional and speed by using L293D IC, I wrote the code and directional control is done but I have a problem in speed control using PWM it doesn't read the value of potentiometer .please help me
[quote ]
int mf=13; //motor forward pin
int mr=12; //motor reverse pin
int bf=7; //button for forward move
int br=6; //button for reverse move
int en=9; //to enable pin of L239D
int speedo=0;//the value of analogeread
int an=A0; //pin use to read potentiometer
void setup() {
// put your setup code here, to run once:
pinMode(mf,OUTPUT);
pinMode(mr,OUTPUT);
pinMode(bf,INPUT);
pinMode(br,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(bf)==HIGH && digitalRead(br)==LOW){
digitalWrite(mf,HIGH);
digitalWrite(mr,LOW);
}
else if(digitalRead(br)==HIGH && digitalRead(bf)==LOW){
digitalWrite(mf,LOW);
digitalWrite(mr,HIGH);
}
else{
digitalWrite(mf,LOW);
digitalWrite(mr,LOW);
}
speedo=analogRead(an);
analogWrite(en,speedo/4);
delay(50);
}
[/quote]
[quote ]
int mf=13; //motor forward pin
int mr=12; //motor reverse pin
int bf=7; //button for forward move
int br=6; //button for reverse move
int en=9; //to enable pin of L239D
int speedo=0;//the value of analogeread
int an=A0; //pin use to read potentiometer
void setup() {
// put your setup code here, to run once:
pinMode(mf,OUTPUT);
pinMode(mr,OUTPUT);
pinMode(bf,INPUT);
pinMode(br,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(bf)==HIGH && digitalRead(br)==LOW){
digitalWrite(mf,HIGH);
digitalWrite(mr,LOW);
}
else if(digitalRead(br)==HIGH && digitalRead(bf)==LOW){
digitalWrite(mf,LOW);
digitalWrite(mr,HIGH);
}
else{
digitalWrite(mf,LOW);
digitalWrite(mr,LOW);
}
speedo=analogRead(an);
analogWrite(en,speedo/4);
delay(50);
}
[/quote]
Attachments
-
26.7 KB Views: 0
-
549 bytes Views: 0