Arduino - MG996R

Arduino - MG996R

In this tutorial, we are going to learn how to use the MG996R high-torque servo motor with Arduino.
在本教程中,我们将学习如何将MG996R高扭矩伺服电机与Arduino一起使用。

Hardware Required 所需硬件

1×Arduino UNO or Genuino UNO Arduino UNO 或 Genuino UNO
1×USB 2.0 cable type A/B USB 2.0 电缆 A/B 型
1×MG996R Servo Motor MG996R 伺服电机
1×Jumper Wires 跳线
1×(Optional) 9V Power Adapter for Arduino (可选)用于Arduino的9V电源适配器
1×(Recommended) Screw Terminal Block Shield for Arduino Uno (推荐)用于Arduino Uno的螺钉接线端子屏蔽层
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno (可选)Arduino Uno透明亚克力外壳

About Servo Motor 关于伺服电机

The MG996R servo motor is a high-torque servo motor capable of lifting up to 15kg in weight. The motor can rotate its handle from 0° to 180°, providing precise control of angular position. For basic information about servo motors, please refer to the Arduino - Servo Motor tutorial.
MG996R伺服电机是一款高扭矩伺服电机,能够举起高达15kg的重量。电机可以将其手柄旋转 0° 至 180°,从而提供对角度位置的精确控制。有关伺服电机的基本信息,请参阅Arduino - 伺服电机教程。

Pinout 引脚排列

The MG996R servo motor used in this example includes three pins:
本例中使用的MG996R伺服电机包括三个引脚:

  • VCC pin: (typically red) needs to be connected to VCC (4.8V – 7.2V)
    VCC 引脚:(通常为红色)需要连接到 VCC (4.8V – 7.2V)
  • GND pin: (typically black or brown) needs to be connected to GND (0V)
    GND 引脚:(通常为黑色或棕色)需要连接到 GND (0V)
  • Signal pin: (typically yellow or orange) receives the PWM control signal from an Arduino’s pin.
    信号引脚:(通常为黄色或橙色)接收来自Arduino引脚的PWM控制信号。
    请添加图片描述

Wiring Diagram 接线图

Since the MG996R is a high-torque servo motor, it draws a lot of power. We should not power this motor via the 5v pin of Arduino. Instead, we need to use the external power supply for the MG996R servo motor.
由于MG996R是一款高扭矩伺服电机,因此它消耗了大量的动力。我们不应该通过Arduino的5v引脚为该电机供电。相反,我们需要使用MG996R伺服电机的外部电源。
请添加图片描述

This image is created using Fritzing. Click to enlarge image
此图像是使用 Fritzing 创建的。点击放大图片

Arduino Code Arduino代码

/** Created by ArduinoGetStarted.com** This example code is in the public domain** Tutorial page: https://arduinogetstarted.com/tutorials/arduino-mg996r*/#include <Servo.h>Servo servo;  // create servo object to control a servovoid setup() {servo.attach(9);  // attaches the servo on pin 9 to the servo objectưservo.write(0);   // rotate slowly servo to 0 degrees immediately
}void loop() {for (int angle = 0; angle <= 180; angle += 1) {  // rotate slowly from 0 degrees to 180 degrees, one by one degree// in steps of 1 degreeservo.write(angle);  // control servo to go to position in variable 'angle'delay(10);         // waits 10ms for the servo to reach the position}for (int angle = 180; angle >= 0; angle -= 1) {  // rotate from 180 degrees to 0 degrees, one by one degreeservo.write(angle);                        // control servo to go to position in variable 'angle'delay(10);                               // waits 10ms for the servo to reach the position}
}

Quick Steps 快速步骤

  • Connect Arduino to PC via USB cable
    通过USB线将Arduino连接到PC
  • Open Arduino IDE, select the right board and port
    打开Arduino IDE,选择正确的板卡和端口
  • Copy the above code and open with Arduino IDE
    复制上面的代码并使用Arduino IDE打开
  • Click Upload button on Arduino IDE to upload code to Arduino
    单击Arduino IDE上的“上传”按钮,将代码上传到Arduino

请添加图片描述

  • See the result: Servo motor rotates slowly from 0 to 180° and then back rotates slowly from 180 back to 0°
    查看结果:伺服电机从 0 到 180° 缓慢旋转,然后从 180° 缓慢旋转到 0°

Code Explanation 代码说明

Read the line-by-line explanation in comment lines of code!
阅读代码注释行中的逐行说明!

How to Control Speed of Servo Motor 伺服电机的速度如何控制

By using map() and millis() functions, we can control the speed of servo motor smoothly without blocking other code
通过使用 map() 和 millis() 函数,我们可以在不阻塞其他代码的情况下平稳地控制伺服电机的速度

/** Created by ArduinoGetStarted.com** This example code is in the public domain** Tutorial page: https://arduinogetstarted.com/tutorials/arduino-mg996r*/#include <Servo.h>Servo myServo;
unsigned long MOVING_TIME = 3000; // moving time is 3 seconds
unsigned long moveStartTime;
int startAngle = 30; // 30°
int stopAngle  = 90; // 90°void setup() {myServo.attach(9);moveStartTime = millis(); // start moving// TODO: other code
}void loop() {unsigned long progress = millis() - moveStartTime;if (progress <= MOVING_TIME) {long angle = map(progress, 0, MOVING_TIME, startAngle, stopAngle);myServo.write(angle); }// TODO: other code
}

