muftY

Bluetooth Controlled Car_HC-05_Arduino_Code

Apr 9th, 2021 (edited)
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. int motor1_Back=7,motor1=8,motor2=4,motor2_Back=2;
  2.  
  3. int command ;
  4.  
  5. void setup() {
  6.    
  7.     pinMode(motor1,OUTPUT);
  8.     pinMode(motor1_Back,OUTPUT);
  9.  
  10.     pinMode(motor2,OUTPUT);
  11.     pinMode(motor2_Back,OUTPUT);
  12.    
  13.     Serial.begin(9600);
  14. }
  15.  
  16. void loop()
  17.   {
  18.     if (Serial.available() > 0) {
  19.     command = Serial.read();
  20.  
  21.   Serial.print("command=");
  22.  
  23.   Serial.println(command);
  24.   if(command==82)
  25.   {
  26.     digitalWrite(motor1,HIGH);
  27.    
  28.   }
  29.  
  30.    else if(command==70)
  31.   {
  32.     digitalWrite(motor1,HIGH);
  33.     digitalWrite(motor2,HIGH);
  34.    
  35.   }
  36.    else if(command==76)
  37.   {
  38.     digitalWrite(motor2,HIGH);
  39.    
  40.   }
  41.  
  42.   else if(command==66)
  43.   {
  44.     digitalWrite(motor1_Back,HIGH);
  45.     digitalWrite(motor2_Back,HIGH);
  46.   }
  47.  
  48.   else if(command==110)
  49.   {
  50.     digitalWrite(motor1_Back,HIGH);
  51.    
  52.   }
  53.   else if(command==109)
  54.   {
  55.    
  56.     digitalWrite(motor2_Back,HIGH);
  57.   }
  58.  
  59.  
  60.   else if(command==83)
  61.   {
  62.     digitalWrite(motor1,LOW);
  63.     digitalWrite(motor1_Back,LOW);
  64.     digitalWrite(motor2,LOW);
  65.     digitalWrite(motor2_Back,LOW);
  66.   }
  67.  
  68.   }
  69.   }
  70.  
Add Comment
Please, Sign In to add comment