DC motor controlled by push button using Arduino - wired Connection
Circuit Diagram:
Required Components:
Arduino Nano/uno - 1 Nos
DC Motor - 1 Nos
L293D Motor Driver - 1 Nos
Push Button - 1 Nos
10k Ohm Resister - 1 Nos
Battery - 1 Nos
Program Code:
int switch1 = 2;
int switch2 = 4;
int motorforward = 7;
int motorbackward = 6;
void setup() {
pinMode(switch1,INPUT);
pinMode(switch2,INPUT);
pinMode(motorforward,OUTPUT);
pinMode(motorbackward,OUTPUT);
// put your setup code here, to run once:
}
void loop() {
{
if(digitalRead(switch1)==HIGH){
digitalWrite(motorforward,HIGH);
digitalWrite(motorbackward,LOW);
}
else{
(digitalWrite(motorforward,LOW));
(digitalWrite(motorbackward,LOW));
}
}
{
if(digitalRead(switch2)==HIGH){
digitalWrite(motorbackward,HIGH);
digitalWrite(motorforward,LOW);
}
else{
(digitalWrite(motorbackward,LOW));
(digitalWrite(motorforward,LOW));
}
}
// put your main code here, to run repeatedly
}
Video:
Hello, I have an important question that I would if you appreciate you answer......
ReplyDeleteWhat do you mean by "// put your setup code here, to run once:"? Am I supposed to type that as it is? Am I supposed to type a specific code of my own? If yes, I'm a beginner and don't know what code to type.
Once again, I would really appreciate an answer.
Thank you for your time, and have a great day!