کد:
Smart Car Bluetooth phone control
Arduino via Bluetooth communication
<!--[if !vml]--> <!--[endif]--> <!--[if !vml]--> <!--[endif]--> Bluetooth - This name came from
a tenth-century Danish King Harald Blatand, Blatand meaning in the English language can be
interpreted as Bluetooth (Bluetooth).
The so-called Bluetooth (Bluetooth) technology, in fact, is a short-range radio technology, the
use of "Bluetooth" technology that can effectively simplify PDAs, notebook computers and
communications mobile phone handsets and other mobile communications terminal equipment,
but also able to successfully These simplify the communication device and the Internet (Internet)
between them so that the modern data transmission between the communication device and
the Internet more quickly and efficiently, to broaden the wireless communication path.
Because it is the first to deal with the Bluetooth module, today or take a small test chopper,
make Arduino and pc successfully communicate it. Let's wiring, the board +5 V connection
Bluetooth VCC, GND motherboard connector Bluetooth-GND, TX motherboard connection
Bluetooth RX, RX connected Bluetooth TX. After the success of the Bluetooth module
connected to the power supply and PC, Bluetooth module power indicator flashes green link light
is lit.
Here's a look at the program, I let my Arduino receives input "r", the interface is pin13 LED
flash once, and then output the words keyes.
Procedures are as follows:
char val;
int ledpin = 13;
void setup ()
{
Serial.begin (9600);
pinMode (ledpin, OUTPUT);
}
void loop ()
{
val = Serial.read ();
if (val == 'r')
{
digitalWrite (ledpin, HIGH);
delay ((500);
digitalWrite (ledpin, LOW);
delay (500);
Serial.println ("keyes");
}
}
Here we learn about the Arduino Bluetooth remote control programmable intelligent car. Can
be controlled via Bluetooth forward, backward, turn left, turn right, etc., simple keys, computer
and mobile phone two control modes. (Android mobile operating system support 2.3.7
Above. Computer must own Bluetooth)
The first time you need to use the car phone with Bluetooth pairing (after the first pairing later
in the wireless device location would not), see the following first steps:
1 Turn on Bluetooth Oh I remember the phone, open the Bluetooth software will alert the user
to open
2 Then, as shown in the text prompts, connect Bluetooth devices, Bluetooth devices paired
scans Oh, otherwise you can not connect the car.
3 matching car, the password is "1234" try it.
Then it can flourish.
Arduino Bluetooth remote control programmable smart car program:
/ / *******************************
int MotorRight1 = 5;
int MotorRight2 = 6;
int MotorLeft1 = 10;
int MotorLeft2 = 11;
void setup ()
{
Serial.begin (9600);
pinMode (MotorRight1, OUTPUT); / / Pin 8 (PWM)
pinMode (MotorRight2, OUTPUT); / / Pin 9 (PWM)
pinMode (MotorLeft1, OUTPUT); / / Pin 10 (PWM)
pinMode (MotorLeft2, OUTPUT); / / Pin 11 (PWM)
}
void go () / / Forward
{
digitalWrite (MotorRight1, LOW);
digitalWrite (MotorRight2, HIGH);
digitalWrite (MotorLeft1, LOW);
digitalWrite (MotorLeft2, HIGH);
}
void left () / / turn right
{
digitalWrite (MotorRight1, HIGH);
digitalWrite (MotorRight2, LOW);
digitalWrite (MotorLeft1, LOW);
digitalWrite (MotorLeft2, HIGH);
}
void right () / / turn left
{
digitalWrite (MotorRight1, LOW);
digitalWrite (MotorRight2, HIGH);
digitalWrite (MotorLeft1, HIGH);
digitalWrite (MotorLeft2, LOW);
}
void stop () / / stop
{
digitalWrite (MotorRight1, LOW);
digitalWrite (MotorRight2, LOW);
digitalWrite (MotorLeft1, LOW);
digitalWrite (MotorLeft2, LOW);
}
void back () / / Check out
{
digitalWrite (MotorRight1, HIGH);
digitalWrite (MotorRight2, LOW);
digitalWrite (MotorLeft1, HIGH);
digitalWrite (MotorLeft2, LOW);;
}
void loop ()
{
char val = Serial.read ();
Serial.write (val);
if (-1! = val) {
if ('W' == val)
go ();
else if ('A' == val)
left ();
else if ('D' == val)
right ();
else if ('S' == val)
back ();
else if ('Q' == val)
stop ();
delay (500);
}
else
{
/ / Stop ();
delay (500);
}
}