Design of a mobile phone Bluetooth remote control car controlled by 51 single chip microcomputer

Publisher:CrystalBreezeLatest update time:2021-12-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Without further ado, here are the pictures of the real thing

insert image description here
insert image description here
insert image description here

1. Project Components List

1. Buy a smart car chassis from Taobao (my car is four-wheel drive, so it has four motors, two acrylic plates and some accessory screws)

2. Two L298n modules (one 298 controls two motors)

3. HC-06 Bluetooth module

4. Battery box and 3 18650 batteries

5. Single chip microcomputer minimum system

6. At least 12 DuPont wires, the more the better

7. Several wires (for connecting the motor, and the battery box to L298N and the microcontroller)


2. Production process

First, learn about the wiring of L298N. I was also confused for a long time at that time, but I learned it by groping. Generally, there are materials in the store. Then, the use of the Bluetooth module. After getting the Bluetooth module, if you have a development board (if you don’t have it, use the microcontroller burner), first connect TXD to TXD and RXD to RXD, open the computer’s serial port assistant to establish communication with Bluetooth, open AT, and send AT command sets, such as setting the baud rate, changing the name, and changing the pairing password. But when connecting and communicating with the microcontroller via Bluetooth, TXD is connected to RXD. The last one is that I often run into obstacles when wiring. For example, the wire you thought was connected was actually not connected properly, and it didn’t work at all. I still took multimeter B to find out.


Because I forgot to buy the battery box, I used 12V DC power, which caused the remote control car to drag along the wires.


3. Physical picture

(I am dragging a car with a power cord and a power bank, but I don’t have electricity)


The data includes some information about L298N, as well as the Bluetooth manual (just read the AT command set) and source code.


/Mobile Bluetooth remote control car APP can be searched in the application market for Bluetooth serial port assistant

Turning left and right is about 90 degrees. My car is a four-wheel drive. If there is only one l298N, delete the one with 2.

PWM has ten levels of speed change/


#include


#define Left_moto2_pwm P0_4 //Connect to the ENA enable terminal of the driver module, input PWM signal to adjust the speed of the left rear wheel

#define Right_moto2_pwm P0_5 //Connect to drive module ENB right rear wheel

#define Left_moto_pwm P1_4 //Connect to the ENA enable terminal of the driver module, input PWM signal to adjust the speed of the left front wheel

#define Right_moto_pwm P1_5 //Connect to drive module ENB right front wheel

#define uchar unsigned char

#define uint unsigned int


sbit P0_4=P0^4; //define P0_4

sbit P0_5=P0^5; //define P0_5

sbit P1_4=P1^4; //define P1_4

sbit P1_5=P1^5; //define P1_5


/Motor drive IO definition/

sbit IN1 = P1^2; //1, left motor reverses the front wheel

sbit IN2 = P1^3; //1, left motor rotates the front wheel forward

sbit IN3 = P1^6; //1, right motor rotates the front wheel forward

sbit IN4 = P1^7; //1, right motor reverses the front wheel

/*sbit EN1 = P1^4; //1 left motor enabled

sbit EN2 = P1^5; //1, right motor enabled*/


sbit IN5 = P0^2; //1, the left motor reverses the rear wheel

sbit IN6 = P0^3; //1, left motor rotates the rear wheel forward

sbit IN7 = P0^6; //1, right motor rotates the rear wheel forward

sbit IN8 = P0^7; //1, right motor reverses rear wheel

/*sbit EN3 = P0^4; //1 left motor enables rear wheel

sbit EN4 = P0^5; //1, right motor enables rear wheel*/


bit Right_moto_stop=1;

bit Left_moto_stop =1;

unsigned int time=0;

int pwm=1;


#define left_motor_en EN1 = 1 //Left motor enable

#define left_motor_stops EN1 = 0 //Left motor stops

#define right_motor_en EN2 = 1 //right motor enable

#define right_motor_stops EN2 = 0 //right motor stops


#define left_motor2_en EN3 = 1 //After the left motor is enabled

#define left_motor2_stops EN3 = 0 //After the left motor stops

#define right_motor2_en EN4 = 1 //After the right motor is enabled

#define right_motor2_stops EN4 = 0 //After the right motor stops


#define left_motor_go IN1 = 0, IN2 = 1 // Left motor forward

#define left_motor_back IN1 = 1, IN2 = 0 // Left motor reverses

#define right_motor_go IN3 = 1, IN4 = 0 //right motor forward

#define right_motor_back IN3 = 0, IN4 = 1 //Right motor reverse


#define left_motor2_go IN5 = 0, IN6 = 1 // Left motor forward

#define left_motor2_back IN5 = 1, IN6 = 0 //Left motor reverses

#define right_motor2_go IN7 = 1, IN8 = 0 // Right motor forward

#define right_motor2_back IN7 = 0, IN8 = 1 //Right motor reverse


unsigned char pwm_val_left =0; // variable definition

