Arduino controlled RC car making in tamil
Coding
void setup() {
pinMode(2,OUTPUT); //in1
pinMode(3,OUTPUT); //in2
pinMode(4,OUTPUT); //in3
pinMode(5,OUTPUT); //in4
Serial.begin(9600);
}
void loop() {
if(Serial.available()>0)
{
char cmt = Serial.read();
Serial.println(cmt);
if(cmt == '0') //forward
{
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
Serial.println("0");
}
else if(cmt == '1') //backward
{
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
Serial.println("1");
}
else if(cmt == '2') //right
{
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
Serial.println("2");
}
else if(cmt == '3')//left
{
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
Serial.println("3");
}
else if(cmt == '4') // stop
{
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
Serial.println("4");
}
}
}
Comments
Post a Comment