Arduino Bluetooth RC car CODE
Help me by sharing this post

This is the code for the Arduino based RC car with Bluetooth conenction. You will need the Android App controller as well from this link. Make sure you install the needed libraries as well. Downlaod the .zip file or copy+paste from below. Read all comments in the code in order to understand more.







schematic arduino Bluetooth RC car radio



MAIN .ino
/* Test code for the RC car PCB with Bluetooth
 *  Tutorial: https://www.electronoobs.com/eng_arduino_tut92.php
 *  Schematic: https://www.electronoobs.com/eng_arduino_tut92_sch2.php
 *  Video: https://www.youtube.com/watch?v=bb1u_kne-m4
 * Upload this code to the Arduino NANO
Please, like share and subscribe : https://www.youtube.com/c/ELECTRONOOBS
*/


#include <SoftwareSerial.h>
#include <DFMiniMp3.h>          //Downlaod it here: https://www.electronoobs.com/eng_arduino_DFPlayer_Mini_Mp3_by_Makuna.php




class Mp3Notify
{
public:
  static void OnError(uint16_t errorCode)
  {
    // see DfMp3_Error for code meaning
    Serial.println();
    Serial.print("Com Error ");
    Serial.println(errorCode);
  }
  static void OnPlayFinished(uint16_t track)
  {
    Serial.print("Play finished for #");
    Serial.println(track);  
  }
  static void OnCardOnline(uint16_t code)
  {
    Serial.println("Card online ");
  }
  static void OnCardInserted(uint16_t code)
  {
    Serial.println("Card inserted ");
  }
  static void OnCardRemoved(uint16_t code)
  {
    Serial.println("Card removed ");
  }
};

// instance a DFMiniMp3 object, 
// defined with the above notification class and the hardware serial class
//
DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial);


int mot_A_L = 3;
int mot_A_R = 5;
int mot_B_L = 6;
int mot_B_R = 9;

bool movement = false;
bool stopped = false;
bool fire = false;
char Received = '0';
/**************************************************/



void setup()
{
  pinMode(mot_A_L,OUTPUT);
  pinMode(mot_A_R,OUTPUT);
  pinMode(mot_B_L,OUTPUT);
  pinMode(mot_B_R,OUTPUT);
  digitalWrite(mot_A_L,LOW);
  digitalWrite(mot_A_R,LOW);
  digitalWrite(mot_B_L,LOW);
  digitalWrite(mot_B_R,LOW);

  
 Serial.begin(9600);  
 mp3.begin();
 uint16_t volume = mp3.getVolume();
 mp3.setVolume(20);  
 uint16_t count = mp3.getTotalTrackCount();
 delay(200);
 }


 
void loop()
{
 
if(Serial.available()>0)
{
  Received = Serial.read();
  //char Rec = char(Received);  
  //Serial.println(Received); //This is to visualise the received character      
}




if(Received == '0')
{
  if(!stopped)
  {
    mp3.playMp3FolderTrack(2); 
    //mp3_next();     
    stopped = true;   
  } 
  digitalWrite(mot_A_L,LOW); 
  digitalWrite(mot_A_R,LOW); 
  digitalWrite(mot_B_L,LOW); 
  digitalWrite(mot_B_R,LOW); 
  movement = false; 
  fire = false;
}

if (Received == '1')
{
  if(!movement)
  {
    mp3.playMp3FolderTrack(1); 
    //mp3_next();
    movement = true;   
  }  
  digitalWrite(mot_A_L,HIGH); 
  digitalWrite(mot_A_R,LOW); 
  digitalWrite(mot_B_L,LOW); 
  digitalWrite(mot_B_R,HIGH); 
  stopped = false;
}

if (Received == '2')
{
  if(!movement)
  {
    mp3.playMp3FolderTrack(1); 
    //mp3_next();
    movement = true;   
  }  
  digitalWrite(mot_A_L,HIGH); 
  digitalWrite(mot_A_R,LOW); 
  digitalWrite(mot_B_L,HIGH); 
  digitalWrite(mot_B_R,LOW); 
  stopped = false; 
}

if (Received == '3')
{
  if(!movement)
  {
    mp3.playMp3FolderTrack(1); 
    //mp3_next();
    movement = true;   
  }  
  digitalWrite(mot_A_L,LOW); 
  digitalWrite(mot_A_R,HIGH); 
  digitalWrite(mot_B_L,HIGH); 
  digitalWrite(mot_B_R,LOW); 
  stopped = false; 
}

if (Received == '4')
{
  if(!movement)
  {
    mp3.playMp3FolderTrack(1); 
    //mp3_next();
    movement = true;   
  }  
  digitalWrite(mot_A_L,LOW); 
  digitalWrite(mot_A_R,HIGH); 
  digitalWrite(mot_B_L,LOW); 
  digitalWrite(mot_B_R,HIGH); 
  stopped = false; 
}


if (Received == 'l')
{
  if(!fire)
  {
    mp3.playMp3FolderTrack(3); 
    //mp3_next();
    fire = true;   
  }  
  digitalWrite(mot_A_L,LOW); 
  digitalWrite(mot_A_R,LOW); 
  digitalWrite(mot_B_L,LOW); 
  digitalWrite(mot_B_R,LOW);   
}

}

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








yt_link
insta_link
fb_link
twitter_link

RC car code


ADVERTISERS

PCBWAY PCB service

PCBWAY PCB service





Arduino curso en español desde cero