Video Tutorial 视频教程

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.
我们正在考虑制作视频教程。如果您认为视频教程是必不可少的,请订阅我们的 YouTube 频道,为我们制作视频提供动力。

Function References 函数参考

  • map()
  • millis()
  • Servo.attach()
  • Servo.write()
  • Servo.writeMicroseconds()
  • Servo.read()
  • Servo.attached()
  • Servo.detach()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/361208.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WPF 深入理解六、ControlTemplate控件模板

ControlTemplate 定义 控件模板用于来定义控件的外观、样式&#xff0c;还可通过控件模板的触发器(ControlTemplate.Triggers)修改控件的行为、响应动画等。 对与WPF当中,每个控件都是无外观的,这意味着我们可以完全自定义其可视元素的外观,但是不能修改其内部的行为&#xf…

【数据分享】《国际统计年鉴》1996-2022

公众号新功能 目前公众号新增以下等功能 1、处理GIS出图、Python制图、区位图、土地利用现状图、土地利用动态度和重心迁移图等等 2、核密度分析、网络od分析、地形分析、空间分析等等 3、地理加权回归、地理探测器、生态环境质量指数、地理加权回归模型影响因素分析、计算…

11年之约 聚焦上海 | 亚信科技邀您相约2024 MWC上海展

关于亚信安慧AntDB数据库 AntDB数据库始于2008年&#xff0c;在运营商的核心系统上&#xff0c;服务国内24个省市自治区的数亿用户&#xff0c;具备高性能、弹性扩展、高可靠等产品特性&#xff0c;峰值每秒可处理百万笔通信核心交易&#xff0c;保障系统持续稳定运行超十年&a…

安科瑞APM520电能质量分析仪表-安科瑞 蒋静

1 电能质量分析用三相网络电力仪表概述 APM5 系列网络电力仪表&#xff08;以下简称仪表&#xff09;按 IEC 国际标准设计&#xff0c;具有全电量测量、电能统计、电能质 量分析&#xff08;包括谐波、间谐波、闪变&#xff09;、故障录波功能(包括电压暂升暂降中断、冲击电流…

校园巡礼:一周只上四天课,入学即发钱?深圳理工大学,开局即王炸

校园巡礼 | 一周只上四天课&#xff0c;入学即发钱&#xff1f;深圳理工大学&#xff0c;开局即王炸&#xff01; 会议之眼 快讯 目前各省的高考成绩现已陆续揭晓&#xff0c;广东省教育考试院发布了2024年高考录取最低分数线&#xff0c;物理类本科线为442分&#xff0c;历史…

【Linux学习十八】网站管理:防火墙介绍、静态站点、动态站点、域名

