This is a project for controlling Arduino for Android device and connected by Bluetooth. For creating this project I used app inventor for the Android application and Arduino IDE for the Arduino program.
int lstat = 0;
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void forward()
{
Serial.println("Forward");
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
}
void backward()
{
Serial.println("Backward");
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
}
void left()
{
Serial.println("Left");
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
}
void right()
{
Serial.println("Right");
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
}
void quit()
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
void loop()
{
if(Serial.available())
{
switch(Serial.read())
{
case 'w':
forward();
break;
case 's':
backward();
break;
case 'a':
left();
break;
case 'd':
right();
break;
case 'q':
quit();
break;
case 'o':
if(lstat == 0)
{
digitalWrite(7, HIGH);
lstat = 1;
}
else if(lstat == 1)
{
digitalWrite(7, LOW);
lstat = 0;
}
break;
}
}
}
Above is my Arduino Code.
1 project • 4 followers
I'm studying Computer Engineering at King Mongkut's Institute of Technology Ladkrabang, https://github.com/DreamN
Comments