Home > other >  Based on the mobile phone bluetooth arduino remote control car
Based on the mobile phone bluetooth arduino remote control car

Time:05-07

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --//
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
///
//motor/set
///

# define leftA_PIN 5
# define leftB_PIN 6
9 # define righA_PIN
# define righB_PIN 10
Void motor_pinint ();//pin initializing
Void forward ();//forward
Void back ();//back
Void turnLeftOrigin ();//in situ left
Void turnRightOrigin ();//in situ right
Void turnRightforword ();//right front
Void turnLeftforword ();//the left
Void turnLeftback ();//left after
Void turnRightback ();//right rear
Void _stop ();//stop

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --//
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
///
Bluetooth remote control///
///
Int the receive;
Void reve (void);

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --//

Void setup ()
{
Serial. The begin (9600);//serial port baud rate 9600 (mobile end use)
Motor_pinint ();
}
Void loop ()
{
Reve ();
}

Void reve (void)
{
The receive=Serial. The parseInt ();
If (the receive==7) {forward (); delay(500); _stop (); }//forward
Else if (the receive==6) {back (); delay(500); _stop (); }//back
Else if (the receive==1) {_stop (); delay(500); _stop (); }//parking
Else if (the receive==3) {turnLeftforword (); delay(500); _stop (); }//left before
Else if (the receive==2) {turnRightforword (); delay(500); _stop (); }//right front
Else if (the receive==5) {turnLeftback (); delay(500); _stop (); }//left after
Else if (the receive==4) {turnRightback (); delay(500); _stop (); }//right rear
Else if (the receive==8) {turnLeftOrigin (); Delay (250); _stop (); }//in situ left
Else if (the receive==9) {turnRightOrigin (); Delay (250); _stop (); }//place right
}

Initialize the *//* motor pin
Void motor_pinint ()
{
PinMode (leftA_PIN, the OUTPUT);//set the pin to output pin
PinMode (leftB_PIN, the OUTPUT);//set the pin to output pin
PinMode (righA_PIN, the OUTPUT);//set the pin to output pin
PinMode (righB_PIN, the OUTPUT);//set the pin to output pin
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Forward the son function - forward function
Functions: forward control vehicles
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void forward ()
{
AnalogWrite (leftA_PIN, 180);
AnalogWrite (leftB_PIN, 0);//left forward
AnalogWrite (righA_PIN, 180);
AnalogWrite (righB_PIN, 0);//right wheel forward
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Son back function - back function
Function: control vehicles back
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void back ()
{
AnalogWrite (leftA_PIN, 0);
AnalogWrite (leftB_PIN, 180);//revolver back
AnalogWrite (righA_PIN, 0);
AnalogWrite (righB_PIN, 180);//right wheel back
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TurnLeftOrigin sub function - situ left child function
Function: control vehicles in situ left
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void turnLeftOrigin ()
{
AnalogWrite (leftA_PIN, 0);
AnalogWrite (leftB_PIN, 120);//revolver back
AnalogWrite (righA_PIN, 120);
AnalogWrite (righB_PIN, 0);//right wheel forward
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TurnRightOrigin sub function - situ right rotor function
Function: turn right control vehicles in situ
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void turnRightOrigin ()
{
AnalogWrite (leftA_PIN, 120);
AnalogWrite (leftB_PIN, 0);//left forward
AnalogWrite (righA_PIN, 0);
AnalogWrite (righB_PIN, 120);//right wheel back
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TurnRightforword sub function - right front movement function
Function: control vehicles right front
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void turnRightforword ()
{
AnalogWrite (leftA_PIN, 200);
AnalogWrite (leftB_PIN, 0);//loads fast forward
AnalogWrite (righA_PIN, 120);
AnalogWrite (righB_PIN, 0);//right wheel down
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TurnLeftforword son function - the left front movement function
Function: control vehicles left before
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void turnLeftforword ()
{
AnalogWrite (leftA_PIN, 120);
AnalogWrite (leftB_PIN, 0);//left down
AnalogWrite (righA_PIN, 200);
AnalogWrite (righB_PIN, 0); Fast forward/right/round
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TurnRightforword sub function - right rear movement function
Function: control vehicles right rear
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void turnRightback ()
{
AnalogWrite (leftA_PIN, 0);
AnalogWrite (leftB_PIN, 200);//fast revolver back
AnalogWrite (righA_PIN, 0);
AnalogWrite (righB_PIN, 120);//right wheel slowly back
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TurnLeftforword sub function - left after the movement function
Function: control vehicles left after
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void turnLeftback ()
{
AnalogWrite (leftA_PIN, 0);
AnalogWrite (leftB_PIN, 120);//slow revolver back
AnalogWrite (righA_PIN, 0);
AnalogWrite (righB_PIN, 200);//right round fast back
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Stop child function - to stop the child function
Function: control vehicles stop
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void _stop ()
{
AnalogWrite (leftA_PIN, 0);
nullnullnullnull
  • Related