This is an Android app for control car by Bluetooth with Arduino.
#include
char blueToothVal; //value sent .over via bluetooth
char lastValue; //stores last state of device (on/off)
#define trigPin 2
#define echoPin A2
int led = 3;
int ledone = 5;
int ledtwo = 7;
int ledthree =9;
int r = 4;
int rone = 6;
int rtwo = 8;
int rthree =10;
int buz = 12;
int sto = 13;
int LED = A0;
int LEDD= A1;
int pos = 0;
Servo myservo;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(ledone, OUTPUT);
pinMode(ledtwo, OUTPUT);
pinMode(ledthree, OUTPUT);
pinMode(r, OUTPUT);
pinMode(rone, OUTPUT);
pinMode(rtwo, OUTPUT);
pinMode(rthree, OUTPUT);
pinMode(buz, OUTPUT);
pinMode(sto, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(LEDD, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(11);
}
void loop()
{
if(Serial.available())
{//if there is data being recieved
blueToothVal=Serial.read(); //read it
}
if (blueToothVal=='n')
{//if value from bluetooth serial is n
digitalWrite(led,HIGH);
digitalWrite(ledone,HIGH);
digitalWrite(ledtwo,HIGH);
digitalWrite(ledthree,HIGH);
digitalWrite(r,LOW);
digitalWrite(rone,LOW);
digitalWrite(rtwo,LOW);
digitalWrite(rthree,LOW);
digitalWrite(LED,HIGH);
digitalWrite(LEDD,LOW);
if (lastValue!='n'){
Serial.println(F("LED is on")); //print LED is on
lastValue=blueToothVal;}
}
else if (blueToothVal=='f')
{//if value from bluetooth serial is n
digitalWrite(led,LOW);
digitalWrite(ledone,LOW);
digitalWrite(ledtwo,LOW);
digitalWrite(ledthree,LOW);
digitalWrite(r,HIGH);
digitalWrite(rone,HIGH);
digitalWrite(rtwo,HIGH);
digitalWrite(rthree,HIGH);
digitalWrite(LED,LOW);
digitalWrite(LEDD,HIGH);
digitalWrite(buz,HIGH);
delay(500);
digitalWrite(buz,LOW);
if (lastValue!='f')
Serial.println(F("LED is off")); //print LED is on
lastValue=blueToothVal;
}
if (blueToothVal=='a')
{//if value from bluetooth serial is n
digitalWrite(led,LOW);
digitalWrite(ledone,LOW);
digitalWrite(ledtwo,LOW);
digitalWrite(ledthree,LOW);
digitalWrite(r,HIGH);
digitalWrite(rone,HIGH);
digitalWrite(rtwo,HIGH);
digitalWrite(rthree,LOW);
digitalWrite(LED,HIGH);
digitalWrite(buz,HIGH);
delay(1000);
digitalWrite(buz,LOW);
digitalWrite(LED,LOW);
if (lastValue!='a'){
Serial.println(F("ledone is on")); //print LED is on
lastValue=blueToothVal;}
}
#include
char blueToothVal; //value sent .over via bluetooth
char lastValue; //stores last state of device (on/off)
#define trigPin 2
#define echoPin A2
int led = 3;
int ledone = 5;
int ledtwo = 7;
int ledthree =9;
int r = 4;
int rone = 6;
int rtwo = 8;
int rthree =10;
int buz = 12;
int sto = 13;
int LED = A0;
int LEDD= A1;
int pos = 0;
Servo myservo;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(ledone, OUTPUT);
pinMode(ledtwo, OUTPUT);
pinMode(ledthree, OUTPUT);
pinMode(r, OUTPUT);
pinMode(rone, OUTPUT);
pinMode(rtwo, OUTPUT);
pinMode(rthree, OUTPUT);
pinMode(buz, OUTPUT);
pinMode(sto, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(LEDD, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(11);
}
void loop()
{
if(Serial.available())
{//if there is data being recieved
blueToothVal=Serial.read(); //read it
}
if (blueToothVal=='n')
{//if value from bluetooth serial is n
digitalWrite(led,HIGH);
digitalWrite(ledone,HIGH);
digitalWrite(ledtwo,HIGH);
digitalWrite(ledthree,HIGH);
digitalWrite(r,LOW);
digitalWrite(rone,LOW);
digitalWrite(rtwo,LOW);
digitalWrite(rthree,LOW);
digitalWrite(LED,HIGH);
digitalWrite(LEDD,LOW);
if (lastValue!='n'){
Serial.println(F("LED is on")); //print LED is on
lastValue=blueToothVal;}
}
else if (blueToothVal=='f')
{//if value from bluetooth serial is n
digitalWrite(led,LOW);
digitalWrite(ledone,LOW);
digitalWrite(ledtwo,LOW);
digitalWrite(ledthree,LOW);
digitalWrite(r,HIGH);
digitalWrite(rone,HIGH);
digitalWrite(rtwo,HIGH);
digitalWrite(rthree,HIGH);
digitalWrite(LED,LOW);
digitalWrite(LEDD,HIGH);
digitalWrite(buz,HIGH);
delay(500);
digitalWrite(buz,LOW);
if (lastValue!='f')
Serial.println(F("LED is off")); //print LED is on
lastValue=blueToothVal;
}
if (blueToothVal=='a')
{//if value from bluetooth serial is n
digitalWrite(led,LOW);
digitalWrite(ledone,LOW);
digitalWrite(ledtwo,LOW);
digitalWrite(ledthree,LOW);
digitalWrite(r,HIGH);
digitalWrite(rone,HIGH);
digitalWrite(rtwo,HIGH);
digitalWrite(rthree,LOW);
digitalWrite(LED,HIGH);
digitalWrite(buz,HIGH);
delay(1000);
digitalWrite(buz,LOW);
digitalWrite(LED,LOW);
if (lastValue!='a'){
Serial.println(F("ledone is on")); //print LED is on
lastValue=blueToothVal;}
}
Show More