1.Apache Apache官网: www.apache.org 软件包名称: httpd 服务端口:80/tcp(http) 443/tcp(https) 配置文件: /etc/httpd/conf/httpd.conf 子配置文件:/etc/httpd/conf.d/*.conf 查看被占用的端口号 netstat -tuln | grep <端口号> 解哪个程序正在使用端口 80&#xff0…

维吉尼亚密文解密小程序

维吉尼亚密文解密小程序 这几天在看CTF相关的课程&#xff0c;涉及到古典密码学和近代密码学还有现代密码学。自己编了一个解密小程序。 Vigenere 维吉尼亚密码 维吉尼亚是多表替换密码中比较典型的代表&#xff0c;维吉尼亚密码是在凯撒密码基础上产生的一种加密方法&#…

Centos7 Cpolar内网穿透工具

你是否想把本地测试的项目挂载到公网上提供给别人调用查看&#xff08;当然这是在你没有服务器的情况下&#xff0c;如果有请跳过&#xff09; 服务器系统&#xff1a;CentOS-7-x86_64-DVD-2009.iso 这是我在本地测试使用的服务器系统 Coplar官网 注册方式&#xff1a;邮箱注…

[C/C++][VsCode]使用VsCode在Linux上开发和Vscode在线调试

目录 0. 前言1. win10上搭建环境Linux环境2.编写makefile3.怎么在线调试结语 0. 前言 在开发中&#xff0c;可以一边开发一边调试&#xff0c;这样可以大大的减少bug&#xff1b;但是正常来说一个大点的项目&#xff0c;是不太可能单步调试的&#xff0c;因为一般都是用make或…

微信小程序版threejs的使用

首先是使用环境:我是使用的uniapp制作的微信小程序,当然原生的也是可以的,但是测试过很多,发现微信官方的threejs移植版本只能够导入gltf格式的模型,无法导入obj,这就有些尴尬了,为此我找了很多版本的threejs,首先是threejs-miniprogram,也就是官方的,可以直接在unia…

修改 Linux 终端提示符的色彩与字体

1、引言 Linux 终端是许多开发者和系统管理员每天工作的主要工具之一。但你是否曾留意过那个位于命令行开头的提示符&#xff1f;是不是觉得它有点单调&#xff1f;别担心&#xff0c;本文将介绍如何通过修改提示符的颜色和字体&#xff0c;为你的 Linux 终端增添一抹独特的色…

教师资格证考试笔试报名流程

文章目录 前言笔试报名流程一、登录官网二、选择报考省份三、注册报名账号四、确认考试承诺五、填报个人信息六、上传个人照片七、查看个人信息八、笔试报名九、等待审核十、考试缴费最后&#xff08;必看&#xff09;附录1. 中小学教师资格考试网2. 广东省教资笔试报名通知&am…

Python 实现Excel转TXT,或TXT文本导入Excel

Excel是一种具有强大的数据处理和图表制作功能的电子表格文件&#xff0c;而TXT则是一种简单通用、易于编辑的纯文本文件。将Excel转换为TXT可以帮助我们将复杂的数据表格以文本的形式保存&#xff0c;方便其他程序读取和处理。而将TXT转换为Excel则可以将文本文件中的数据导入…

AI绘画Stable diffusion的SDXL模型超详细讲解,针不错!(含实操教程)

大家好&#xff0c;我是画画的小强 朋友们好&#xff0c;今天分享的是Stable diffusion的SDXL模型以及相关实操。 与之前的SD1.5大模型不同&#xff0c;这次的SDXL在架构上采用了“两步走”的生图方式&#xff1a; 以往SD1.5大模型&#xff0c;生成步骤为 Prompt → Base → …

【arm扩容】docker load -i tar包 空间不足

背景&#xff1a; 首先我在/home/nvidia/work下导入了一些镜像源码tar包。然后逐个load进去。当我 load -i dev-aarch64-18.04-20210423_2000.tar包的时候&#xff0c;出现 Error processing tar file(exit status 1): write /9818cf5a7cbd5a828600d9a4d4e62185a7067e2a6f2ee…

TCP:TCP连接的建立与终止

TCP连接的建立与终止 建立连接第一次握手第二次握手第三次握手 终止连接第一次挥手第二次挥手第三次挥手第四次挥手 T C P是一个面向连接的协议。无论哪一方向另一方发送数据之前&#xff0c;都必须先在双方之间建立一条连接。本文将详细讨论一个T C P连接是如何建立的以及通信…

python-登录界面-demo

文章目录 前言python-登录界面-demo 前言 如果您觉得有用的话&#xff0c;记得给博主点个赞&#xff0c;评论&#xff0c;收藏一键三连啊&#xff0c;写作不易啊^ _ ^。   而且听说点赞的人每天的运气都不会太差&#xff0c;实在白嫖的话&#xff0c;那欢迎常来啊!!! python-…

【深度学习】快速入门KerasNLP:微调BERT模型完成电影评论情感分类任务

简介&#xff1a;本文将介绍 KerasNLP 的安装及使用&#xff0c;以及如何使用它在情感分析任务中微调 BERT 的预训练模型。 1. KerasNLP库 KerasNLP 是一个自然语言处理库&#xff0c;兼容 TensorFlow、JAX 和 PyTorch 等多种深度学习框架。基于 Keras 3 构建&#xff0c;这些…

leetcode119 杨辉三角②

给定一个非负索引 rowIndex&#xff0c;返回「杨辉三角」的第 rowIndex 行。 在「杨辉三角」中&#xff0c;每个数是它左上方和右上方的数的和。 示例 1: 输入: rowIndex 3 输出: [1,3,3,1]示例 2: 输入: rowIndex 0 输出: [1]示例 3: 输入: rowIndex 1 输出: [1,1] pub…

WebSocket 连接失败的原因及解决方法

WebSocket 目前已经成为了一项极为重要的技术&#xff0c;其允许客户端和服务器之间进行实时、全双工的通信。然而&#xff0c;在实际项目中&#xff0c;开发者时常会遇到 WebSocket 连接失败的情况。这不仅影响了用户体验&#xff0c;还可能导致不可预见的系统错误或数据丢失。…