#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial BlueTooth(0,1);
Servo myservo;
int pos = 90;
char BT_input;
int motorPin1 = 4;
int motorPin2 = 5;
int motorPin3 = 6;
int motorPin4 = 7;
void setup()
{
BlueTooth.begin(9600);
Serial.begin(9600);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
myservo.attach(9);
}
void loop() {
if (BlueTooth.available())
{
BT_input=BlueTooth.read();
if (BT_input=='f')//forward
{
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
Serial.println("running");
}
else if (BT_input=='b')//backward
{
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
}
else if (BT_input=='r')//right
{
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}
else if (BT_input=='l')//left
{
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
}
else if (BT_input=='s')//stop
{
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}
else if (BT_input=='m')
{
for (pos = 90; pos <= 180; pos += 1)
myservo.write(pos);
}
else if (BT_input=='n')
{
for (pos = 180; pos >= 90; pos -= 1)
myservo.write(pos);
}}}
.rTable { display: table; width: 100%;} .rTableRow { display: table-row; } .rTableHeading { background-color: #ddd; display: table-header-group; } .rTableCell, .rTableHead { display: table-cell; padding: 3px 10px; border: 1px solid #999999; } .rTableHeading { display: table-header-group; background-color: #ddd; font-weight: bold; } .rTableFoot { display: table-footer-group; font-weight: bold; background-color: #ddd; } .rTableBody { display: table-row-group; }