Bluetooth Car Robot
In this project, We will use Zduino BT to make a car robot with L298P motor driven shields, control it with Bluetooth ,and you can add more sensor module, get or send more data by Bluetooth.
Preparation:
We need a Zduino BT, a L298P shields, many Dupont lines, a CP2102 module and a Car Robot chassis with 2 or 4 motors.
First we connect Zduino BT to computer through CP2102 module(RX to TX,TX to RX),and supply electricity.
Open Serial Debug assistant, choose the right COM of CP2102, and then Open this Serial.
After that,You should send these AT Command to Configure Zduino BT:
- AT
Answer:OK(test connection)
- AT+NAME=”XXX”//XX will be the name of Zduino BT.
Answer:OK
- AT+NAME?
Answer:”XXX”//check the name.
- AT+PASS=”XXXXXX”//XXXXXX is the password of Zduino BT,default is 000000
Answer:OK
- AT+PASS?//check the password.
Answer:OK
- AT+TYPE=”X”//X(0,1),0 means connect without password,1 means connect with password.Default is “0”
Answer:OK
- AT+TYPE?
Answer:OK//check the type.
then add L298P shields on to Zduino BT, then put them on the Car robot chassis.connect motor and L298P shields.
Like This :
After the hardware preparation, we need a Phone of a Pad or…whatever device with Bluetooth 4.0.
Install a Bluetooth debug assistant.
About the Code
Here is a sample code.
char val; int INA = 4; int PWMA = 5; int INB = 7; int PWMB = 6; void setup() { pinMode(INA,OUTPUT); pinMode(INB,OUTPUT); Serial.begin(9600); } void loop() { val = Serial.read(); if (-1 != val) { switch(val) { case 'c':Serial.println("testOk");break; case 'w':motosp(-180,-180);break; case 's':motosp(180,180);break; case 'a':motosp(0,-150);break; case 'd':motosp(-150,0);break; } delay(20); } } void motosp(int sp1,int sp2) { if(sp1>0) { digitalWrite(INA, HIGH); } else { digitalWrite(INA, LOW); } if(sp2>0) { digitalWrite(INB, HIGH); } else { digitalWrite(INB, LOW); } analogWrite(PWMA,abs (sp1)); analogWrite(PWMB,abs (sp2)); }
Upload this code into Zduino BT,then Open Bluetooth debug assistant.Just send a letter“c” in the characteristic 6 in UTF-8 string,then if it answer “test0k”,that means it works . Now you can send “w”,”a”,”s”,”d”to control this little Car robot. You can DIY moves whatever you want through edit the Code.