LOGIN
Anmol Ratan
4
Collaborator
Electrical Engineering Student (Project Leader)
 · BengaluruIndia
Share
Report
Get Link
TASK
 Completed
Reward › Contribution Review
Assigned to
Kevin Tom

CODE FOR THE BLUETOOTH CONTROLLED CAR

char data = 0;//Variable for storing received data
void setup()
{
    Serial.begin(9600);//Sets the baud for serial data transmission                               
    pinMode(13,OUTPUT);//motor 1 pin 1
    pinMode(12,OUTPUT);//motor 1 pin 2
    pinMode(11,OUTPUT);//motor 2 pin 1
    pinMode(10,OUTPUT);//motor 2 pin 2
}
void loop()
{
   if(Serial.available() > 0)      // Send data only when you receive data:
   {
     data = Serial.read();        //Read the incoming data & store into data
      Serial.println(data);          //Print Value inside data in Serial monitor
              
      if(data == 'f') // Checks whether value of data is equal to 'f'
        {
         digitalWrite(13,HIGH);   
         digitalWrite(12, LOW);
         digitalWrite(11,HIGH);
         digitalWrite(10,LOW);
        }    
      if(data == 'r') //checks whether value of data is equal to 'r'
         {
          digitalWrite(13,HIGH);
          digitalWrite(12,LOW);
          digitalWrite(11,LOW);
          digitalWrite(10,HIGH);
         }
      if(data == 'b') //checks whether value of data is equal to 'b'
      {
        digitalWrite(13,LOW);
        digitalWrite(12,HIGH);
        digitalWrite(11,LOW);
        digitalWrite(10,HIGH);
      }
      if(data =='l') //checks whether value of data is equal to 'l'
      {
        digitalWrite(13,LOW);
        digitalWrite(12,HIGH);
        digitalWrite(11,HIGH);
        digitalWrite(10,LOW);
      }
      if(data == 's') //checks whether value of data is equal to 's'
      {
        digitalWrite(13,LOW);
        digitalWrite(12,LOW);
        digitalWrite(11,LOW);
        digitalWrite(10,LOW);
      }
     
        
   }
}
Arduino
Bluetooth
Contributions
Anmol Ratan

Code uploaded for Bluetooth car.!

Kevin Tom

I like it , that code will help in making bigger code into smaller compressed code , we can directly call the function wherever needed , GOOD WORK KEVIN

3 likes 
Like
Award Contribution
Kevin Tom
5
Collaborator
Electronics and Communication Student
 · MysuruIndia
Share
Report
Get Link
#define m11 11    // rear motor
#define m12 12
#define m21 10    // front motor
#define m22 9
char str[2],i;
void forward()
{
  digitalWrite(m11, LOW);
  digitalWrite(m12, LOW);
  digitalWrite(m21, HIGH);
  digitalWrite(m22, LOW);
}
void backward()
{
  digitalWrite(m11, LOW);
  digitalWrite(m12, LOW);
  digitalWrite(m21, LOW);
  digitalWrite(m22, HIGH); 
}
void left()
{
  digitalWrite(m11, HIGH);
  digitalWrite(m12, LOW);
  delay(100);
  digitalWrite(m21, HIGH);
  digitalWrite(m22, LOW);
}
void right()
{
  digitalWrite(m11, LOW);
  digitalWrite(m12, HIGH);
  delay(100);
  digitalWrite(m21, HIGH);
  digitalWrite(m22, LOW);
}
void Stop()
{
  digitalWrite(m11, LOW);
  digitalWrite(m12, LOW);
  digitalWrite(m21, LOW);
  digitalWrite(m22, LOW);
}
void setup() 
{
 Serial.begin(9600);
 pinMode(m11, OUTPUT);
 pinMode(m12, OUTPUT);
 pinMode(m21, OUTPUT);
 pinMode(m22, OUTPUT);
}
void loop() 
{
 while(Serial.available())
 {
   char ch=Serial.read();
   str[i++]=ch;
   
   if(str[i-1]=='1')
   {
    Serial.println("Forward");
    forward();
    i=0;
   }
   else if(str[i-1]=='2')
   {
    Serial.println("Left");
    right();
    i=0;
   }
   else if(str[i-1]=='3')
   {
     Serial.println("Right");
     left();
     i=0;
   }
   
   else if(str[i-1]=='4')
   {
     Serial.println("Backward");
     backward();
     i=0;
   }
   else if(str[i-1]=='5')
   {
     Serial.println("Stop");
     Stop();
     i=0;
   }
   delay(100);
 }
}

This was what I used for my robot.Works well !
You can avoid that print statements if you want

Contribution

I like it , that code will help in making bigger code into smaller compressed code , we can directly call the function wherever needed , GOOD WORK KEVIN

Applicant
Like
1 like 
Award Contribution
Leave a reply...
DISCOVER
CHAT
HIRE
ACTIVITY
FEED
New Post
Help
Start Project
Online Users
Share Link