×

蓝牙控制的Arduino机器人

消耗积分:0 | 格式:zip | 大小:0.01 MB | 2023-06-27

14230

分享资料个

 

代码

 

#include
SoftwareSerial bt(10,11); // assigning 10 as RX ans 11 as TX 
#define motor_left 5
#define motor_right 3
#define motor_right_dir 2
#define motor_left_dir 4
void setup() {
 pinMode(2,OUTPUT);
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);
 while(!Serial){;} // waiting for serial communication to setup
 bt.begin(9600); // beginning the bluetooth connection
}
void loop() {
 bt.listen(); // listening to the bluetooth
 while(bt.available()) // till we are receiving the input continue in the loop
 {
     char ch = bt.read();  // reading one character at a time
     if(ch=='f'){          // action to be performed if input is 'f'
       digitalWrite(motor_left_dir,HIGH);
       digitalWrite(motor_right_dir,HIGH);
       analogWrite(motor_left,150);
       analogWrite(motor_right,150);
     }
     else if(ch == 'b'){       // action to be performed if input is 'b'
       digitalWrite(motor_left_dir,LOW);
       digitalWrite(motor_right_dir,LOW);
       analogWrite(motor_left,150);
       analogWrite(motor_right,150);
     }
     else if(ch == 'l'){       // action to be performed if input is 'l'
       digitalWrite(motor_left_dir,HIGH);
       digitalWrite(motor_right_dir,HIGH);
       analogWrite(motor_left,0);
       analogWrite(motor_right,120);
     }
     else if(ch == 'r'){     // action to be performed if input is 'r'
       digitalWrite(motor_left_dir,HIGH);
       digitalWrite(motor_right_dir,HIGH);
       analogWrite(motor_left,120);
       analogWrite(motor_right,0); 
     }
     else if(ch =='s'){  // action to be performed if input is 's'
       digitalWrite(motor_left_dir,HIGH);
       digitalWrite(motor_right_dir,HIGH);
       analogWrite(motor_left,0);
       analogWrite(motor_right,0); 
     }
 }
} 

电路组装

 

 
poYBAGOIklqAKVfAAAD1I8-KIsk735.jpg
用于蓝牙控制的 Arduino 机器人汽车的电路组件
 

 

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !