0

Arduino board type used in this session is Arduino Uno R3 DIP/SMD CH340

Below is the description of wiring and code in Arduino to assemble a Bluetooth RC car using android smartphone:

  1. Tested the motor dc result both of wheel works (can spin forward and or backward). power direct from the battery.
  2. Tested HC-05 bluetooth moduled. The phone can paired the bluetooth module.
  3. Tested out1 out2 out3 and out4 on L298N using direct power from the battery the wheel spinning (forward and or backward).
  4. The code for the Bluetooth rc simple car used below as described.

The car failed to move (forward, backward, turn left/right). how to make the motor dc and or the motor stepper works remotely. thank you

Wiring Table

L298N Motor Stepper / Driver Motor

HC-05 Bluetooth module

Pin to Arduino

Fritzing Skematic #include SoftwareSerial mySerial(12, 13); // RX, TX #define m1 3 #define m2 5 #define m3 9 #define m4 10

int data=0,kec=0;
boolean forward=true;
int fast[11]={0,80,100,120,140,160,180,200,220,240,255};
void setup()
{
 pinMode(m1,OUTPUT);
 pinMode(m2,OUTPUT);
 pinMode(m3,OUTPUT);
 pinMode(m4,OUTPUT);
 mySerial.begin(9600);
 }
void motorOut(unsigned char lpwm, unsigned char rpwm, boolean arrow){
 if(arrow==false){
 digitalWrite(m3,HIGH);
 digitalWrite(m1,LOW);
 analogWrite(m4,255-lpwm);
 analogWrite(m2,rpwm);
 }
 else{
 digitalWrite(m3,LOW);
 digitalWrite(m1,HIGH);
 analogWrite(m4,lpwm);
 analogWrite(m2,255-rpwm);
 }
}
void loop(){
 if(mySerial.available()>0){
 data=mySerial.read();
 if (data =='0') { kec=0;}
 else if (data =='1') { kec=1;}
 else if (data =='2') { kec=2;}
 else if (data =='3') { kec=3;}
 else if (data =='4') { kec=4;}
 else if (data =='5') { kec=5;}
 else if (data =='6') { kec=6;}
 else if (data =='7') { kec=7;}
 else if (data =='8') { kec=8;}
 else if (data =='9') { kec=9;}
 else if (data =='q') {kec=10;}
 //S= Stop
 if (data == 'S')
 { motorOut(0,0,false); }
//F=Forward
if (data=='F')
{ motorOut(fast[kec],fast[kec],true); }
//I=turn right forward
if (data=='I')
{ motorOut(fast[kec],((fast[kec])/2),true);}
//G=turn left forward
if (data=='G')
{ motorOut(((fast[kec])/2),fast[kec],true); }
//R=turn right
if(data=='R')
{ motorOut(fast[kec],0,true); }
//L=turn left
if(data=='L')
{ motorOut(0,fast[kec],true); }
//B=back
if(data=='B')
{ motorOut(fast[kec],fast[kec],false); }
//H=turn left back
 if (data=='H')
 { motorOut(((fast[kec])/2),fast[kec],false); }
//turn right back
 if (data=='J')
 { motorOut(fast[kec],((fast[kec])/2),false); }
 }
}
asked Jul 9, 2018 at 2:00
5
  • 1
    you forgot to ask a question Commented Jul 9, 2018 at 3:34
  • 1
    what tests have you done? Commented Jul 9, 2018 at 3:35
  • Instead of writing many if-else if statements, use a simple switch(data){ case '0': Commented Jul 9, 2018 at 13:17
  • What data gets send to mySerial? Can you confirm, that the correct data is actually received? Maybe echo it back to the source. If this doesn't work, your serial connection doesn't work (maybe because the HC-05 isn't really connected). If it works, try to drive the motor through the driver, by connecting the corresponding pins to 5V. If this doesn't work, your driver connection is not correct. You should provide a schematic instead of photos. Commented Jul 9, 2018 at 13:26
  • nothing displayed data from serial monitor. HC-05, icon indicator green in android phone (success conecting to the car). L298N, the motor run after i give direct power to PIN 5 and Ground. the battery 4 x 1.2 alkaline or 9v Commented Jul 12, 2018 at 19:49

1 Answer 1

-1

sorry for my careless. finaly its works....wrong pin assign the main problem....should be IN1, IN2, IN4 and IN3 not IN1, IN2, IN3 and IN4. thank you for all hands for help before

answered Jul 14, 2018 at 14:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.