unsigned char push_val_left =0; // Left motor duty cycle N/10

unsigned char pwm_val_right =0;

unsigned char push_val_right=0; // right motor duty cycle N/10


void delay(uint z)

{

uint x,y;

for(x = z; x > 0; x–)

for(y = 114; y > 0 ; y–);

}


//Bluetooth initialization

void UART_INIT()

{

SM0 = 0;

SM1 = 1; //Serial port working mode 1

REN = 1; // Allow serial port to receive

EA = 1; // Enable general interrupt

ES = 1; //Open serial port interrupt

TMOD = 0x20; //8-bit auto-reload mode

TH1 = 0xfd;

TL1 = 0xfd; //9600 baud rate

TR1 = 1; //Start timer 1

}


/****************************************************************************/

void run(void) //pwm speed control function

{

push_val_left =pwm; //PWM adjustment parameter 1-10 1 is the slowest, 10 is the fastest. Changing this value can change its speed

push_val_right =pwm; //PWM adjustment parameter 1-10 1 is the slowest, 10 is the fastest. Changing this value can change its speed

if(pwm10) pwm=0;

if(pwm0&&pwm<0) pwm=0;


}


/*******************************************************************************/

/ PWM modulated motor speed /

/*******************************************************************************/


/* Left motor speed control*/

/*Adjust the value of push_val_left to change the motor speed and duty cycle*/

void pwm_out_left_moto(void)

{

if(Left_moto_stop)

{

if(pwm_val_left<=push_val_left)

{ Left_moto_pwm=1;

Left_moto2_pwm=1; }

else

{ Left_moto_pwm=0;Left_moto2_pwm=0; }


if(pwm_val_left>=10)

pwm_val_left=0;

}

else { Left_moto_pwm=0;Left_moto2_pwm=0; }

}

/********************************************************************/

/ Right motor speed control /

void pwm_out_right_moto(void)

{

if(Right_moto_stop)

{

if(pwm_val_right<=push_val_right)

{Right_moto_pwm=1;

Right_moto2_pwm=1; }

else

{Right_moto_pwm=0;

Right_moto2_pwm=0;}

if(pwm_val_right>=10)

pwm_val_right=0;

}

else {Right_moto_pwm=0;Right_moto2_pwm=0; }

}

/**********************************************************/

///TIMER0 interrupt service sub-function generates PWM signal/

void timer0()interrupt 1 using 2

{

TH0=0XF8; //1Ms timing

TL0=0X30;

time++;

pwm_val_left++;

pwm_val_right++;

pwm_out_left_moto();

pwm_out_right_moto();

}


//The car moves forward

void forward()

{

ET0 = 1;

run(); //pwm program

left_motor_go; //Left motor goes forward

right_motor_go; //right motor goes forward

left_motor2_go; //Left motor moves forward and rear wheels

right_motor2_go; //right motor goes forward and rear wheels

}


void left_go() //Turn left

{

ET0 = 1;

run();

left_motor_back;

right_motor_go;

left_motor2_back;

right_motor2_go;

delay(700);

forward();

}

//Turn right

void right_go()

{

ET0 = 1;

run();

delay(50);

right_motor_back;

left_motor_go;

right_motor2_back;

left_motor2_go;

delay(700);

forward();

}

//The car turns left

void left()

{

ET0 = 1;

run();

delay(50);

right_motor_go; // right motor goes forward

left_motor_back; // Left motor moves backward

right_motor2_go; // right motor goes forward

left_motor2_back; // Left motor moves backward

}


//The car turns right

void right()

{

ET0 = 1;

run();

left_motor_go;

right_motor_back;

left_motor2_go;

right_motor2_back;

}


//The car moves backward

void back()

{

ET0 = 1;

run();

left_motor_back;

right_motor_back;

left_motor2_back;

right_motor2_back;

}


//Stop the car

void stop()

{

ET0 = 0;

P1=0;

P0=0;

}


//Serial port interrupt

void UART_SER() interrupt 4

{

if(RI)

{

RI = 0; // Clear the receive flag

switch(SBUF)

{

case 'g': forward(); break;//forward

case 'b': back(); break;//backward

case 'l': left(); break;//Turn left

case 'r': right(); break;//turn right

case 's': stop(); break;//stop

case 'z': left_go(); break; //Turn left

case 'y': right_go(); break; //Turn right

case 'p': pwm++;break; //acceleration

case 'c': pwm–;break; // deceleration

}


    }

1

}


void main()

{

TMOD=0X01;

TH0= 0XF8; //1ms timing

TL0 = 0X30;

TR0= 1;

ET0= 1;

EA = 1;

UART_INIT(); //Serial port initialization

while(1);

}

Reference address:Design of a mobile phone Bluetooth remote control car controlled by 51 single chip microcomputer

Previous article:51 single chip microcomputer drives LCD1602 liquid crystal display system
Next article:Universal password lock controlled by 51 single chip microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号