SHARE
TWEET

Bluetooth Controlled Arduino robot car

AnmolSahu Jul 6th, 2018 18,366 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. char t;
  2.  
  3. void setup() {
  4. pinMode(9,OUTPUT);   //left motors forward
  5. pinMode(10,OUTPUT);   //left motors reverse
  6. pinMode(11,OUTPUT);   //right motors forward
  7. pinMode(12,OUTPUT);   //right motors reverse
  8.  
  9. Serial.begin(9600);
  10.  
  11. }
  12.  
  13. void loop() {
  14. if(Serial.available()){
  15.   t = Serial.read();
  16.   Serial.println(t);
  17. }
  18.  
  19. if(t == '1'){            //move forward(all motors rotate in forward direction)
  20.   digitalWrite(9,HIGH);
  21.   digitalWrite(10,LOW);
  22.   digitalWrite(11,HIGH);
  23.   digitalWrite(12,LOW);
  24. }
  25.  
  26. else if(t == '2'){      //move reverse (all motors rotate in reverse direction)
  27.   digitalWrite(9,LOW);
  28.   digitalWrite(10,HIGH);
  29.   digitalWrite(11,LOW);
  30.   digitalWrite(12,HIGH);
  31. }
  32.  
  33. else if(t == '3'){      //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)
  34.   digitalWrite(9,LOW);
  35.   digitalWrite(10,LOW);
  36.   digitalWrite(11,HIGH);
  37.   digitalWrite(12,LOW);
  38. }
  39.  
  40. else if(t == '4'){      //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)
  41.   digitalWrite(9,HIGH);
  42.   digitalWrite(10,LOW);
  43.   digitalWrite(11,LOW);
  44.   digitalWrite(12,LOW);
  45. }
  46.  
  47. else if(t == '5'){      //STOP (all motors stop)
  48.   digitalWrite(9,LOW);
  49.   digitalWrite(10,LOW);
  50.   digitalWrite(11,LOW);
  51.   digitalWrite(12,LOW);
  52. }
  53. delay(100);
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top