DC motor controlled by Potentiometer using Arduino & L298N - Wired Connection
Circuit Diagram:
Required Components:
Arduino uno/nano - 1 Nos
Battery - 1 Nos
DC Motor - 1 Nos
L298N Motor Driver - 1 Nos
Potentiometer - 1 Nos
Program Code:
int Pot = A1;
int val;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(A1, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int val = analogRead(Pot);
if(val > 1 && val < 490){
val = map(val, 1, 490, 255, 0);
analogWrite(5,0);
analogWrite(6,val);
}
if(val > 530 && val < 1023){
val = map(val, 530, 1023, 0, 255);
analogWrite(6,0);
analogWrite(5,val);
}
if(val > 491 && val < 529){
val = map(val, 491, 529, 0, 0);
analogWrite(6,0);
analogWrite(5,0);
}
Serial.println(val);
}
Video:
Required Components:
Arduino uno/nano - 1 Nos
Battery - 1 Nos
DC Motor - 1 Nos
L298N Motor Driver - 1 Nos
Potentiometer - 1 Nos
Program Code:
int Pot = A1;
int val;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(A1, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int val = analogRead(Pot);
if(val > 1 && val < 490){
val = map(val, 1, 490, 255, 0);
analogWrite(5,0);
analogWrite(6,val);
}
if(val > 530 && val < 1023){
val = map(val, 530, 1023, 0, 255);
analogWrite(6,0);
analogWrite(5,val);
}
if(val > 491 && val < 529){
val = map(val, 491, 529, 0, 0);
analogWrite(6,0);
analogWrite(5,0);
}
Serial.println(val);
}
Video:
Comments
Post a Comment