Go Down

Topic: simple h-bridge tank (Read 49 times) previous topic - next topic

nikola50

Ok, first of all, i must tell that im total noob when it comes to programming, this is my first attempt to do anything. I modified bluetooth led on-off code to run 2 motors trough h-bridge. I want that because i want to remote controll tank trough bluetooth module. I know its not big problem, its just some command witch i dont know, but i would like if someone of more expirienced programmers would like to help me with this. Whole code is supposed to work like "i pressed button on mobile phone-arduino do theese commands, i let button, arduino stops". Its really simple, but for me, as a noob, its not. Problem is that motors are running only when i send command "a" and "c", and all other commands are not working. Also, problem is that all thoose commands are working constantly, they are not stopping when i let button. If its possible, i would also like help with that.

AWOL

Code: [Select]

char junk;
String inputString="";

void setup()                    // run once, when the sketch starts
{
 Serial.begin(9600);            // set the baud rate to 9600, same should be of your Serial Monitor
 pinMode(3, OUTPUT);//motor1 pin1
 pinMode(4, OUTPUT);//motor1 pin2
 pinMode(5, OUTPUT);//motor2 pin1
 pinMode(6, OUTPUT);//motor2 pin2
 
}

void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters coming on serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0) 
    { junk = Serial.read() ; }      // clear the serial buffer
   
    if(inputString == "a"){         //going foward, both motors
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
   
      (inputString == "d");    //going backward, both motors
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
   
     
     (inputString == "b");    //going left
     digitalWrite(3, HIGH);
     digitalWrite(4, LOW);
     digitalWrite(5, LOW);
     digitalWrite(6, HIGH);
 
     
      (inputString == "c");    //going right
     digitalWrite(3, LOW);
     digitalWrite(4, HIGH);
     digitalWrite(5, HIGH);
     digitalWrite(6, LOW);}
     
     else if(inputString == "e");   //turn off motors
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
   
    }
    inputString = "";
  }
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

AWOL

Code: [Select]
  (inputString == "d");
Can you explain that line, please?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy