查看: 2978|回复: 0

Arduino UNO驱动和控制舵机180度来回摆动

[复制链接]
  • TA的每日心情
    奋斗
    2019-10-1 12:54
  • 签到天数: 313 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2018-4-23 08:51:37 | 显示全部楼层 |阅读模式
    分享到:
    下面介绍使用Arduino UNO来控制舵机180度来回摆动
    硬件连接方法:
    舵机的VCC GND SIG(信号)分别连接开发板的5V GND 数字输入输出9,然后使用USB打印线连接Arduino UNO和电脑USB
    连接如下图

    软件设置:
    打开Arduino IDE选择开发板Arduino UNO和端口号,新建Sketch输入下面代码
    #include <Servo.h>Servo myservo;int pos = 0;void setup() {  myservo.attach(9);}void loop() {  for (pos = 0; pos <= 180; pos += 1) {    // in steps of 1 degree    myservo.write(pos);    delay(15);  }  for (pos = 180; pos >= 0; pos -= 1) {    myservo.write(pos);    delay(15);  }}
    然后上传,效果如下
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-18 11:10 , Processed in 0.123368 second(s), 18 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.