hbolanos2001
Published © CERN-OHL

Bluetooth Controlled LEGO Toy Car

Enjoy teaching your kids basic electronics and as a reward get them a unique Toy.

IntermediateProtip6,015
Bluetooth  Controlled LEGO Toy Car

Things used in this project

Story

Read more

Schematics

carritomasTABSchem_bb.jpg

carritomasTABSchem_schem.png

Code

CarritomasTAB.ino

C/C++
//Update No.: 2 ( Beta Version)  original version issued: August_29_2016
//Developed by : Hernando Bolaos
//***********************************************************************************************************************************************
//Disclaim Note:
//THIS SOFTWARE IS PROVIDED BY THE DEVELOPER "AS IS" AND ANY EXPRESSED OR 
//IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
//OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
//IN NO EVENT SHALL THE DEVELOPER OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
//INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
//(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
//HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
//STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
//IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
//THE POSSIBILITY OF SUCH DAMAGE.
//*************************************************************************************************************************************************




const int ENB = 3;
const int IN4 = 5;
const int IN3 = 6;
const int ENA = 11;
const int IN2 = 9;
const int IN1 = 10;



byte speed = 0;
char data=0;


void setup() {
  pinMode(ENB, OUTPUT); //Set  digital output PWM as  motor 1 speed value
  pinMode(IN4, OUTPUT); //Set digital otuput PWM as motor 1 direction A
  pinMode(IN3, OUTPUT); //Set digital ouput  PWM as motor 1 direction B 
  pinMode(ENA, OUTPUT); //Set digital output PWM as motor 2 speed value
  pinMode(IN2, OUTPUT); //Set digital output PWM as motor 2 direction B
  pinMode(IN1, OUTPUT); //Set digital output PWM as motor 2 direction A
  
  Serial.begin(9600);   //Sets the baud for serial data transmission 
}

 void loop() {

if(Serial.available() > 0)      // Send data only when you receive data:
          
           {
           data = Serial.read();        //Read the incoming data & store into data
           Serial.print(data);          //Print Value inside data in Serial monitor
           Serial.print("\n");   
           delay(200);    
 

             if(data == 'F')    {            // Checks whether value of data is equal to 1 - it works as pulse and latching
            
            Serial.println("  Forward command Received on Bluetooth - F !!!  ");   //Send message to serial 
            forward();
            delay(100);
            
               
         
         }

            
            if(data == 'B')   {      //  Checks whether value of data is equal to B - it works as pulse and latching
           
           Serial.println(" Backward Command received on Bluetooth - B !!!  ");   //Send message to serial 
           
           backward();
           delay(100);

           

           
             }

 

           if(data == 'S')    {            // Checks whether value of data is equal to S - it works as pulse and latching



            Serial.println(" Stop command received on  Bluetooth - S !!!  ");
            pare();
            delay(100);
       
         
         }

        if(data == 'L')    {            // Checks whether value of data is equal to L - it works as pulse and latching



            Serial.println(" Left command Received on Bluetooth - L !!!  ");
           leftF();
           delay(2000);
           forward();
       
         
      }

          if(data == 'R')    {            // Checks whether value of data is equal to R - funciona como pulso



            Serial.println(" Right command received on Bluetooth - R !!!  ");//Send message to serial 
            rightF();
           delay(2000);
           forward();
       
         
        }

       if(data == 'X')    {            // Checks whether value of data is equal to R - it works as pulse and latching



            Serial.println(" Left command received on Bluetooth - R !!!  ");//Send message to serial 
            leftB();
           delay(2000);
           backward();
       
         
        }

      if(data == 'Y')    {            // Checks whether value of data is equal to R - it works as pulse and latching



            Serial.println(" Right command received on Bluetooth - R !!!  ");//Send message to serial 
           rightB();
           delay(2000);
           backward();
       
         
        }




      if(data == 'V')    {            // Checks whether value of data is equal to R - funciona como pulso



            Serial.println(" Vmin received on Bluetooth - V !!!  ");//Send message to serial 
            speed = 80; // Sets Vmin output = 80
       
         
        }


     if(data == 'W')    {            // Checks whether value of data is equal to R - funciona como pulso



            Serial.println(" Vmed received on Bluetooth -W !!!  ");//Send message to serial 
            speed = 128;// Sets Vmed output = 128
       
         
        }



     if(data == 'Z')    {            // Checks whether value of data is equal to R - funciona como pulso



            Serial.println(" Vmax received on Bluetooth - Z !!!  ");//Send message to serial 
            speed = 255;// Sets Vmax output = 255
       
         
        }
       
           }


 
 
}

void backward() { //Backward routine

  digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);

analogWrite(ENA, speed);
analogWrite(ENB, speed);


}

void forward() {  //Forward routine
  digitalWrite (IN1, LOW);  
  digitalWrite (IN2, HIGH);
  digitalWrite (IN3, LOW);
  digitalWrite (IN4, HIGH);

analogWrite(ENA, speed);
analogWrite(ENB, speed);

}


void pare() {        //Stop
  analogWrite(ENA, 0);
  analogWrite(ENB, 0);

}


void leftF() {             //Left going Forward routine
digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
  digitalWrite (IN3, LOW);
  digitalWrite (IN4, HIGH);

analogWrite(ENA, speed);
analogWrite(ENB, 0);
}


void rightF() {         //Right going forward routine 
digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
  digitalWrite (IN3, LOW);
  digitalWrite (IN4, HIGH);

analogWrite(ENA, 0);
analogWrite(ENB, speed);
}


void leftB() {             //Left going backward routine
digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);

analogWrite(ENA, speed);
analogWrite(ENB, 0);
}


void rightB() {         //Right going backward routine
  digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);

analogWrite(ENA, 0);
analogWrite(ENB, speed);
}

Credits

hbolanos2001
11 projects • 33 followers
Contact
Thanks to Andres cruz - electronilab .co and Android Studio platform creators.

Comments

Please log in or sign up to comment.